← Index
NYTProf Performance Profile   « line view »
For fastest.pl
  Run on Fri Jan 31 20:48:16 2014
Reported on Fri Jan 31 20:49:40 2014

Filename/opt/perl-5.18.1/lib/site_perl/5.18.1/Try/Tiny.pm
StatementsExecuted 11638 statements in 18.8ms
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
45211814.7ms152msTry::Tiny::::try Try::Tiny::try (recurses: max depth 3, inclusive time 57.6ms)
4521181.49ms1.49msTry::Tiny::::catch Try::Tiny::catch
1111.25ms1.59msTry::Tiny::ScopeGuard::::BEGIN@146Try::Tiny::ScopeGuard::BEGIN@146
11150µs924µsTry::Tiny::::BEGIN@20 Try::Tiny::BEGIN@20
11112µs12µsTry::Tiny::::BEGIN@8 Try::Tiny::BEGIN@8
11110µs10µsTry::Tiny::::BEGIN@2 Try::Tiny::BEGIN@2
11110µs52µsTry::Tiny::::BEGIN@17 Try::Tiny::BEGIN@17
1119µs25µsTry::Tiny::::BEGIN@11 Try::Tiny::BEGIN@11
1119µs13µsTry::Tiny::::BEGIN@12 Try::Tiny::BEGIN@12
1118µs86µsTry::Tiny::::BEGIN@14 Try::Tiny::BEGIN@14
0000s0sTry::Tiny::ScopeGuard::::DESTROYTry::Tiny::ScopeGuard::DESTROY
0000s0sTry::Tiny::ScopeGuard::::_newTry::Tiny::ScopeGuard::_new
0000s0sTry::Tiny::::__ANON__[:20] Try::Tiny::__ANON__[:20]
0000s0sTry::Tiny::::finally Try::Tiny::finally
Call graph for these subroutines as a Graphviz dot language file.
Line State
ments
Time
on line
Calls Time
in subs
Code
1package Try::Tiny;
2
# spent 10µs within Try::Tiny::BEGIN@2 which was called: # once (10µs+0s) by Module::Implementation::BEGIN@13 at line 4
BEGIN {
316µs $Try::Tiny::AUTHORITY = 'cpan:NUFFIN';
4136µs110µs}
# spent 10µs making 1 call to Try::Tiny::BEGIN@2
5{
621µs $Try::Tiny::VERSION = '0.18';
7}
8254µs112µs
# spent 12µs within Try::Tiny::BEGIN@8 which was called: # once (12µs+0s) by Module::Implementation::BEGIN@13 at line 8
use 5.006;
# spent 12µs making 1 call to Try::Tiny::BEGIN@8
9# ABSTRACT: minimal try/catch with proper preservation of $@
10
11230µs241µs
# spent 25µs (9+16) within Try::Tiny::BEGIN@11 which was called: # once (9µs+16µs) by Module::Implementation::BEGIN@13 at line 11
use strict;
# spent 25µs making 1 call to Try::Tiny::BEGIN@11 # spent 16µs making 1 call to strict::import
12230µs218µs
# spent 13µs (9+5) within Try::Tiny::BEGIN@12 which was called: # once (9µs+5µs) by Module::Implementation::BEGIN@13 at line 12
use warnings;
# spent 13µs making 1 call to Try::Tiny::BEGIN@12 # spent 5µs making 1 call to warnings::import
13
14261µs2165µs
# spent 86µs (8+78) within Try::Tiny::BEGIN@14 which was called: # once (8µs+78µs) by Module::Implementation::BEGIN@13 at line 14
use base 'Exporter';
# spent 86µs making 1 call to Try::Tiny::BEGIN@14 # spent 78µs making 1 call to base::import
1512µsour @EXPORT = our @EXPORT_OK = qw(try catch finally);
16
17262µs294µs
# spent 52µs (10+42) within Try::Tiny::BEGIN@17 which was called: # once (10µs+42µs) by Module::Implementation::BEGIN@13 at line 17
use Carp;
# spent 52µs making 1 call to Try::Tiny::BEGIN@17 # spent 42µs making 1 call to Exporter::import
181800ns$Carp::Internal{+__PACKAGE__}++;
19
201581µs1924µs
# spent 924µs (50+874) within Try::Tiny::BEGIN@20 which was called: # once (50µs+874µs) by Module::Implementation::BEGIN@13 at line 20
BEGIN { eval "use Sub::Name; 1" or *{subname} = sub {1} }
# spent 924µs making 1 call to Try::Tiny::BEGIN@20
# spent 140µs executing statements in string eval
# includes 365µs spent executing 1 call to 1 sub defined therein.
21
22# Need to prototype as @ not $$ because of the way Perl evaluates the prototype.
23# Keeping it at $$ means you only ever get 1 sub because we need to eval in a list
24# context & not a scalar one
25
26
# spent 152ms (14.7+138) within Try::Tiny::try which was called 452 times, avg 337µs/call: # 191 times (3.37ms+36.3ms) by Class::MOP::Attribute::_process_accessors at line 401 of Class/MOP/Attribute.pm, avg 208µs/call # 124 times (8.52ms+67.1ms) by Class::MOP::Class::_post_add_attribute at line 896 of Class/MOP/Class.pm, avg 610µs/call # 55 times (1.20ms+-1.20ms) by Class::MOP::Method::Accessor::_generate_reader_method_inline at line 157 of Class/MOP/Method/Accessor.pm, avg 0s/call # 31 times (599µs+32.1ms) by Class::MOP::Method::Constructor::_generate_constructor_method_inline at line 115 of Class/MOP/Method/Constructor.pm, avg 1.05ms/call # 23 times (464µs+-464µs) by Class::MOP::Method::Accessor::_generate_accessor_method_inline at line 123 of Class/MOP/Method/Accessor.pm, avg 0s/call # 16 times (307µs+-307µs) by Class::MOP::Method::Accessor::_generate_predicate_method_inline at line 212 of Class/MOP/Method/Accessor.pm, avg 0s/call # 3 times (91µs+2.28ms) by Module::Implementation::_load_implementation at line 93 of Module/Implementation.pm, avg 791µs/call # 3 times (57µs+-57µs) by Class::MOP::Method::Accessor::_generate_writer_method_inline at line 187 of Class/MOP/Method/Accessor.pm, avg 0s/call # 3 times (71µs+-71µs) by Moose::Meta::Method::Accessor::_compile_code at line 47 of Moose/Meta/Method/Accessor.pm, avg 0s/call # 2 times (45µs+1.72ms) by Class::Load::try_load_class at line 183 of Class/Load.pm, avg 884µs/call # once (22µs+246µs) by Moose::Meta::Method::Destructor::_initialize_body at line 106 of Moose/Meta/Method/Destructor.pm
sub try (&;@) {
27452210µs my ( $try, @code_refs ) = @_;
28
29 # we need to save this here, the eval block will be in scalar context due
30 # to $failed
3145295µs my $wantarray = wantarray;
32
33 # work around perl bug by explicitly initializing these, due to the likelyhood
34 # this will be used in global destruction (perl rt#119311)
35452103µs my ( $catch, @finally ) = ();
36
37 # find labeled blocks in the argument list.
38 # catch and finally tag the blocks by blessing a scalar reference to them.
39452279µs foreach my $code_ref (@code_refs) {
40
41452620µs if ( ref($code_ref) eq 'Try::Tiny::Catch' ) {
4245246µs croak 'A try() may not be followed by multiple catch() blocks'
43 if $catch;
44452152µs $catch = ${$code_ref};
45 } elsif ( ref($code_ref) eq 'Try::Tiny::Finally' ) {
46 push @finally, ${$code_ref};
47 } else {
48 croak(
49 'try() encountered an unexpected argument ('
50 . ( defined $code_ref ? $code_ref : 'undef' )
51 . ') - perhaps a missing semi-colon before or'
52 );
53 }
54 }
55
56 # FIXME consider using local $SIG{__DIE__} to accumulate all errors. It's
57 # not perfect, but we could provide a list of additional errors for
58 # $catch->();
59
60 # name the blocks if we have Sub::Name installed
61452221µs my $caller = caller;
624528.65ms4521.31ms subname("${caller}::try {...} " => $try);
# spent 1.31ms making 452 calls to Sub::Name::subname, avg 3µs/call
634521.70ms452871µs subname("${caller}::catch {...} " => $catch) if $catch;
# spent 871µs making 452 calls to Sub::Name::subname, avg 2µs/call
64452205µs subname("${caller}::finally {...} " => $_) foreach @finally;
65
66 # save the value of $@ so we can set $@ back to it in the beginning of the eval
67 # and restore $@ after the eval finishes
6845291µs my $prev_error = $@;
69
7045229µs my ( @ret, $error );
71
72 # failed will be true if the eval dies, because 1 will not be returned
73 # from the eval body
74452257µs my $failed = not eval {
7545246µs $@ = $prev_error;
76
77 # evaluate the try block in the correct context
78452566µs13463.2ms if ( $wantarray ) {
# spent 31.9ms making 31 calls to Class::MOP::Method::Constructor::try {...} , avg 1.03ms/call # spent 28.1ms making 97 calls to Class::MOP::Method::Accessor::try {...} , avg 289µs/call # spent 1.71ms making 2 calls to Class::Load::try {...} , avg 857µs/call # spent 1.28ms making 3 calls to Moose::Meta::Method::Accessor::try {...} , avg 426µs/call # spent 236µs making 1 call to Moose::Meta::Method::Destructor::try {...}
79 @ret = $try->();
80 } elsif ( defined $wantarray ) {
81 $ret[0] = $try->();
82 } else {
83318320µs318130ms $try->();
# spent 66.5ms making 124 calls to Class::MOP::Class::try {...} , avg 536µs/call # spent 60.4ms making 191 calls to Class::MOP::Attribute::try {...} , avg 316µs/call # spent 3.00ms making 3 calls to Module::Implementation::try {...} , avg 1.00ms/call
84 };
85
86451173µs return 1; # properly set $fail to false
87 };
88
89 # preserve the current error and reset the original value of $@
9045267µs $error = $@;
9145250µs $@ = $prev_error;
92
93 # set up a scope guard to invoke the finally block at the end
94 my @guards =
95452267µs map { Try::Tiny::ScopeGuard->_new($_, $failed ? $error : ()) }
96 @finally;
97
98 # at this point $failed contains a true value if the eval died, even if some
99 # destructor overwrote $@ as the eval was unwinding.
10045282µs if ( $failed ) {
101 # if we got an error, invoke the catch block.
1021700ns if ( $catch ) {
103 # This works like given($error), but is backwards compatible and
104 # sets $_ in the dynamic scope for the body of C<$catch>
105 for ($error) {
10617µs13µs return $catch->($error);
# spent 3µs making 1 call to Module::Implementation::catch {...}
107 }
108
109 # in case when() was used without an explicit return, the C<for>
110 # loop will be aborted and there's no useful return value
111 }
112
113 return;
114 } else {
115 # no failure, $@ is back to what it was, everything is fine
1164511.40ms return $wantarray ? @ret : $ret[0];
117 }
118}
119
120
# spent 1.49ms within Try::Tiny::catch which was called 452 times, avg 3µs/call: # 191 times (620µs+0s) by Class::MOP::Attribute::_process_accessors at line 401 of Class/MOP/Attribute.pm, avg 3µs/call # 124 times (421µs+0s) by Class::MOP::Class::_post_add_attribute at line 896 of Class/MOP/Class.pm, avg 3µs/call # 55 times (173µs+0s) by Class::MOP::Method::Accessor::_generate_reader_method_inline at line 157 of Class/MOP/Method/Accessor.pm, avg 3µs/call # 31 times (107µs+0s) by Class::MOP::Method::Constructor::_generate_constructor_method_inline at line 115 of Class/MOP/Method/Constructor.pm, avg 3µs/call # 23 times (72µs+0s) by Class::MOP::Method::Accessor::_generate_accessor_method_inline at line 123 of Class/MOP/Method/Accessor.pm, avg 3µs/call # 16 times (49µs+0s) by Class::MOP::Method::Accessor::_generate_predicate_method_inline at line 212 of Class/MOP/Method/Accessor.pm, avg 3µs/call # 3 times (12µs+0s) by Module::Implementation::_load_implementation at line 93 of Module/Implementation.pm, avg 4µs/call # 3 times (10µs+0s) by Moose::Meta::Method::Accessor::_compile_code at line 47 of Moose/Meta/Method/Accessor.pm, avg 3µs/call # 3 times (9µs+0s) by Class::MOP::Method::Accessor::_generate_writer_method_inline at line 187 of Class/MOP/Method/Accessor.pm, avg 3µs/call # 2 times (8µs+0s) by Class::Load::try_load_class at line 183 of Class/Load.pm, avg 4µs/call # once (4µs+0s) by Moose::Meta::Method::Destructor::_initialize_body at line 106 of Moose/Meta/Method/Destructor.pm
sub catch (&;@) {
121452193µs my ( $block, @rest ) = @_;
122
12345260µs croak 'Useless bare catch()' unless wantarray;
124
125 return (
1264521.75ms bless(\$block, 'Try::Tiny::Catch'),
127 @rest,
128 );
129}
130
131sub finally (&;@) {
132 my ( $block, @rest ) = @_;
133
134 croak 'Useless bare finally()' unless wantarray;
135
136 return (
137 bless(\$block, 'Try::Tiny::Finally'),
138 @rest,
139 );
140}
141
142{
1431200ns package # hide from PAUSE
144 Try::Tiny::ScopeGuard;
145
1462275µs21.64ms
# spent 1.59ms (1.25+345µs) within Try::Tiny::ScopeGuard::BEGIN@146 which was called: # once (1.25ms+345µs) by Module::Implementation::BEGIN@13 at line 146
use constant UNSTABLE_DOLLARAT => ($] < '5.013002') ? 1 : 0;
# spent 1.59ms making 1 call to Try::Tiny::ScopeGuard::BEGIN@146 # spent 52µs making 1 call to constant::import
147
148 sub _new {
149 shift;
150 bless [ @_ ];
151 }
152
153 sub DESTROY {
154 my ($code, @args) = @{ $_[0] };
155
156 local $@ if UNSTABLE_DOLLARAT;
157 eval {
158 $code->(@args);
159 1;
160 } or do {
161 warn
162 "Execution of finally() block $code resulted in an exception, which "
163 . '*CAN NOT BE PROPAGATED* due to fundamental limitations of Perl. '
164 . 'Your program will continue as if this event never took place. '
165 . "Original exception text follows:\n\n"
166 . (defined $@ ? $@ : '$@ left undefined...')
167 . "\n"
168 ;
169 }
170 }
171}
172
173__PACKAGE__
174
17516µs__END__