Filename | /Users/timbo/perl5/perlbrew/perls/perl-5.18.2/lib/site_perl/5.18.2/Exception/Class/Base.pm |
Statements | Executed 11087 statements in 23.7ms |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
424 | 1 | 1 | 24.1ms | 253ms | _initialize | Exception::Class::Base::
424 | 1 | 1 | 2.23ms | 255ms | new | Exception::Class::Base::
1 | 1 | 1 | 1.19ms | 2.12ms | BEGIN@7 | Exception::Class::Base::
424 | 1 | 1 | 520µs | 520µs | CORE:match (opcode) | Exception::Class::Base::
424 | 1 | 1 | 334µs | 334µs | Fields | Exception::Class::Base::
1 | 1 | 1 | 265µs | 328µs | BEGIN@6 | Exception::Class::Base::
1 | 1 | 1 | 48µs | 48µs | BEGIN@35 | Exception::Class::Base::
1 | 1 | 1 | 41µs | 94µs | BEGIN@12 | Exception::Class::Base::
1 | 1 | 1 | 19µs | 26µs | BEGIN@4 | Exception::Class::Base::
1 | 1 | 1 | 16µs | 38µs | BEGIN@3 | Exception::Class::Base::
1 | 1 | 1 | 10µs | 87µs | BEGIN@10 | Exception::Class::Base::
1 | 1 | 1 | 9µs | 43µs | BEGIN@32 | Exception::Class::Base::
1 | 1 | 1 | 9µs | 35µs | BEGIN@8 | Exception::Class::Base::
1 | 1 | 1 | 8µs | 20µs | BEGIN@41 | Exception::Class::Base::
1 | 1 | 1 | 8µs | 18µs | BEGIN@61 | Exception::Class::Base::
4 | 4 | 1 | 7µs | 7µs | __ANON__[:32] | Exception::Class::Base::
0 | 0 | 0 | 0s | 0s | Classes | Exception::Class::Base::
0 | 0 | 0 | 0s | 0s | __ANON__[:39] | Exception::Class::Base::
0 | 0 | 0 | 0s | 0s | __ANON__[:60] | Exception::Class::Base::
0 | 0 | 0 | 0s | 0s | as_string | Exception::Class::Base::
0 | 0 | 0 | 0s | 0s | caught | Exception::Class::Base::
0 | 0 | 0 | 0s | 0s | context_hash | Exception::Class::Base::
0 | 0 | 0 | 0s | 0s | description | Exception::Class::Base::
0 | 0 | 0 | 0s | 0s | field_hash | Exception::Class::Base::
0 | 0 | 0 | 0s | 0s | full_message | Exception::Class::Base::
0 | 0 | 0 | 0s | 0s | rethrow | Exception::Class::Base::
0 | 0 | 0 | 0s | 0s | show_trace | Exception::Class::Base::
0 | 0 | 0 | 0s | 0s | throw | Exception::Class::Base::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | package Exception::Class::Base; | ||||
2 | 1 | 700ns | $Exception::Class::Base::VERSION = '1.38'; | ||
3 | 2 | 27µs | 2 | 59µs | # spent 38µs (16+21) within Exception::Class::Base::BEGIN@3 which was called:
# once (16µs+21µs) by Exception::Class::BEGIN@7 at line 3 # spent 38µs making 1 call to Exception::Class::Base::BEGIN@3
# spent 21µs making 1 call to strict::import |
4 | 2 | 29µs | 2 | 32µs | # spent 26µs (19+6) within Exception::Class::Base::BEGIN@4 which was called:
# once (19µs+6µs) by Exception::Class::BEGIN@7 at line 4 # spent 26µs making 1 call to Exception::Class::Base::BEGIN@4
# spent 6µs making 1 call to warnings::import |
5 | |||||
6 | 3 | 119µs | 2 | 338µs | # spent 328µs (265+62) within Exception::Class::Base::BEGIN@6 which was called:
# once (265µs+62µs) by Exception::Class::BEGIN@7 at line 6 # spent 328µs making 1 call to Exception::Class::Base::BEGIN@6
# spent 10µs making 1 call to UNIVERSAL::VERSION |
7 | 3 | 119µs | 2 | 2.13ms | # spent 2.12ms (1.19+938µs) within Exception::Class::Base::BEGIN@7 which was called:
# once (1.19ms+938µs) by Exception::Class::BEGIN@7 at line 7 # spent 2.12ms making 1 call to Exception::Class::Base::BEGIN@7
# spent 10µs making 1 call to UNIVERSAL::VERSION |
8 | 2 | 26µs | 2 | 61µs | # spent 35µs (9+26) within Exception::Class::Base::BEGIN@8 which was called:
# once (9µs+26µs) by Exception::Class::BEGIN@7 at line 8 # spent 35µs making 1 call to Exception::Class::Base::BEGIN@8
# spent 26µs making 1 call to Exporter::import |
9 | |||||
10 | 2 | 75µs | 2 | 164µs | # spent 87µs (10+77) within Exception::Class::Base::BEGIN@10 which was called:
# once (10µs+77µs) by Exception::Class::BEGIN@7 at line 10 # spent 87µs making 1 call to Exception::Class::Base::BEGIN@10
# spent 77µs making 1 call to base::import |
11 | |||||
12 | # spent 94µs (41+54) within Exception::Class::Base::BEGIN@12 which was called:
# once (41µs+54µs) by Exception::Class::BEGIN@7 at line 27 | ||||
13 | 1 | 3µs | 1 | 11µs | __PACKAGE__->mk_classdata('Trace'); # spent 11µs making 1 call to Class::Data::Inheritable::mk_classdata |
14 | 1 | 1µs | 1 | 8µs | __PACKAGE__->mk_classdata('NoRefs'); # spent 8µs making 1 call to Class::Data::Inheritable::mk_classdata |
15 | 1 | 1µs | 1 | 3µs | __PACKAGE__->NoRefs(1); # spent 3µs making 1 call to Class::Data::Inheritable::__ANON__[Class/Data/Inheritable.pm:23] |
16 | |||||
17 | 1 | 1µs | 1 | 7µs | __PACKAGE__->mk_classdata('NoContextInfo'); # spent 7µs making 1 call to Class::Data::Inheritable::mk_classdata |
18 | 1 | 1µs | 1 | 2µs | __PACKAGE__->NoContextInfo(0); # spent 2µs making 1 call to Class::Data::Inheritable::__ANON__[Class/Data/Inheritable.pm:23] |
19 | |||||
20 | 1 | 1µs | 1 | 11µs | __PACKAGE__->mk_classdata('RespectOverload'); # spent 11µs making 1 call to Class::Data::Inheritable::mk_classdata |
21 | 1 | 1µs | 1 | 2µs | __PACKAGE__->RespectOverload(0); # spent 2µs making 1 call to Class::Data::Inheritable::__ANON__[Class/Data/Inheritable.pm:23] |
22 | |||||
23 | 1 | 1µs | 1 | 8µs | __PACKAGE__->mk_classdata('MaxArgLength'); # spent 8µs making 1 call to Class::Data::Inheritable::mk_classdata |
24 | 1 | 5µs | 1 | 2µs | __PACKAGE__->MaxArgLength(0); # spent 2µs making 1 call to Class::Data::Inheritable::__ANON__[Class/Data/Inheritable.pm:23] |
25 | |||||
26 | 424 | 3.92ms | # spent 334µs within Exception::Class::Base::Fields which was called 424 times, avg 789ns/call:
# 424 times (334µs+0s) by Perl::Critic::Exception::AggregateConfiguration::Fields at line 13 of (eval 46)[Exception/Class.pm:177], avg 789ns/call | ||
27 | 1 | 34µs | 1 | 94µs | } # spent 94µs making 1 call to Exception::Class::Base::BEGIN@12 |
28 | |||||
29 | use overload | ||||
30 | |||||
31 | # an exception is always true | ||||
32 | 6 | 80µs | 2 | 77µs | # spent 43µs (9+34) within Exception::Class::Base::BEGIN@32 which was called:
# once (9µs+34µs) by Exception::Class::BEGIN@7 at line 32
# spent 7µs within Exception::Class::Base::__ANON__[/Users/timbo/perl5/perlbrew/perls/perl-5.18.2/lib/site_perl/5.18.2/Exception/Class/Base.pm:32] which was called 4 times, avg 2µs/call:
# once (3µs+0s) by Perl::Critic::PolicyFactory::_init at line 149 of Perl/Critic/PolicyFactory.pm
# once (2µs+0s) by Perl::Critic::PolicyFactory::create_all_policies at line 229 of Perl/Critic/PolicyFactory.pm
# once (1µs+0s) by Perl::Critic::PolicyFactory::_init at line 161 of Perl/Critic/PolicyFactory.pm
# once (800ns+0s) by Perl::Critic::PolicyFactory::create_all_policies at line 213 of Perl/Critic/PolicyFactory.pm # spent 43µs making 1 call to Exception::Class::Base::BEGIN@32
# spent 34µs making 1 call to overload::import |
33 | |||||
34 | # Create accessor routines | ||||
35 | # spent 48µs within Exception::Class::Base::BEGIN@35 which was called:
# once (48µs+0s) by Exception::Class::BEGIN@7 at line 64 | ||||
36 | 1 | 2µs | my @fields = qw( message pid uid euid gid egid time trace ); | ||
37 | |||||
38 | 1 | 700ns | foreach my $f (@fields) { | ||
39 | 8 | 9µs | my $sub = sub { my $s = shift; return $s->{$f}; }; | ||
40 | |||||
41 | 2 | 109µs | 2 | 31µs | # spent 20µs (8+11) within Exception::Class::Base::BEGIN@41 which was called:
# once (8µs+11µs) by Exception::Class::BEGIN@7 at line 41 # spent 20µs making 1 call to Exception::Class::Base::BEGIN@41
# spent 11µs making 1 call to strict::unimport |
42 | 8 | 15µs | *{$f} = $sub; | ||
43 | } | ||||
44 | 1 | 500ns | *error = \&message; | ||
45 | |||||
46 | 1 | 2µs | my %trace_fields = ( | ||
47 | package => 'package', | ||||
48 | file => 'filename', | ||||
49 | line => 'line', | ||||
50 | ); | ||||
51 | |||||
52 | 1 | 9µs | while ( my ( $f, $m ) = each %trace_fields ) { | ||
53 | my $sub = sub { | ||||
54 | my $s = shift; | ||||
55 | return $s->{$f} if exists $s->{$f}; | ||||
56 | |||||
57 | my $frame = $s->trace->frame(0); | ||||
58 | |||||
59 | return $s->{$f} = $frame ? $frame->$m() : undef; | ||||
60 | 3 | 4µs | }; | ||
61 | 2 | 30µs | 2 | 29µs | # spent 18µs (8+10) within Exception::Class::Base::BEGIN@61 which was called:
# once (8µs+10µs) by Exception::Class::BEGIN@7 at line 61 # spent 18µs making 1 call to Exception::Class::Base::BEGIN@61
# spent 10µs making 1 call to strict::unimport |
62 | 3 | 3µs | *{$f} = $sub; | ||
63 | } | ||||
64 | 1 | 679µs | 1 | 48µs | } # spent 48µs making 1 call to Exception::Class::Base::BEGIN@35 |
65 | |||||
66 | sub Classes { Exception::Class::Classes() } | ||||
67 | |||||
68 | sub throw { | ||||
69 | my $proto = shift; | ||||
70 | |||||
71 | $proto->rethrow if ref $proto; | ||||
72 | |||||
73 | die $proto->new(@_); | ||||
74 | } | ||||
75 | |||||
76 | sub rethrow { | ||||
77 | my $self = shift; | ||||
78 | |||||
79 | die $self; | ||||
80 | } | ||||
81 | |||||
82 | # spent 255ms (2.23+253) within Exception::Class::Base::new which was called 424 times, avg 602µs/call:
# 424 times (2.23ms+253ms) by Perl::Critic::Exception::AggregateConfiguration::new at line 47 of Perl/Critic/Exception/AggregateConfiguration.pm, avg 602µs/call | ||||
83 | 424 | 93µs | my $proto = shift; | ||
84 | 424 | 88µs | my $class = ref $proto || $proto; | ||
85 | |||||
86 | 424 | 501µs | my $self = bless {}, $class; | ||
87 | |||||
88 | 424 | 480µs | 424 | 253ms | $self->_initialize(@_); # spent 253ms making 424 calls to Exception::Class::Base::_initialize, avg 597µs/call |
89 | |||||
90 | 424 | 770µs | return $self; | ||
91 | } | ||||
92 | |||||
93 | # spent 253ms (24.1+229) within Exception::Class::Base::_initialize which was called 424 times, avg 597µs/call:
# 424 times (24.1ms+229ms) by Exception::Class::Base::new at line 88, avg 597µs/call | ||||
94 | 424 | 46µs | my $self = shift; | ||
95 | 424 | 312µs | my %p = @_ == 1 ? ( error => $_[0] ) : @_; | ||
96 | |||||
97 | 424 | 462µs | $self->{message} = $p{message} || $p{error} || ''; | ||
98 | |||||
99 | 424 | 89µs | $self->{show_trace} = $p{show_trace} if exists $p{show_trace}; | ||
100 | |||||
101 | 424 | 634µs | 424 | 852µs | if ( $self->NoContextInfo() ) { # spent 852µs making 424 calls to Class::Data::Inheritable::__ANON__[Class/Data/Inheritable.pm:23], avg 2µs/call |
102 | $self->{show_trace} = 0; | ||||
103 | $self->{package} = $self->{file} = $self->{line} = undef; | ||||
104 | } | ||||
105 | else { | ||||
106 | # CORE::time is important to fix an error with some versions of | ||||
107 | # Perl | ||||
108 | 424 | 372µs | $self->{time} = CORE::time(); | ||
109 | 424 | 267µs | $self->{pid} = $$; | ||
110 | 424 | 479µs | $self->{uid} = $<; | ||
111 | 424 | 267µs | $self->{euid} = $>; | ||
112 | 424 | 1.57ms | $self->{gid} = $(; | ||
113 | 424 | 1.09ms | $self->{egid} = $); | ||
114 | |||||
115 | 424 | 259µs | my @ignore_class = (__PACKAGE__); | ||
116 | 424 | 145µs | my @ignore_package = 'Exception::Class'; | ||
117 | |||||
118 | 424 | 163µs | if ( my $i = delete $p{ignore_class} ) { | ||
119 | push @ignore_class, ( ref($i) eq 'ARRAY' ? @$i : $i ); | ||||
120 | } | ||||
121 | |||||
122 | 424 | 53µs | if ( my $i = delete $p{ignore_package} ) { | ||
123 | push @ignore_package, ( ref($i) eq 'ARRAY' ? @$i : $i ); | ||||
124 | } | ||||
125 | |||||
126 | 424 | 2.52ms | 1696 | 223ms | $self->{trace} = Devel::StackTrace->new( # spent 221ms making 424 calls to Devel::StackTrace::new, avg 520µs/call
# spent 2.06ms making 1272 calls to Class::Data::Inheritable::__ANON__[Class/Data/Inheritable.pm:23], avg 2µs/call |
127 | ignore_class => \@ignore_class, | ||||
128 | ignore_package => \@ignore_package, | ||||
129 | no_refs => $self->NoRefs, | ||||
130 | respect_overload => $self->RespectOverload, | ||||
131 | max_arg_length => $self->MaxArgLength, | ||||
132 | ); | ||||
133 | } | ||||
134 | |||||
135 | 424 | 1.32ms | 424 | 5.17ms | my %fields = map { $_ => 1 } $self->Fields; # spent 5.17ms making 424 calls to Perl::Critic::Exception::AggregateConfiguration::Fields, avg 12µs/call |
136 | 424 | 1.51ms | while ( my ( $key, $value ) = each %p ) { | ||
137 | 424 | 4.60ms | 424 | 520µs | next if $key =~ /^(?:error|message|show_trace)$/; # spent 520µs making 424 calls to Exception::Class::Base::CORE:match, avg 1µs/call |
138 | |||||
139 | 424 | 323µs | if ( $fields{$key} ) { | ||
140 | $self->{$key} = $value; | ||||
141 | } | ||||
142 | else { | ||||
143 | Exception::Class::Base->throw( | ||||
144 | error => "unknown field $key passed to constructor for class " | ||||
145 | . ref $self ); | ||||
146 | } | ||||
147 | } | ||||
148 | } | ||||
149 | |||||
150 | sub context_hash { | ||||
151 | my $self = shift; | ||||
152 | |||||
153 | return { | ||||
154 | time => $self->{time}, | ||||
155 | pid => $self->{pid}, | ||||
156 | uid => $self->{uid}, | ||||
157 | euid => $self->{euid}, | ||||
158 | gid => $self->{gid}, | ||||
159 | egid => $self->{egid}, | ||||
160 | }; | ||||
161 | } | ||||
162 | |||||
163 | sub field_hash { | ||||
164 | my $self = shift; | ||||
165 | |||||
166 | my $hash = {}; | ||||
167 | |||||
168 | for my $field ( $self->Fields ) { | ||||
169 | $hash->{$field} = $self->$field; | ||||
170 | } | ||||
171 | |||||
172 | return $hash; | ||||
173 | } | ||||
174 | |||||
175 | sub description { | ||||
176 | return 'Generic exception'; | ||||
177 | } | ||||
178 | |||||
179 | sub show_trace { | ||||
180 | my $self = shift; | ||||
181 | |||||
182 | return 0 unless $self->{trace}; | ||||
183 | |||||
184 | if (@_) { | ||||
185 | $self->{show_trace} = shift; | ||||
186 | } | ||||
187 | |||||
188 | return exists $self->{show_trace} ? $self->{show_trace} : $self->Trace; | ||||
189 | } | ||||
190 | |||||
191 | sub as_string { | ||||
192 | my $self = shift; | ||||
193 | |||||
194 | my $str = $self->full_message; | ||||
195 | unless ( defined $str && length $str ) { | ||||
196 | my $desc = $self->description; | ||||
197 | $str = defined $desc | ||||
198 | && length $desc ? "[$desc]" : "[Generic exception]"; | ||||
199 | } | ||||
200 | |||||
201 | $str .= "\n\n" . $self->trace->as_string | ||||
202 | if $self->show_trace; | ||||
203 | |||||
204 | return $str; | ||||
205 | } | ||||
206 | |||||
207 | sub full_message { $_[0]->{message} } | ||||
208 | |||||
209 | # | ||||
210 | # The %seen bit protects against circular inheritance. | ||||
211 | # | ||||
212 | 1 | 900ns | eval <<'EOF' if $] == 5.006; | ||
213 | sub isa { | ||||
214 | my ( $inheritor, $base ) = @_; | ||||
215 | $inheritor = ref($inheritor) if ref($inheritor); | ||||
216 | |||||
217 | my %seen; | ||||
218 | |||||
219 | no strict 'refs'; | ||||
220 | my @parents = ( $inheritor, @{"$inheritor\::ISA"} ); | ||||
221 | while ( my $class = shift @parents ) { | ||||
222 | return 1 if $class eq $base; | ||||
223 | |||||
224 | push @parents, grep { !$seen{$_}++ } @{"$class\::ISA"}; | ||||
225 | } | ||||
226 | return 0; | ||||
227 | } | ||||
228 | EOF | ||||
229 | |||||
230 | sub caught { | ||||
231 | my $class = shift; | ||||
232 | |||||
233 | my $e = $@; | ||||
234 | |||||
235 | return unless defined $e && blessed($e) && $e->isa($class); | ||||
236 | return $e; | ||||
237 | } | ||||
238 | |||||
239 | 1 | 8µs | 1; | ||
240 | |||||
241 | # ABSTRACT: A base class for exception objects | ||||
242 | |||||
243 | __END__ | ||||
# spent 520µs within Exception::Class::Base::CORE:match which was called 424 times, avg 1µs/call:
# 424 times (520µs+0s) by Exception::Class::Base::_initialize at line 137, avg 1µs/call |