← 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:17 2010

File /usr/local/lib/perl5/site_perl/5.10.1/darwin-2level/Sub/Identify.pm
Statements Executed 112
Statement Execution Time 2.27ms
Subroutines — ordered by exclusive time
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
90111.56ms1.64msSub::Identify::::sub_fullnameSub::Identify::sub_fullname
901282µs82µsSub::Identify::::get_code_infoSub::Identify::get_code_info (xsub)
11123µs194µsSub::Identify::::BEGIN@6Sub::Identify::BEGIN@6
11114µs18µsSub::Identify::::BEGIN@3Sub::Identify::BEGIN@3
1118µs26µsSub::Identify::::BEGIN@4Sub::Identify::BEGIN@4
0000s0sSub::Identify::::__ANON__[:44]Sub::Identify::__ANON__[:44]
0000s0sSub::Identify::::stash_nameSub::Identify::stash_name
0000s0sSub::Identify::::sub_nameSub::Identify::sub_name
Call graph for these subroutines as a Graphviz dot language file.
Line State
ments
Time
on line
Calls Time
in subs
Code
1package Sub::Identify;
2
3322µs221µs
# spent 18µs (14+3) within Sub::Identify::BEGIN@3 which was called # once (14µs+3µs) by namespace::clean::BEGIN@15 at line 3
use strict;
# spent 18µs making 1 call to Sub::Identify::BEGIN@3 # spent 3µs making 1 call to strict::import
43243µs244µs
# spent 26µs (8+18) within Sub::Identify::BEGIN@4 which was called # once (8µs+18µs) by namespace::clean::BEGIN@15 at line 4
use Exporter;
# spent 26µs making 1 call to Sub::Identify::BEGIN@4 # spent 18µs making 1 call to Exporter::import
5
6
# spent 194µs (23+170) within Sub::Identify::BEGIN@6 which was called # once (23µs+170µs) by namespace::clean::BEGIN@15 at line 46
BEGIN {
71500ns our $VERSION = '0.04';
816µs our @ISA = ('Exporter');
912µs our %EXPORT_TAGS = (all => [ our @EXPORT_OK = qw(sub_name stash_name sub_fullname get_code_info) ]);
10
111300ns my $loaded = 0;
1211µs unless ($ENV{PERL_SUB_IDENTIFY_PP}) {
131100ns local $@;
141400ns eval {
151900ns if ($] >= 5.006) {
161400ns require XSLoader;
171176µs1170µs XSLoader::load(__PACKAGE__, $VERSION);
# spent 170µs making 1 call to XSLoader::load
18 }
19 else {
20 require DynaLoader;
21 push @ISA, 'DynaLoader';
22 __PACKAGE__->bootstrap($VERSION);
23 }
24 };
25
261200ns die $@ if $@ && $@ !~ /object version|loadable object/;
27
281500ns $loaded = 1 unless $@;
29 }
30
311400ns our $IsPurePerl = !$loaded;
32
3313µs if ($IsPurePerl) {
34 require B;
35 *get_code_info = sub ($) {
36 my ($coderef) = @_;
37 ref $coderef or return;
38 my $cv = B::svref_2object($coderef);
39 $cv->isa('B::CV') or return;
40 # bail out if GV is undefined
41 $cv->GV->isa('B::SPECIAL') and return;
42
43 return ($cv->GV->STASH->NAME, $cv->GV->NAME);
44 };
45 }
461108µs1194µs}
# spent 194µs making 1 call to Sub::Identify::BEGIN@6
47
48sub stash_name ($) { (get_code_info($_[0]))[0] }
49sub sub_name ($) { (get_code_info($_[0]))[1] }
50901.70ms9082µs
# spent 1.64ms (1.56+82µs) within Sub::Identify::sub_fullname which was called 90 times, avg 18µs/call: # 90 times (1.56ms+82µs) by namespace::clean::__ANON__[/usr/local/lib/perl5/site_perl/5.10.1/namespace/clean.pm:211] at line 181 of namespace/clean.pm, avg 18µs/call
sub sub_fullname ($) { join '::', get_code_info($_[0]) }
# spent 82µs making 90 calls to Sub::Identify::get_code_info, avg 909ns/call
51
5212µs1;
53
54__END__
55
56=head1 NAME
57
58Sub::Identify - Retrieve names of code references
59
60=head1 SYNOPSIS
61
62 use Sub::Identify ':all';
63 my $subname = sub_name( $some_coderef );
64 my $p = stash_name( $some_coderef );
65 my $fully_qualified_name = sub_fullname( $some_coderef );
66 defined $subname
67 and print "this coderef points to sub $subname in package $p\n";
68
69=head1 DESCRIPTION
70
71C<Sub::Identify> allows you to retrieve the real name of code references. For
72this, it uses perl's introspection mechanism, provided by the C<B> module.
73
74It provides four functions : C<sub_name> returns the name of the
75subroutine (or C<__ANON__> if it's an anonymous code reference),
76C<stash_name> returns its package, and C<sub_fullname> returns the
77concatenation of the two.
78
79The fourth function, C<get_code_info>, returns a list of two elements,
80the package and the subroutine name (in case of you want both and are worried
81by the speed.)
82
83In case of subroutine aliasing, those functions always return the
84original name.
85
86=head1 LICENSE
87
88(c) Rafael Garcia-Suarez (rgarciasuarez at gmail dot com) 2005, 2008
89
90This program is free software; you may redistribute it and/or modify it under
91the same terms as Perl itself.
92
93=cut
# spent 82µs within Sub::Identify::get_code_info which was called 90 times, avg 909ns/call: # 90 times (82µs+0s) by Sub::Identify::sub_fullname at line 50 of Sub/Identify.pm, avg 909ns/call
sub Sub::Identify::get_code_info; # xsub