| Filename | /Users/timbo/perl5/perlbrew/perls/perl-5.18.2/lib/site_perl/5.18.2/Exception/Class.pm |
| Statements | Executed 753 statements in 2.64ms |
| Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
|---|---|---|---|---|---|
| 19 | 1 | 1 | 2.11ms | 5.73ms | Exception::Class::_make_subclass (recurses: max depth 2, inclusive time 2.16ms) |
| 1 | 1 | 1 | 1.20ms | 4.06ms | Exception::Class::BEGIN@7 |
| 21 | 21 | 21 | 455µs | 6.07ms | Exception::Class::import (recurses: max depth 2, inclusive time 2.30ms) |
| 21 | 1 | 1 | 21µs | 21µs | Exception::Class::CORE:sort (opcode) |
| 1 | 1 | 1 | 20µs | 20µs | Exception::Class::BEGIN@3 |
| 19 | 1 | 1 | 19µs | 19µs | Exception::Class::CORE:subst (opcode) |
| 1 | 1 | 1 | 8µs | 24µs | Exception::Class::BEGIN@5 |
| 1 | 1 | 1 | 8µs | 34µs | Exception::Class::BEGIN@8 |
| 1 | 1 | 1 | 7µs | 17µs | Exception::Class::BEGIN@165 |
| 1 | 1 | 1 | 7µs | 17µs | Exception::Class::BEGIN@43 |
| 1 | 1 | 1 | 7µs | 17µs | Exception::Class::BEGIN@76 |
| 1 | 1 | 1 | 7µs | 16µs | Exception::Class::BEGIN@173 |
| 1 | 1 | 1 | 4µs | 4µs | Exception::Class::BEGIN@11 |
| 2 | 1 | 1 | 3µs | 3µs | Exception::Class::CORE:substcont (opcode) |
| 0 | 0 | 0 | 0s | 0s | Exception::Class::Classes |
| 0 | 0 | 0 | 0s | 0s | Exception::Class::__ANON__[:167] |
| 0 | 0 | 0 | 0s | 0s | Exception::Class::_make_parents |
| 0 | 0 | 0 | 0s | 0s | Exception::Class::caught |
| Line | State ments |
Time on line |
Calls | Time in subs |
Code |
|---|---|---|---|---|---|
| 1 | package Exception::Class; | ||||
| 2 | 1 | 600ns | $Exception::Class::VERSION = '1.38'; | ||
| 3 | 2 | 50µs | 1 | 20µs | # spent 20µs within Exception::Class::BEGIN@3 which was called:
# once (20µs+0s) by Perl::Critic::Exception::Fatal::Generic::BEGIN@20 at line 3 # spent 20µs making 1 call to Exception::Class::BEGIN@3 |
| 4 | |||||
| 5 | 2 | 24µs | 2 | 39µs | # spent 24µs (8+15) within Exception::Class::BEGIN@5 which was called:
# once (8µs+15µs) by Perl::Critic::Exception::Fatal::Generic::BEGIN@20 at line 5 # spent 24µs making 1 call to Exception::Class::BEGIN@5
# spent 15µs making 1 call to strict::import |
| 6 | |||||
| 7 | 2 | 141µs | 1 | 4.06ms | # spent 4.06ms (1.20+2.86) within Exception::Class::BEGIN@7 which was called:
# once (1.20ms+2.86ms) by Perl::Critic::Exception::Fatal::Generic::BEGIN@20 at line 7 # spent 4.06ms making 1 call to Exception::Class::BEGIN@7 |
| 8 | 2 | 32µs | 2 | 58µs | # spent 34µs (8+25) within Exception::Class::BEGIN@8 which was called:
# once (8µs+25µs) by Perl::Critic::Exception::Fatal::Generic::BEGIN@20 at line 8 # spent 34µs making 1 call to Exception::Class::BEGIN@8
# spent 25µs making 1 call to Exporter::import |
| 9 | |||||
| 10 | 1 | 0s | our $BASE_EXC_CLASS; | ||
| 11 | 1 | 98µs | 1 | 4µs | # spent 4µs within Exception::Class::BEGIN@11 which was called:
# once (4µs+0s) by Perl::Critic::Exception::Fatal::Generic::BEGIN@20 at line 11 # spent 4µs making 1 call to Exception::Class::BEGIN@11 |
| 12 | |||||
| 13 | 1 | 200ns | our %CLASSES; | ||
| 14 | |||||
| 15 | # spent 6.07ms (455µs+5.61) within Exception::Class::import which was called 21 times, avg 289µs/call:
# once (20µs+1.15ms) by Perl::Critic::Exception::Configuration::Option::Policy::ParameterValue::BEGIN@22 at line 28 of Perl/Critic/Exception/Configuration/Option/Policy/ParameterValue.pm
# once (18µs+1.11ms) by Perl::Critic::Exception::Configuration::Option::Global::ParameterValue::BEGIN@22 at line 28 of Perl/Critic/Exception/Configuration/Option/Global/ParameterValue.pm
# once (24µs+1.06ms) by Perl::Critic::Exception::Fatal::Generic::BEGIN@20 at line 26 of Perl/Critic/Exception/Fatal/Generic.pm
# once (21µs+597µs) by Perl::Critic::Exception::Configuration::Generic::BEGIN@20 at line 27 of Perl/Critic/Exception/Configuration/Generic.pm
# once (32µs+251µs) by Perl::Critic::Exception::Configuration::Option::Policy::ExtraParameter::BEGIN@20 at line 26 of Perl/Critic/Exception/Configuration/Option/Policy/ExtraParameter.pm
# once (25µs+249µs) by Perl::Critic::Exception::Configuration::NonExistentPolicy::BEGIN@20 at line 26 of Perl/Critic/Exception/Configuration/NonExistentPolicy.pm
# once (31µs+239µs) by Perl::Critic::Exception::Fatal::Internal::BEGIN@20 at line 26 of Perl/Critic/Exception/Fatal/Internal.pm
# once (19µs+208µs) by Perl::Critic::Exception::IO::BEGIN@24 at line 31 of Perl/Critic/Exception/IO.pm
# once (25µs+198µs) by Perl::Critic::Exception::Fatal::PolicyDefinition::BEGIN@20 at line 26 of Perl/Critic/Exception/Fatal/PolicyDefinition.pm
# once (20µs+184µs) by Perl::Critic::Exception::Parse::BEGIN@24 at line 31 of Perl/Critic/Exception/Parse.pm
# once (17µs+186µs) by Perl::Critic::Exception::AggregateConfiguration::BEGIN@24 at line 31 of Perl/Critic/Exception/AggregateConfiguration.pm
# once (28µs+174µs) by Perl::Critic::Exception::Configuration::Option::Global::ExtraParameter::BEGIN@20 at line 26 of Perl/Critic/Exception/Configuration/Option/Global/ExtraParameter.pm
# once (21µs+143µs) by PPIx::Utilities::Exception::Bug::BEGIN@17 at line 22 of PPIx/Utilities/Exception/Bug.pm
# once (10µs+600ns) by Perl::Critic::PolicyFactory::BEGIN@37 at line 37 of Perl/Critic/PolicyFactory.pm
# once (10µs+500ns) by Perl::Critic::Policy::BEGIN@48 at line 48 of Perl/Critic/Policy.pm
# once (24µs+-24µs) by Perl::Critic::Exception::BEGIN@18 at line 23 of Perl/Critic/Exception.pm
# once (20µs+-20µs) by Perl::Critic::Exception::Fatal::BEGIN@18 at line 24 of Perl/Critic/Exception/Fatal.pm
# once (18µs+-18µs) by Perl::Critic::Exception::Configuration::Option::Global::BEGIN@18 at line 23 of Perl/Critic/Exception/Configuration/Option/Global.pm
# once (22µs+-22µs) by Perl::Critic::Exception::Configuration::Option::BEGIN@20 at line 26 of Perl/Critic/Exception/Configuration/Option.pm
# once (32µs+-32µs) by Perl::Critic::Exception::Configuration::Option::Policy::BEGIN@20 at line 26 of Perl/Critic/Exception/Configuration/Option/Policy.pm
# once (20µs+-20µs) by Perl::Critic::Exception::Configuration::BEGIN@18 at line 24 of Perl/Critic/Exception/Configuration.pm | ||||
| 16 | 21 | 8µs | my $class = shift; | ||
| 17 | |||||
| 18 | 21 | 12µs | local $Exception::Class::Caller = caller(); | ||
| 19 | |||||
| 20 | 21 | 3µs | my %c; | ||
| 21 | |||||
| 22 | 21 | 800ns | my %needs_parent; | ||
| 23 | 21 | 21µs | while ( my $subclass = shift ) { | ||
| 24 | 19 | 11µs | my $def = ref $_[0] ? shift : {}; | ||
| 25 | 19 | 34µs | $def->{isa} | ||
| 26 | = $def->{isa} | ||||
| 27 | ? ( ref $def->{isa} ? $def->{isa} : [ $def->{isa} ] ) | ||||
| 28 | : []; | ||||
| 29 | |||||
| 30 | 19 | 14µs | $c{$subclass} = $def; | ||
| 31 | } | ||||
| 32 | |||||
| 33 | # We need to sort by length because if we check for keys in the | ||||
| 34 | # Foo::Bar:: stash, this creates a "Bar::" key in the Foo:: stash! | ||||
| 35 | MAKE_CLASSES: | ||||
| 36 | 21 | 112µs | 21 | 21µs | foreach my $subclass ( sort { length $a <=> length $b } keys %c ) { # spent 21µs making 21 calls to Exception::Class::CORE:sort, avg 1µs/call |
| 37 | 19 | 7µs | my $def = $c{$subclass}; | ||
| 38 | |||||
| 39 | # We already made this one. | ||||
| 40 | 19 | 6µs | next if $CLASSES{$subclass}; | ||
| 41 | |||||
| 42 | { | ||||
| 43 | 21 | 130µs | 2 | 27µs | # spent 17µs (7+10) within Exception::Class::BEGIN@43 which was called:
# once (7µs+10µs) by Perl::Critic::Exception::Fatal::Generic::BEGIN@20 at line 43 # spent 17µs making 1 call to Exception::Class::BEGIN@43
# spent 10µs making 1 call to strict::unimport |
| 44 | 19 | 11µs | foreach my $parent ( @{ $def->{isa} } ) { | ||
| 45 | 19 | 40µs | unless ( keys %{"$parent\::"} ) { | ||
| 46 | $needs_parent{$subclass} = { | ||||
| 47 | parents => $def->{isa}, | ||||
| 48 | def => $def | ||||
| 49 | }; | ||||
| 50 | next MAKE_CLASSES; | ||||
| 51 | } | ||||
| 52 | } | ||||
| 53 | } | ||||
| 54 | |||||
| 55 | $class->_make_subclass( | ||||
| 56 | 19 | 57µs | 19 | 5.73ms | subclass => $subclass, # spent 7.89ms making 19 calls to Exception::Class::_make_subclass, avg 415µs/call, recursion: max depth 2, sum of overlapping time 2.16ms |
| 57 | def => $def || {}, | ||||
| 58 | ); | ||||
| 59 | } | ||||
| 60 | |||||
| 61 | 21 | 110µs | foreach my $subclass ( keys %needs_parent ) { | ||
| 62 | |||||
| 63 | # This will be used to spot circular references. | ||||
| 64 | my %seen; | ||||
| 65 | $class->_make_parents( \%needs_parent, $subclass, \%seen ); | ||||
| 66 | } | ||||
| 67 | } | ||||
| 68 | |||||
| 69 | sub _make_parents { | ||||
| 70 | my $class = shift; | ||||
| 71 | my $needs = shift; | ||||
| 72 | my $subclass = shift; | ||||
| 73 | my $seen = shift; | ||||
| 74 | my $child = shift; # Just for error messages. | ||||
| 75 | |||||
| 76 | 2 | 309µs | 2 | 27µs | # spent 17µs (7+10) within Exception::Class::BEGIN@76 which was called:
# once (7µs+10µs) by Perl::Critic::Exception::Fatal::Generic::BEGIN@20 at line 76 # spent 17µs making 1 call to Exception::Class::BEGIN@76
# spent 10µs making 1 call to strict::unimport |
| 77 | |||||
| 78 | # What if someone makes a typo in specifying their 'isa' param? | ||||
| 79 | # This should catch it. Either it's been made because it didn't | ||||
| 80 | # have missing parents OR it's in our hash as needing a parent. | ||||
| 81 | # If neither of these is true then the _only_ place it is | ||||
| 82 | # mentioned is in the 'isa' param for some other class, which is | ||||
| 83 | # not a good enough reason to make a new class. | ||||
| 84 | die | ||||
| 85 | "Class $subclass appears to be a typo as it is only specified in the 'isa' param for $child\n" | ||||
| 86 | unless exists $needs->{$subclass} | ||||
| 87 | || $CLASSES{$subclass} | ||||
| 88 | || keys %{"$subclass\::"}; | ||||
| 89 | |||||
| 90 | foreach my $c ( @{ $needs->{$subclass}{parents} } ) { | ||||
| 91 | |||||
| 92 | # It's been made | ||||
| 93 | next if $CLASSES{$c} || keys %{"$c\::"}; | ||||
| 94 | |||||
| 95 | die "There appears to be some circularity involving $subclass\n" | ||||
| 96 | if $seen->{$subclass}; | ||||
| 97 | |||||
| 98 | $seen->{$subclass} = 1; | ||||
| 99 | |||||
| 100 | $class->_make_parents( $needs, $c, $seen, $subclass ); | ||||
| 101 | } | ||||
| 102 | |||||
| 103 | return if $CLASSES{$subclass} || keys %{"$subclass\::"}; | ||||
| 104 | |||||
| 105 | $class->_make_subclass( | ||||
| 106 | subclass => $subclass, | ||||
| 107 | def => $needs->{$subclass}{def} | ||||
| 108 | ); | ||||
| 109 | } | ||||
| 110 | |||||
| 111 | # spent 5.73ms (2.11+3.62) within Exception::Class::_make_subclass which was called 19 times, avg 302µs/call:
# 19 times (2.11ms+3.62ms) by Exception::Class::import at line 56, avg 302µs/call | ||||
| 112 | 19 | 5µs | my $class = shift; | ||
| 113 | 19 | 22µs | my %p = @_; | ||
| 114 | |||||
| 115 | 19 | 5µs | my $subclass = $p{subclass}; | ||
| 116 | 19 | 3µs | my $def = $p{def}; | ||
| 117 | |||||
| 118 | 19 | 1µs | my $isa; | ||
| 119 | 19 | 27µs | if ( $def->{isa} ) { | ||
| 120 | $isa = ref $def->{isa} ? join ' ', @{ $def->{isa} } : $def->{isa}; | ||||
| 121 | } | ||||
| 122 | 19 | 2µs | $isa ||= $BASE_EXC_CLASS; | ||
| 123 | |||||
| 124 | 19 | 4µs | my $version_name = 'VERSION'; | ||
| 125 | |||||
| 126 | 19 | 18µs | my $code = <<"EOPERL"; | ||
| 127 | package $subclass; | ||||
| 128 | |||||
| 129 | use base qw($isa); | ||||
| 130 | |||||
| 131 | our \$$version_name = '1.1'; | ||||
| 132 | |||||
| 133 | 1; | ||||
| 134 | |||||
| 135 | EOPERL | ||||
| 136 | |||||
| 137 | 19 | 6µs | if ( $def->{description} ) { | ||
| 138 | 19 | 77µs | 21 | 22µs | ( my $desc = $def->{description} ) =~ s/([\\\'])/\\$1/g; # spent 19µs making 19 calls to Exception::Class::CORE:subst, avg 984ns/call
# spent 3µs making 2 calls to Exception::Class::CORE:substcont, avg 1µs/call |
| 139 | 19 | 17µs | $code .= <<"EOPERL"; | ||
| 140 | sub description | ||||
| 141 | { | ||||
| 142 | return '$desc'; | ||||
| 143 | } | ||||
| 144 | EOPERL | ||||
| 145 | } | ||||
| 146 | |||||
| 147 | 19 | 3µs | my @fields; | ||
| 148 | 19 | 8µs | if ( my $fields = $def->{fields} ) { | ||
| 149 | 7 | 39µs | 7 | 16µs | @fields = UNIVERSAL::isa( $fields, 'ARRAY' ) ? @$fields : $fields; # spent 16µs making 7 calls to UNIVERSAL::isa, avg 2µs/call |
| 150 | |||||
| 151 | $code | ||||
| 152 | .= "sub Fields { return (\$_[0]->SUPER::Fields, " | ||||
| 153 | 7 | 21µs | . join( ", ", map { "'$_'" } @fields ) | ||
| 154 | . ") }\n\n"; | ||||
| 155 | |||||
| 156 | 7 | 3µs | foreach my $field (@fields) { | ||
| 157 | 10 | 19µs | $code .= sprintf( "sub %s { \$_[0]->{%s} }\n", $field, $field ); | ||
| 158 | } | ||||
| 159 | } | ||||
| 160 | |||||
| 161 | 19 | 9µs | if ( my $alias = $def->{alias} ) { | ||
| 162 | 11 | 2µs | die "Cannot make alias without caller" | ||
| 163 | unless defined $Exception::Class::Caller; | ||||
| 164 | |||||
| 165 | 2 | 74µs | 2 | 27µs | # spent 17µs (7+10) within Exception::Class::BEGIN@165 which was called:
# once (7µs+10µs) by Perl::Critic::Exception::Fatal::Generic::BEGIN@20 at line 165 # spent 17µs making 1 call to Exception::Class::BEGIN@165
# spent 10µs making 1 call to strict::unimport |
| 166 | *{"$Exception::Class::Caller\::$alias"} | ||||
| 167 | 11 | 57µs | = sub { $subclass->throw(@_) }; | ||
| 168 | } | ||||
| 169 | |||||
| 170 | 19 | 5µs | if ( my $defaults = $def->{defaults} ) { | ||
| 171 | $code | ||||
| 172 | .= "sub _defaults { return shift->SUPER::_defaults, our \%_DEFAULTS }\n"; | ||||
| 173 | 2 | 126µs | 2 | 26µs | # spent 16µs (7+10) within Exception::Class::BEGIN@173 which was called:
# once (7µs+10µs) by Perl::Critic::Exception::Fatal::Generic::BEGIN@20 at line 173 # spent 16µs making 1 call to Exception::Class::BEGIN@173
# spent 10µs making 1 call to strict::unimport |
| 174 | *{"$subclass\::_DEFAULTS"} = {%$defaults}; | ||||
| 175 | } | ||||
| 176 | |||||
| 177 | 19 | 757µs | eval $code; # spent 2.46ms executing statements in string eval # includes 5.34ms spent executing 851 calls to 4 subs defined therein. # spent 109µs executing statements in string eval # includes 17µs spent executing 1 call to 4 subs defined therein. # spent 92µs executing statements in string eval # includes 9µs spent executing 1 call to 6 subs defined therein. # spent 92µs executing statements in string eval # includes 9µs spent executing 1 call to 5 subs defined therein. # spent 92µs executing statements in string eval # includes 12µs spent executing 1 call to 4 subs defined therein. # spent 69µs executing statements in string eval # includes 10µs spent executing 1 call to 4 subs defined therein. # spent 65µs executing statements in string eval # includes 10µs spent executing 1 call to 4 subs defined therein. # spent 63µs executing statements in string eval # includes 15µs spent executing 1 call to 2 subs defined therein. # spent 59µs executing statements in string eval # includes 15µs spent executing 1 call to 2 subs defined therein. # spent 54µs executing statements in string eval # includes 12µs spent executing 1 call to 2 subs defined therein. # spent 49µs executing statements in string eval # includes 12µs spent executing 1 call to 2 subs defined therein. # spent 40µs executing statements in string eval # includes 11µs spent executing 1 call to 2 subs defined therein. # spent 38µs executing statements in string eval # includes 10µs spent executing 1 call to 2 subs defined therein. # spent 37µs executing statements in string eval # includes 10µs spent executing 1 call to 2 subs defined therein. # spent 33µs executing statements in string eval # includes 10µs spent executing 1 call to 2 subs defined therein. # spent 32µs executing statements in string eval # includes 9µs spent executing 1 call to 2 subs defined therein. # spent 32µs executing statements in string eval # includes 9µs spent executing 1 call to 2 subs defined therein. # spent 32µs executing statements in string eval # includes 10µs spent executing 1 call to 2 subs defined therein. # spent 32µs executing statements in string eval # includes 10µs spent executing 1 call to 2 subs defined therein. | ||
| 178 | |||||
| 179 | 19 | 3µs | die $@ if $@; | ||
| 180 | |||||
| 181 | 19 | 92µs | $CLASSES{$subclass} = 1; | ||
| 182 | } | ||||
| 183 | |||||
| 184 | sub caught { | ||||
| 185 | my $e = $@; | ||||
| 186 | |||||
| 187 | return $e unless $_[1]; | ||||
| 188 | |||||
| 189 | return unless blessed($e) && $e->isa( $_[1] ); | ||||
| 190 | return $e; | ||||
| 191 | } | ||||
| 192 | |||||
| 193 | sub Classes { sort keys %Exception::Class::CLASSES } | ||||
| 194 | |||||
| 195 | 1 | 2µs | 1; | ||
| 196 | |||||
| 197 | # ABSTRACT: A module that allows you to declare real exception classes in Perl | ||||
| 198 | |||||
| 199 | __END__ | ||||
# spent 21µs within Exception::Class::CORE:sort which was called 21 times, avg 1µs/call:
# 21 times (21µs+0s) by Exception::Class::import at line 36, avg 1µs/call | |||||
# spent 19µs within Exception::Class::CORE:subst which was called 19 times, avg 984ns/call:
# 19 times (19µs+0s) by Exception::Class::_make_subclass at line 138, avg 984ns/call | |||||
# spent 3µs within Exception::Class::CORE:substcont which was called 2 times, avg 1µs/call:
# 2 times (3µs+0s) by Exception::Class::_make_subclass at line 138, avg 1µs/call |