← Index
NYTProf Performance Profile   « line view »
For bin/benchmark-perlformance
  Run on Fri Apr 17 15:31:48 2015
Reported on Fri Apr 17 15:32:02 2015

Filename/home/ss5/perl5/perlbrew/perls/tapper-perl/lib/site_perl/5.16.3/Exception/Class.pm
StatementsExecuted 264 statements in 1.33ms
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
111859µs4.71msException::Class::::BEGIN@10Exception::Class::BEGIN@10
811599µs1.19msException::Class::::_make_subclassException::Class::_make_subclass
11181µs1.28msException::Class::::importException::Class::import
11114µs14µsException::Class::::BEGIN@6Exception::Class::BEGIN@6
11113µs26µsException::Class::::BEGIN@8Exception::Class::BEGIN@8
1119µs9µsException::Class::::CORE:sortException::Class::CORE:sort (opcode)
8118µs8µsException::Class::::CORE:substException::Class::CORE:subst (opcode)
1117µs30µsException::Class::::BEGIN@11Exception::Class::BEGIN@11
1117µs16µsException::Class::::BEGIN@79Exception::Class::BEGIN@79
1117µs16µsException::Class::::BEGIN@168Exception::Class::BEGIN@168
1117µs16µsException::Class::::BEGIN@46Exception::Class::BEGIN@46
1116µs14µsException::Class::::BEGIN@176Exception::Class::BEGIN@176
2114µs4µsException::Class::::CORE:substcontException::Class::CORE:substcont (opcode)
1113µs3µsException::Class::::BEGIN@14Exception::Class::BEGIN@14
0000s0sException::Class::::ClassesException::Class::Classes
0000s0sException::Class::::__ANON__[:170]Exception::Class::__ANON__[:170]
0000s0sException::Class::::_make_parentsException::Class::_make_parents
0000s0sException::Class::::caughtException::Class::caught
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;
2{
32800ns $Exception::Class::VERSION = '1.37';
4}
5
6252µs114µs
# spent 14µs within Exception::Class::BEGIN@6 which was called: # once (14µs+0s) by Iterator::BEGIN@22 at line 6
use 5.008001;
# spent 14µs making 1 call to Exception::Class::BEGIN@6
7
8234µs239µs
# spent 26µs (13+13) within Exception::Class::BEGIN@8 which was called: # once (13µs+13µs) by Iterator::BEGIN@22 at line 8
use strict;
# spent 26µs making 1 call to Exception::Class::BEGIN@8 # spent 13µs making 1 call to strict::import
9
102115µs14.71ms
# spent 4.71ms (859µs+3.85) within Exception::Class::BEGIN@10 which was called: # once (859µs+3.85ms) by Iterator::BEGIN@22 at line 10
use Exception::Class::Base;
# spent 4.71ms making 1 call to Exception::Class::BEGIN@10
11230µs252µs
# spent 30µs (7+22) within Exception::Class::BEGIN@11 which was called: # once (7µs+22µs) by Iterator::BEGIN@22 at line 11
use Scalar::Util qw(blessed);
# spent 30µs making 1 call to Exception::Class::BEGIN@11 # spent 22µs making 1 call to Exporter::import
12
131100nsour $BASE_EXC_CLASS;
14188µs13µs
# spent 3µs within Exception::Class::BEGIN@14 which was called: # once (3µs+0s) by Iterator::BEGIN@22 at line 14
BEGIN { $BASE_EXC_CLASS ||= 'Exception::Class::Base'; }
# spent 3µs making 1 call to Exception::Class::BEGIN@14
15
161300nsour %CLASSES;
17
18
# spent 1.28ms (81µs+1.20) within Exception::Class::import which was called: # once (81µs+1.20ms) by Iterator::BEGIN@22 at line 23 of Iterator.pm
sub import {
191400ns my $class = shift;
20
211500ns local $Exception::Class::Caller = caller();
22
231100ns my %c;
24
251100ns my %needs_parent;
2613µs while ( my $subclass = shift ) {
2782µs my $def = ref $_[0] ? shift : {};
2885µs $def->{isa}
29 = $def->{isa}
30 ? ( ref $def->{isa} ? $def->{isa} : [ $def->{isa} ] )
31 : [];
32
3384µs $c{$subclass} = $def;
34 }
35
36 # We need to sort by length because if we check for keys in the
37 # Foo::Bar:: stash, this creates a "Bar::" key in the Foo:: stash!
38MAKE_CLASSES:
39116µs19µs foreach my $subclass ( sort { length $a <=> length $b } keys %c ) {
# spent 9µs making 1 call to Exception::Class::CORE:sort
4083µs my $def = $c{$subclass};
41
42 # We already made this one.
4382µs next if $CLASSES{$subclass};
44
45 {
4610113µs225µs
# spent 16µs (7+9) within Exception::Class::BEGIN@46 which was called: # once (7µs+9µs) by Iterator::BEGIN@22 at line 46
no strict 'refs';
# spent 16µs making 1 call to Exception::Class::BEGIN@46 # spent 9µs making 1 call to strict::unimport
4786µs foreach my $parent ( @{ $def->{isa} } ) {
48710µs unless ( keys %{"$parent\::"} ) {
49 $needs_parent{$subclass} = {
50 parents => $def->{isa},
51 def => $def
52 };
53 next MAKE_CLASSES;
54 }
55 }
56 }
57
58 $class->_make_subclass(
59820µs81.19ms subclass => $subclass,
# spent 1.19ms making 8 calls to Exception::Class::_make_subclass, avg 149µs/call
60 def => $def || {},
61 );
62 }
63
6415µs foreach my $subclass ( keys %needs_parent ) {
65
66 # This will be used to spot circular references.
67 my %seen;
68 $class->_make_parents( \%needs_parent, $subclass, \%seen );
69 }
70}
71
72sub _make_parents {
73 my $class = shift;
74 my $needs = shift;
75 my $subclass = shift;
76 my $seen = shift;
77 my $child = shift; # Just for error messages.
78
792257µs224µs
# spent 16µs (7+8) within Exception::Class::BEGIN@79 which was called: # once (7µs+8µs) by Iterator::BEGIN@22 at line 79
no strict 'refs';
# spent 16µs making 1 call to Exception::Class::BEGIN@79 # spent 8µs making 1 call to strict::unimport
80
81 # What if someone makes a typo in specifying their 'isa' param?
82 # This should catch it. Either it's been made because it didn't
83 # have missing parents OR it's in our hash as needing a parent.
84 # If neither of these is true then the _only_ place it is
85 # mentioned is in the 'isa' param for some other class, which is
86 # not a good enough reason to make a new class.
87 die
88 "Class $subclass appears to be a typo as it is only specified in the 'isa' param for $child\n"
89 unless exists $needs->{$subclass}
90 || $CLASSES{$subclass}
91 || keys %{"$subclass\::"};
92
93 foreach my $c ( @{ $needs->{$subclass}{parents} } ) {
94
95 # It's been made
96 next if $CLASSES{$c} || keys %{"$c\::"};
97
98 die "There appears to be some circularity involving $subclass\n"
99 if $seen->{$subclass};
100
101 $seen->{$subclass} = 1;
102
103 $class->_make_parents( $needs, $c, $seen, $subclass );
104 }
105
106 return if $CLASSES{$subclass} || keys %{"$subclass\::"};
107
108 $class->_make_subclass(
109 subclass => $subclass,
110 def => $needs->{$subclass}{def}
111 );
112}
113
114
# spent 1.19ms (599µs+591µs) within Exception::Class::_make_subclass which was called 8 times, avg 149µs/call: # 8 times (599µs+591µs) by Exception::Class::import at line 59, avg 149µs/call
sub _make_subclass {
11582µs my $class = shift;
11689µs my %p = @_;
117
11883µs my $subclass = $p{subclass};
11981µs my $def = $p{def};
120
1218800ns my $isa;
12288µs if ( $def->{isa} ) {
123 $isa = ref $def->{isa} ? join ' ', @{ $def->{isa} } : $def->{isa};
124 }
12581µs $isa ||= $BASE_EXC_CLASS;
126
12781µs my $version_name = 'VERSION';
128
12986µs my $code = <<"EOPERL";
130package $subclass;
131
132use base qw($isa);
133
134our \$$version_name = '1.1';
135
1361;
137
138EOPERL
139
14083µs if ( $def->{description} ) {
141836µs1012µs ( my $desc = $def->{description} ) =~ s/([\\\'])/\\$1/g;
# spent 8µs making 8 calls to Exception::Class::CORE:subst, avg 963ns/call # spent 4µs making 2 calls to Exception::Class::CORE:substcont, avg 2µs/call
14286µs $code .= <<"EOPERL";
143sub description
144{
145 return '$desc';
146}
147EOPERL
148 }
149
15081µs my @fields;
15183µs if ( my $fields = $def->{fields} ) {
152311µs34µs @fields = UNIVERSAL::isa( $fields, 'ARRAY' ) ? @$fields : $fields;
# spent 4µs making 3 calls to UNIVERSAL::isa, avg 1µs/call
153
154 $code
155 .= "sub Fields { return (\$_[0]->SUPER::Fields, "
15636µs . join( ", ", map { "'$_'" } @fields )
157 . ") }\n\n";
158
15931µs foreach my $field (@fields) {
16035µs $code .= sprintf( "sub %s { \$_[0]->{%s} }\n", $field, $field );
161 }
162 }
163
16482µs if ( my $alias = $def->{alias} ) {
165 die "Cannot make alias without caller"
166 unless defined $Exception::Class::Caller;
167
168258µs225µs
# spent 16µs (7+9) within Exception::Class::BEGIN@168 which was called: # once (7µs+9µs) by Iterator::BEGIN@22 at line 168
no strict 'refs';
# spent 16µs making 1 call to Exception::Class::BEGIN@168 # spent 9µs making 1 call to strict::unimport
169 *{"$Exception::Class::Caller\::$alias"}
170 = sub { $subclass->throw(@_) };
171 }
172
17381µs if ( my $defaults = $def->{defaults} ) {
174 $code
175 .= "sub _defaults { return shift->SUPER::_defaults, our \%_DEFAULTS }\n";
1762126µs221µs
# spent 14µs (6+7) within Exception::Class::BEGIN@176 which was called: # once (6µs+7µs) by Iterator::BEGIN@22 at line 176
no strict 'refs';
# spent 14µs making 1 call to Exception::Class::BEGIN@176 # spent 7µs making 1 call to strict::unimport
177 *{"$subclass\::_DEFAULTS"} = {%$defaults};
178 }
179
1808236µs eval $code;
# spent 54µs executing statements in string eval
# includes 8µs spent executing 1 call to 4 subs defined therein. # spent 51µs executing statements in string eval
# includes 8µs spent executing 1 call to 4 subs defined therein. # spent 51µs executing statements in string eval
# includes 8µs spent executing 1 call to 4 subs defined therein. # spent 33µs executing statements in string eval
# includes 8µs spent executing 1 call to 2 subs defined therein. # spent 28µs executing statements in string eval
# includes 9µs spent executing 1 call to 2 subs defined therein. # spent 28µs executing statements in string eval
# includes 9µs spent executing 1 call to 2 subs defined therein. # spent 28µs executing statements in string eval
# includes 8µs spent executing 1 call to 2 subs defined therein. # spent 28µs executing statements in string eval
# includes 8µs spent executing 1 call to 2 subs defined therein.
181
1828900ns die $@ if $@;
183
184831µs $CLASSES{$subclass} = 1;
185}
186
187sub caught {
188 my $e = $@;
189
190 return $e unless $_[1];
191
192 return unless blessed($e) && $e->isa( $_[1] );
193 return $e;
194}
195
196sub Classes { sort keys %Exception::Class::CLASSES }
197
19812µs1;
199
200# ABSTRACT: A module that allows you to declare real exception classes in Perl
201
202__END__
 
# spent 9µs within Exception::Class::CORE:sort which was called: # once (9µs+0s) by Exception::Class::import at line 39
sub Exception::Class::CORE:sort; # opcode
# spent 8µs within Exception::Class::CORE:subst which was called 8 times, avg 963ns/call: # 8 times (8µs+0s) by Exception::Class::_make_subclass at line 141, avg 963ns/call
sub Exception::Class::CORE:subst; # opcode
# spent 4µs within Exception::Class::CORE:substcont which was called 2 times, avg 2µs/call: # 2 times (4µs+0s) by Exception::Class::_make_subclass at line 141, avg 2µs/call
sub Exception::Class::CORE:substcont; # opcode