← Index
NYTProf Performance Profile   « block view • line view • sub view »
For -e
  Run on Wed Nov 17 21:39:01 2010
Reported on Wed Nov 17 22:04:46 2010

Filename/home/doy/perl5/perlbrew/perls/perl-5.10.1/lib/site_perl/5.10.1/Try/Tiny.pm
StatementsExecuted 13982 statements in 77.5ms
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
6385560.4ms4.96sTry::Tiny::::try Try::Tiny::try (recurses: max depth 4, inclusive time 1.93s)
6323313.3ms13.3msTry::Tiny::::catch Try::Tiny::catch
11177µs93µsTry::Tiny::::BEGIN@3 Try::Tiny::BEGIN@3
11147µs282µsTry::Tiny::::BEGIN@46 Try::Tiny::BEGIN@46
11142µs42µsTry::Tiny::::BEGIN@8 Try::Tiny::BEGIN@8
11134µs329µsTry::Tiny::::BEGIN@6 Try::Tiny::BEGIN@6
0000s0sTry::Tiny::ScopeGuard::::DESTROYTry::Tiny::ScopeGuard::DESTROY
0000s0sTry::Tiny::ScopeGuard::::_newTry::Tiny::ScopeGuard::_new
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
33114µs2110µs
# spent 93µs (77+17) within Try::Tiny::BEGIN@3 which was called: # once (77µs+17µs) by Class::MOP::BEGIN@14 at line 3
use strict;
# spent 93µs making 1 call to Try::Tiny::BEGIN@3 # spent 17µs making 1 call to strict::import
4#use warnings;
5
63157µs2625µs
# spent 329µs (34+296) within Try::Tiny::BEGIN@6 which was called: # once (34µs+296µs) by Class::MOP::BEGIN@14 at line 6
use vars qw(@EXPORT @EXPORT_OK $VERSION @ISA);
# spent 329µs making 1 call to Try::Tiny::BEGIN@6 # spent 296µs making 1 call to vars::import
7
8
# spent 42µs within Try::Tiny::BEGIN@8 which was called: # once (42µs+0s) by Class::MOP::BEGIN@14 at line 11
BEGIN {
9243µs require Exporter;
10 @ISA = qw(Exporter);
111393µs142µs}
# spent 42µs making 1 call to Try::Tiny::BEGIN@8
12
1314µs$VERSION = "0.07";
14
15164µs$VERSION = eval $VERSION;
# spent 12µs executing statements in string eval
16
17110µs@EXPORT = @EXPORT_OK = qw(try catch finally);
18
1915µs$Carp::Internal{+__PACKAGE__}++;
20
21# Need to prototype as @ not $$ because of the way Perl evaluates the prototype.
22# Keeping it at $$ means you only ever get 1 sub because we need to eval in a list
23# context & not a scalar one
24
25
# spent 4.96s (60.4ms+4.90) within Try::Tiny::try which was called 638 times, avg 7.77ms/call: # 359 times (33.9ms+71.0ms) by Class::MOP::Attribute::_process_accessors at line 345 of Class/MOP/Attribute.pm, avg 292µs/call # 238 times (22.5ms+1.37s) by Class::MOP::Class::_post_add_attribute at line 794 of Class/MOP/Class.pm, avg 5.86ms/call # 35 times (3.56ms+3.45s) by Class::MOP::load_first_existing_class at line 125 of Class/MOP.pm, avg 98.8ms/call # 5 times (370µs+3.52ms) by Moose::Meta::Attribute::does at line 40 of Moose/Meta/Attribute.pm, avg 779µs/call # once (89µs+-89µs) by Class::MOP::__ANON__[/home/doy/perl5/perlbrew/perls/perl-5.10.1/lib/site_perl/5.10.1/x86_64-linux/Class/MOP.pm:118] at line 13 of KiokuDB/Role/UUIDs.pm
sub try (&;@) {
261270159.9ms my ( $try, @code_refs ) = @_;
27
28 # we need to save this here, the eval block will be in scalar context due
29 # to $failed
30 my $wantarray = wantarray;
31
32 my ( $catch, @finally );
33
34 # find labeled blocks in the argument list.
35 # catch and finally tag the blocks by blessing a scalar reference to them.
36 foreach my $code_ref (@code_refs) {
37 next unless $code_ref;
38
39 my $ref = ref($code_ref);
40
41 if ( $ref eq 'Try::Tiny::Catch' ) {
42 $catch = ${$code_ref};
43 } elsif ( $ref eq 'Try::Tiny::Finally' ) {
44 push @finally, ${$code_ref};
45 } else {
4631.32ms2517µs
# spent 282µs (47+235) within Try::Tiny::BEGIN@46 which was called: # once (47µs+235µs) by Class::MOP::BEGIN@14 at line 46
use Carp;
# spent 282µs making 1 call to Try::Tiny::BEGIN@46 # spent 235µs making 1 call to Exporter::import
47 confess("Unknown code ref type given '${ref}'. Check your usage & try again");
48 }
49 }
50
51 # save the value of $@ so we can set $@ back to it in the beginning of the eval
52 my $prev_error = $@;
53
54 my ( @ret, $error, $failed );
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 {
61 # localize $@ to prevent clobbering of previous value by a successful
62 # eval.
63 local $@;
64
65 # failed will be true if the eval dies, because 1 will not be returned
66 # from the eval body
67 $failed = not eval {
68 $@ = $prev_error;
69
70 # evaluate the try block in the correct context
71414.79s if ( $wantarray ) {
# spent 4.77s making 35 calls to Class::MOP::__ANON__[Class/MOP.pm:118], avg 136ms/call # spent 8.88ms making 1 call to KiokuDB::Role::UUIDs::__ANON__[KiokuDB/Role/UUIDs.pm:13] # spent 3.52ms making 5 calls to Moose::Meta::Attribute::__ANON__[Moose/Meta/Attribute.pm:40], avg 705µs/call
72 @ret = $try->();
73 } elsif ( defined $wantarray ) {
74 $ret[0] = $try->();
75 } else {
765972.04s $try->();
# spent 1.42s making 238 calls to Class::MOP::Class::__ANON__[Class/MOP/Class.pm:790], avg 5.96ms/call # spent 627ms making 359 calls to Class::MOP::Attribute::__ANON__[Class/MOP/Attribute.pm:342], avg 1.75ms/call
77 };
78
79 return 1; # properly set $fail to false
80 };
81
82 # copy $@ to $error; when we leave this scope, local $@ will revert $@
83 # back to its previous value
84 $error = $@;
85 }
86
87 # set up a scope guard to invoke the finally block at the end
88 my @guards =
89 map { Try::Tiny::ScopeGuard->_new($_, $failed ? $error : ()) }
90 @finally;
91
92 # at this point $failed contains a true value if the eval died, even if some
93 # destructor overwrote $@ as the eval was unwinding.
94 if ( $failed ) {
95 # if we got an error, invoke the catch block.
96 if ( $catch ) {
97 # This works like given($error), but is backwards compatible and
98 # sets $_ in the dynamic scope for the body of C<$catch>
99 for ($error) {
1003265µs return $catch->($error);
# spent 265µs making 3 calls to Class::MOP::__ANON__[Class/MOP.pm:125], avg 88µs/call
101 }
102
103 # in case when() was used without an explicit return, the C<for>
104 # loop will be aborted and there's no useful return value
105 }
106
107 return;
108 } else {
109 # no failure, $@ is back to what it was, everything is fine
110 return $wantarray ? @ret : $ret[0];
111 }
112}
113
114
# spent 13.3ms within Try::Tiny::catch which was called 632 times, avg 21µs/call: # 359 times (7.40ms+0s) by Class::MOP::Attribute::_process_accessors at line 345 of Class/MOP/Attribute.pm, avg 21µs/call # 238 times (5.10ms+0s) by Class::MOP::Class::_post_add_attribute at line 794 of Class/MOP/Class.pm, avg 21µs/call # 35 times (785µs+0s) by Class::MOP::load_first_existing_class at line 125 of Class/MOP.pm, avg 22µs/call
sub catch (&;@) {
115126415.6ms my ( $block, @rest ) = @_;
116
117 return (
118 bless(\$block, 'Try::Tiny::Catch'),
119 @rest,
120 );
121}
122
123sub finally (&;@) {
124 my ( $block, @rest ) = @_;
125
126 return (
127 bless(\$block, 'Try::Tiny::Finally'),
128 @rest,
129 );
130}
131
132{
13315µs package Try::Tiny::ScopeGuard;
134
135 sub _new {
136 shift;
137 bless [ @_ ];
138 }
139
140 sub DESTROY {
141 my @guts = @{ shift() };
142 my $code = shift @guts;
143 $code->(@guts);
144 }
145}
146
147__PACKAGE__
148
149116µs__END__