← Index
NYTProf Performance Profile   « block view • line view • sub view »
For 05.Domain_and_Item.t
  Run on Tue May 4 17:21:41 2010
Reported on Tue May 4 17:23:14 2010

File /usr/local/lib/perl5/site_perl/5.10.1/Exception/Class/Base.pm
Statements Executed 257
Statement Execution Time 2.34ms
Subroutines — ordered by exclusive time
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
1111.50ms3.62msException::Class::Base::::BEGIN@9Exception::Class::Base::BEGIN@9
511387µs1.98msException::Class::Base::::_initializeException::Class::Base::_initialize
111301µs367µsException::Class::Base::::BEGIN@8Exception::Class::Base::BEGIN@8
511215µs2.20msException::Class::Base::::newException::Class::Base::new
4322213µs504µsException::Class::Base::::caughtException::Class::Base::caught
11172µs72µsException::Class::Base::::BEGIN@36Exception::Class::Base::BEGIN@36
51157µs2.26msException::Class::Base::::throwException::Class::Base::throw
11127µs71µsException::Class::Base::::BEGIN@14Exception::Class::Base::BEGIN@14
101222µs22µsException::Class::Base::::CORE:matchException::Class::Base::CORE:match (opcode)
11115µs17µsException::Class::Base::::BEGIN@3Exception::Class::Base::BEGIN@3
11114µs28µsException::Class::Base::::BEGIN@65Exception::Class::Base::BEGIN@65
52212µs12µsException::Class::Base::::__ANON__[:30]Exception::Class::Base::__ANON__[:30]
11110µs70µsException::Class::Base::::BEGIN@11Exception::Class::Base::BEGIN@11
5118µs8µsException::Class::Base::::FieldsException::Class::Base::Fields
1118µs17µsException::Class::Base::::BEGIN@4Exception::Class::Base::BEGIN@4
1118µs50µsException::Class::Base::::BEGIN@30Exception::Class::Base::BEGIN@30
1117µs18µsException::Class::Base::::BEGIN@43Exception::Class::Base::BEGIN@43
0000s0sException::Class::Base::::ClassesException::Class::Base::Classes
0000s0sException::Class::Base::::__ANON__[:41]Exception::Class::Base::__ANON__[:41]
0000s0sException::Class::Base::::__ANON__[:64]Exception::Class::Base::__ANON__[:64]
0000s0sException::Class::Base::::as_stringException::Class::Base::as_string
0000s0sException::Class::Base::::descriptionException::Class::Base::description
0000s0sException::Class::Base::::full_messageException::Class::Base::full_message
0000s0sException::Class::Base::::rethrowException::Class::Base::rethrow
0000s0sException::Class::Base::::show_traceException::Class::Base::show_trace
Call graph for these subroutines as a Graphviz dot language file.
Line State
ments
Time
on line
Calls Time
in subs
Code
1package Exception::Class::Base;
2
3321µs220µs
# spent 17µs (15+3) within Exception::Class::Base::BEGIN@3 which was called # once (15µs+3µs) by Exception::Class::BEGIN@7 at line 3
use strict;
# spent 17µs making 1 call to Exception::Class::Base::BEGIN@3 # spent 2µs making 1 call to strict::import
4334µs226µs
# spent 17µs (8+9) within Exception::Class::Base::BEGIN@4 which was called # once (8µs+9µs) by Exception::Class::BEGIN@7 at line 4
use warnings;
# spent 17µs making 1 call to Exception::Class::Base::BEGIN@4 # spent 9µs making 1 call to warnings::import
5
61600nsour $VERSION = '1.20';
7
83128µs1367µs
# spent 367µs (301+66) within Exception::Class::Base::BEGIN@8 which was called # once (301µs+66µs) by Exception::Class::BEGIN@7 at line 8
use Class::Data::Inheritable;
# spent 367µs making 1 call to Exception::Class::Base::BEGIN@8
93153µs23.66ms
# spent 3.62ms (1.50+2.12) within Exception::Class::Base::BEGIN@9 which was called # once (1.50ms+2.12ms) by Exception::Class::BEGIN@7 at line 9
use Devel::StackTrace 1.20;
# spent 3.62ms making 1 call to Exception::Class::Base::BEGIN@9 # spent 37µs making 1 call to UNIVERSAL::VERSION
10
11360µs2131µs
# spent 70µs (10+61) within Exception::Class::Base::BEGIN@11 which was called # once (10µs+61µs) by Exception::Class::BEGIN@7 at line 11
use base qw(Class::Data::Inheritable);
# spent 70µs making 1 call to Exception::Class::Base::BEGIN@11 # spent 60µs making 1 call to base::import
12
13BEGIN
14
# spent 71µs (27+44) within Exception::Class::Base::BEGIN@14 which was called # once (27µs+44µs) by Exception::Class::BEGIN@7 at line 26
{
1513µs110µs __PACKAGE__->mk_classdata('Trace');
# spent 10µs making 1 call to Class::Data::Inheritable::mk_classdata
161900ns17µs __PACKAGE__->mk_classdata('NoRefs');
# spent 7µs making 1 call to Class::Data::Inheritable::mk_classdata
1711µs13µs __PACKAGE__->NoRefs(1);
18
191700ns17µs __PACKAGE__->mk_classdata('RespectOverload');
# spent 7µs making 1 call to Class::Data::Inheritable::mk_classdata
201900ns12µs __PACKAGE__->RespectOverload(0);
21
221700ns112µs __PACKAGE__->mk_classdata('MaxArgLength');
# spent 12µs making 1 call to Class::Data::Inheritable::mk_classdata
2313µs12µs __PACKAGE__->MaxArgLength(0);
24
25518µs
# spent 8µs within Exception::Class::Base::Fields which was called 5 times, avg 2µs/call: # 5 times (8µs+0s) by SimpleDB::Class::Exception::ObjectNotFound::Fields at line 13 of (eval 0)[Exception/Class.pm:172] at line 172 of Exception/Class.pm, avg 2µs/call
sub Fields { () }
26132µs171µs}
# spent 71µs making 1 call to Exception::Class::Base::BEGIN@14
27
28use overload
29 # an exception is always true
30519µs
# spent 12µs within Exception::Class::Base::__ANON__[/usr/local/lib/perl5/site_perl/5.10.1/Exception/Class/Base.pm:30] which was called 5 times, avg 2µs/call: # 3 times (6µs+0s) by SimpleDB::Class::ResultSet::next at line 467 of ../lib/SimpleDB/Class/ResultSet.pm, avg 2µs/call # 2 times (6µs+0s) by SimpleDB::Class::Domain::find at line 158 of ../lib/SimpleDB/Class/Domain.pm, avg 3µs/call # spent 50µs (8+42) within Exception::Class::Base::BEGIN@30 which was called # once (8µs+42µs) by Exception::Class::BEGIN@7 at line 32
bool => sub { 1 },
3115µs142µs '""' => 'as_string',
# spent 42µs making 1 call to overload::import
32264µs150µs fallback => 1;
# spent 50µs making 1 call to Exception::Class::Base::BEGIN@30
33
34# Create accessor routines
35BEGIN
36
# spent 72µs within Exception::Class::Base::BEGIN@36 which was called # once (72µs+0s) by Exception::Class::BEGIN@7 at line 68
{
3713µs my @fields = qw( message pid uid euid gid egid time trace );
38
391900ns foreach my $f (@fields)
40 {
41824µs my $sub = sub { my $s = shift; return $s->{$f}; };
42
433105µs229µs
# spent 18µs (7+11) within Exception::Class::Base::BEGIN@43 which was called # once (7µs+11µs) by Exception::Class::BEGIN@7 at line 43
no strict 'refs';
# spent 18µs making 1 call to Exception::Class::Base::BEGIN@43 # spent 11µs making 1 call to strict::unimport
44814µs *{$f} = $sub;
45 }
461600ns *error = \&message;
47
4812µs my %trace_fields =
49 ( package => 'package',
50 file => 'filename',
51 line => 'line',
52 );
53
54114µs while ( my ( $f, $m ) = each %trace_fields )
55 {
56 my $sub = sub
57 {
58 my $s = shift;
59 return $s->{$f} if exists $s->{$f};
60
61 my $frame = $s->trace->frame(0);
62
63 return $s->{$f} = $frame ? $frame->$m() : undef;
6435µs };
65344µs242µs
# spent 28µs (14+14) within Exception::Class::Base::BEGIN@65 which was called # once (14µs+14µs) by Exception::Class::BEGIN@7 at line 65
no strict 'refs';
# spent 28µs making 1 call to Exception::Class::Base::BEGIN@65 # spent 14µs making 1 call to strict::unimport
6635µs *{$f} = $sub;
67 }
681711µs172µs}
# spent 72µs making 1 call to Exception::Class::Base::BEGIN@36
69
7010s1;
71
72sub Classes { Exception::Class::Classes() }
73
74sub throw
75
# spent 2.26ms (57µs+2.20) within Exception::Class::Base::throw which was called 5 times, avg 451µs/call: # 5 times (57µs+2.20ms) by SimpleDB::Class::Cache::get at line 259 of ../lib/SimpleDB/Class/Cache.pm, avg 451µs/call
{
7656µs my $proto = shift;
77
7852µs $proto->rethrow if ref $proto;
79
80565µs52.20ms die $proto->new(@_);
# spent 2.20ms making 5 calls to Exception::Class::Base::new, avg 440µs/call
81}
82
83sub rethrow
84{
85 my $self = shift;
86
87 die $self;
88}
89
90sub new
91
# spent 2.20ms (215µs+1.98) within Exception::Class::Base::new which was called 5 times, avg 440µs/call: # 5 times (215µs+1.98ms) by Exception::Class::Base::throw at line 80, avg 440µs/call
{
9253µs my $proto = shift;
9353µs my $class = ref $proto || $proto;
94
955173µs my $self = bless {}, $class;
96
97518µs51.98ms $self->_initialize(@_);
# spent 1.98ms making 5 calls to Exception::Class::Base::_initialize, avg 397µs/call
98
99516µs return $self;
100}
101
102sub _initialize
103
# spent 1.98ms (387µs+1.60) within Exception::Class::Base::_initialize which was called 5 times, avg 397µs/call: # 5 times (387µs+1.60ms) by Exception::Class::Base::new at line 97, avg 397µs/call
{
10453µs my $self = shift;
105520µs my %p = @_ == 1 ? ( error => $_[0] ) : @_;
106
107515µs $self->{message} = $p{message} || $p{error} || '';
108
10954µs $self->{show_trace} = $p{show_trace} if exists $p{show_trace};
110
111 # CORE::time is important to fix an error with some versions of
112 # Perl
11359µs $self->{time} = CORE::time();
11456µs $self->{pid} = $$;
11558µs $self->{uid} = $<;
11655µs $self->{euid} = $>;
117542µs $self->{gid} = $(;
118523µs $self->{egid} = $);
119
12058µs my @ignore_class = (__PACKAGE__);
12154µs my @ignore_package = 'Exception::Class';
122
12355µs if ( my $i = delete $p{ignore_class} )
124 {
125 push @ignore_class, ( ref($i) eq 'ARRAY' ? @$i : $i );
126 }
127
12853µs if ( my $i = delete $p{ignore_package} )
129 {
130 push @ignore_package, ( ref($i) eq 'ARRAY' ? @$i : $i );
131 }
132
133581µs201.49ms $self->{trace} =
# spent 1.43ms making 5 calls to Devel::StackTrace::new, avg 287µs/call # spent 57µs making 15 calls to Class::Data::Inheritable::__ANON__[Class/Data/Inheritable.pm:23], avg 4µs/call
134 Devel::StackTrace->new( ignore_class => \@ignore_class,
135 ignore_package => \@ignore_package,
136 no_refs => $self->NoRefs,
137 respect_overload => $self->RespectOverload,
138 max_arg_length => $self->MaxArgLength,
139 );
140
141528µs585µs my %fields = map { $_ => 1 } $self->Fields;
# spent 85µs making 5 calls to SimpleDB::Class::Exception::ObjectNotFound::Fields, avg 17µs/call
142544µs while ( my ($key, $value) = each %p )
143 {
1441056µs1022µs next if $key =~ /^(?:error|message|show_trace)$/;
# spent 22µs making 10 calls to Exception::Class::Base::CORE:match, avg 2µs/call
145
14659µs if ( $fields{$key})
147 {
148 $self->{$key} = $value;
149 }
150 else
151 {
152 Exception::Class::Base->throw
153 ( error =>
154 "unknown field $key passed to constructor for class " . ref $self );
155 }
156 }
157}
158
159sub description
160{
161 return 'Generic exception';
162}
163
164sub show_trace
165{
166 my $self = shift;
167
168 if (@_)
169 {
170 $self->{show_trace} = shift;
171 }
172
173 return exists $self->{show_trace} ? $self->{show_trace} : $self->Trace;
174}
175
176sub as_string
177{
178 my $self = shift;
179
180 my $str = $self->full_message;
181 $str .= "\n\n" . $self->trace->as_string
182 if $self->show_trace;
183
184 return $str;
185}
186
187sub full_message { $_[0]->{message} }
188
189#
190# The %seen bit protects against circular inheritance.
191#
1921900nseval <<'EOF' if $] == 5.006;
193sub isa
194{
195 my ($inheritor, $base) = @_;
196 $inheritor = ref($inheritor) if ref($inheritor);
197
198 my %seen;
199
200 no strict 'refs';
201 my @parents = ($inheritor, @{"$inheritor\::ISA"});
202 while (my $class = shift @parents)
203 {
204 return 1 if $class eq $base;
205
206 push @parents, grep {!$seen{$_}++} @{"$class\::ISA"};
207 }
208 return 0;
209}
210EOF
211
212sub caught
213
# spent 504µs (213+290) within Exception::Class::Base::caught which was called 43 times, avg 12µs/call: # 33 times (154µs+207µs) by SimpleDB::Class::ResultSet::next at line 467 of ../lib/SimpleDB/Class/ResultSet.pm, avg 11µs/call # 10 times (59µs+84µs) by SimpleDB::Class::Domain::find at line 158 of ../lib/SimpleDB/Class/Domain.pm, avg 14µs/call
{
21443202µs43291µs return Exception::Class->caught(shift);
# spent 291µs making 43 calls to Exception::Class::caught, avg 7µs/call
215}
216
21715µs1;
218
219=head1 NAME
220
221Exception::Class::Base - Base class for exception classes created by Exception::Class
222
223=head1 SYNOPSIS
224
225 use Exception::Class 'MyException';
226
227 eval { MyException->throw( error => 'I feel funny.' ) };
228
229 print $@->error();
230
231=head1 DESCRIPTION
232
233This class is the base class for all exceptions created by
234L<Exception::Class>. It provides a number of methods for getting
235information about the exception.
236
237=head1 METHODS
238
239=head2 MyException->Trace($boolean)
240
241Each C<Exception::Class::Base> subclass can be set individually to
242include a a stracktrace when the C<as_string> method is called. The
243default is to not include a stacktrace. Calling this method with a
244value changes this behavior. It always returns the current value
245(after any change is applied).
246
247This value is inherited by any subclasses. However, if this value is
248set for a subclass, it will thereafter be independent of the value in
249C<Exception::Class::Base>.
250
251Do not call this on the C<Exception::Class::Base> class directly or
252you'll change it for all exception classes that use
253L<Exception::Class>, including ones created in modules you don't
254control.
255
256This is a class method, not an object method.
257
258=head2 MyException->NoRefs($boolean)
259
260When a C<Devel::StackTrace> object is created, it walks through the
261stack and stores the arguments which were passed to each subroutine on
262the stack. If any of these arguments are references, then that means
263that the C<Devel::StackTrace> ends up increasing the refcount of these
264references, delaying their destruction.
265
266Since C<Exception::Class::Base> uses C<Devel::StackTrace> internally,
267this method provides a way to tell C<Devel::StackTrace> not to store
268these references. Instead, C<Devel::StackTrace> replaces references
269with their stringified representation.
270
271This method defaults to true. As with C<Trace()>, it is inherited by
272subclasses but setting it in a subclass makes it independent
273thereafter.
274
275Do not call this on the C<Exception::Class::Base> class directly or
276you'll change it for all exception classes that use
277L<Exception::Class>, including ones created in modules you don't
278control.
279
280=head2 MyException->RespectOverload($boolean)
281
282When a C<Devel::StackTrace> object stringifies, by default it ignores
283stringification overloading on any objects being dealt with.
284
285Since C<Exception::Class::Base> uses C<Devel::StackTrace> internally,
286this method provides a way to tell C<Devel::StackTrace> to respect
287overloading.
288
289This method defaults to false. As with C<Trace()>, it is inherited by
290subclasses but setting it in a subclass makes it independent
291thereafter.
292
293Do not call this on the C<Exception::Class::Base> class directly or
294you'll change it for all exception classes that use
295L<Exception::Class>, including ones created in modules you don't
296control.
297
298=head2 MyException->MaxArgLength($boolean)
299
300When a C<Devel::StackTrace> object stringifies, by default it displays
301the full argument for each function. This parameter can be used to
302limit the maximum length of each argument.
303
304Since C<Exception::Class::Base> uses C<Devel::StackTrace> internally,
305this method provides a way to tell C<Devel::StackTrace> to limit the
306length of arguments.
307
308This method defaults to 0. As with C<Trace()>, it is inherited by
309subclasses but setting it in a subclass makes it independent
310thereafter.
311
312Do not call this on the C<Exception::Class::Base> class directly or
313you'll change it for all exception classes that use
314L<Exception::Class>, including ones created in modules you don't
315control.
316
317=head2 MyException->Fields
318
319This method returns the extra fields defined for the given class, as
320an array.
321
322Do not call this on the C<Exception::Class::Base> class directly or
323you'll change it for all exception classes that use
324L<Exception::Class>, including ones created in modules you don't
325control.
326
327=head2 MyException->throw( $message )
328
329=head2 MyException->throw( message => $message )
330
331=head2 MyException->throw( error => $error )
332
333This method creates a new object with the given error message. If no
334error message is given, this will be an empty string. It then die's
335with this object as its argument.
336
337This method also takes a C<show_trace> parameter which indicates
338whether or not the particular exception object being created should
339show a stacktrace when its C<as_string()> method is called. This
340overrides the value of C<Trace()> for this class if it is given.
341
342The frames included in the trace can be controlled by the C<ignore_class>
343and C<ignore_package> parameters. These are passed directly to
344Devel::Stacktrace's constructor. See C<Devel::Stacktrace> for more details.
345
346If only a single value is given to the constructor it is assumed to be
347the message parameter.
348
349Additional keys corresponding to the fields defined for the particular
350exception subclass will also be accepted.
351
352=head2 MyException->new(...)
353
354This method takes the same parameters as C<throw()>, but instead of
355dying simply returns a new exception object.
356
357This method is always called when constructing a new exception object
358via the C<throw()> method.
359
360=head2 MyException->description()
361
362Returns the description for the given C<Exception::Class::Base>
363subclass. The C<Exception::Class::Base> class's description is
364"Generic exception" (this may change in the future). This is also an
365object method.
366
367=head2 $exception->rethrow()
368
369Simply dies with the object as its sole argument. It's just syntactic
370sugar. This does not change any of the object's attribute values.
371However, it will cause C<caller()> to report the die as coming from
372within the C<Exception::Class::Base> class rather than where rethrow
373was called.
374
375Of course, you always have access to the original stacktrace for the
376exception object.
377
378=head2 $exception->message()
379
380=head2 $exception->error()
381
382Returns the error/message associated with the exception.
383
384=head2 $exception->pid()
385
386Returns the pid at the time the exception was thrown.
387
388=head2 $exception->uid()
389
390Returns the real user id at the time the exception was thrown.
391
392=head2 $exception->gid()
393
394Returns the real group id at the time the exception was thrown.
395
396=head2 $exception->euid()
397
398Returns the effective user id at the time the exception was thrown.
399
400=head2 $exception->egid()
401
402Returns the effective group id at the time the exception was thrown.
403
404=head2 $exception->time()
405
406Returns the time in seconds since the epoch at the time the exception
407was thrown.
408
409=head2 $exception->package()
410
411Returns the package from which the exception was thrown.
412
413=head2 $exception->file()
414
415Returns the file within which the exception was thrown.
416
417=head2 $exception->line()
418
419Returns the line where the exception was thrown.
420
421=head2 $exception->trace()
422
423Returns the trace object associated with the object.
424
425=head2 $exception->show_trace($boolean)
426
427This method can be used to set whether or not a strack trace is
428included when the as_string method is called or the object is
429stringified.
430
431=head2 $exception->as_string()
432
433Returns a string form of the error message (something like what you'd
434expect from die). If the class or object is set to show traces then
435then the full trace is also included. The result looks like
436C<Carp::confess()>.
437
438=head2 $exception->full_message()
439
440Called by the C<as_string()> method to get the message. By default,
441this is the same as calling the C<message()> method, but may be
442overridden by a subclass. See below for details.
443
444=head1 OVERLOADING
445
446C<Exception::Class::Base> objects are overloaded so that
447stringification produces a normal error message. This just calls the
448C<< $exception->as_string() >> method described above. This means
449that you can just C<print $@> after an C<eval> and not worry about
450whether or not its an actual object. It also means an application or
451module could do this:
452
453 $SIG{__DIE__} = sub { Exception::Class::Base->throw( error => join '', @_ ); };
454
455and this would probably not break anything (unless someone was
456expecting a different type of exception object from C<die()>).
457
458=head1 OVERRIDING THE as_string METHOD
459
460By default, the C<as_string()> method simply returns the value
461C<message> or C<error> param plus a stack trace, if the class's
462C<Trace()> method returns a true value or C<show_trace> was set when
463creating the exception.
464
465However, once you add new fields to a subclass, you may want to
466include those fields in the stringified error.
467
468Inside the C<as_string()> method, the message (non-stack trace)
469portion of the error is generated by calling the C<full_message()>
470method. This can be easily overridden. For example:
471
472 sub full_message
473 {
474 my $self = shift;
475
476 my $msg = $self->message;
477
478 $msg .= " and foo was " . $self->foo;
479
480 return $msg;
481 }
482
483=head1 AUTHOR
484
485Dave Rolsky, E<gt>autarch@urth.orgE<lt>
486
487=head1 COPYRIGHT
488
489Copyright (c) 2000-2009 David Rolsky. All rights reserved. This
490program is free software; you can redistribute it and/or modify it
491under the same terms as Perl itself.
492
493The full text of the license can be found in the LICENSE file included
494with this module.
495
496=cut
# spent 22µs within Exception::Class::Base::CORE:match which was called 10 times, avg 2µs/call: # 10 times (22µs+0s) by Exception::Class::Base::_initialize at line 144 of Exception/Class/Base.pm, avg 2µs/call
sub Exception::Class::Base::CORE:match; # xsub