← Index
NYTProf Performance Profile   « block view • line view • sub view »
For script/nytprof.pl
  Run on Thu May 31 16:29:39 2012
Reported on Thu May 31 16:36:01 2012

Filename/Users/edenc/perl5/lib/perl5/Devel/InnerPackage.pm
StatementsExecuted 549 statements in 2.67ms
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
50331.84ms2.22msDevel::InnerPackage::::list_packagesDevel::InnerPackage::list_packages (recurses: max depth 1, inclusive time 652µs)
100051208µs208µsDevel::InnerPackage::::CORE:matchDevel::InnerPackage::CORE:match (opcode)
2811122µs122µsDevel::InnerPackage::::_loadedDevel::InnerPackage::_loaded
281147µs47µsDevel::InnerPackage::::CORE:substDevel::InnerPackage::CORE:subst (opcode)
11115µs19µsDevel::InnerPackage::::BEGIN@3Devel::InnerPackage::BEGIN@3
1119µs79µsDevel::InnerPackage::::BEGIN@4Devel::InnerPackage::BEGIN@4
1118µs18µsDevel::InnerPackage::::BEGIN@86Devel::InnerPackage::BEGIN@86
1117µs19µsDevel::InnerPackage::::BEGIN@66Devel::InnerPackage::BEGIN@66
1117µs48µsDevel::InnerPackage::::BEGIN@5Devel::InnerPackage::BEGIN@5
Call graph for these subroutines as a Graphviz dot language file.
Line State
ments
Time
on line
Calls Time
in subs
Code
1package Devel::InnerPackage;
2
3226µs223µs
# spent 19µs (15+4) within Devel::InnerPackage::BEGIN@3 which was called: # once (15µs+4µs) by Catalyst::Component::BEGIN@8 at line 3
use strict;
# spent 19µs making 1 call to Devel::InnerPackage::BEGIN@3 # spent 4µs making 1 call to strict::import
4227µs2150µs
# spent 79µs (9+71) within Devel::InnerPackage::BEGIN@4 which was called: # once (9µs+71µs) by Catalyst::Component::BEGIN@8 at line 4
use base qw(Exporter);
# spent 79µs making 1 call to Devel::InnerPackage::BEGIN@4 # spent 71µs making 1 call to base::import
5286µs289µs
# spent 48µs (7+41) within Devel::InnerPackage::BEGIN@5 which was called: # once (7µs+41µs) by Catalyst::Component::BEGIN@8 at line 5
use vars qw($VERSION @EXPORT_OK);
# spent 48µs making 1 call to Devel::InnerPackage::BEGIN@5 # spent 41µs making 1 call to vars::import
6
71800ns$VERSION = '0.4';
81800ns@EXPORT_OK = qw(list_packages);
9
10=pod
11
12=head1 NAME
13
14
15Devel::InnerPackage - find all the inner packages of a package
16
17=head1 SYNOPSIS
18
19 use Foo::Bar;
20 use Devel::InnerPackage qw(list_packages);
21
22 my @inner_packages = list_packages('Foo::Bar');
23
24
25=head1 DESCRIPTION
26
27
28Given a file like this
29
30
31 package Foo::Bar;
32
33 sub foo {}
34
35
36 package Foo::Bar::Quux;
37
38 sub quux {}
39
40 package Foo::Bar::Quirka;
41
42 sub quirka {}
43
44 1;
45
46then
47
48 list_packages('Foo::Bar');
49
50will return
51
52 Foo::Bar::Quux
53 Foo::Bar::Quirka
54
55=head1 METHODS
56
57=head2 list_packages <package name>
58
59Return a list of all inner packages of that package.
60
61=cut
62
63
# spent 2.22ms (1.84+377µs) within Devel::InnerPackage::list_packages which was called 50 times, avg 44µs/call: # 28 times (592µs+-592µs) by Devel::InnerPackage::list_packages at line 72, avg 0s/call # 13 times (645µs+889µs) by Module::Pluggable::Object::handle_innerpackages at line 296 of Module/Pluggable/Object.pm, avg 118µs/call # 9 times (603µs+80µs) by Catalyst::Component::expand_modules at line 164 of Catalyst/Component.pm, avg 76µs/call
sub list_packages {
643001.68ms5025µs my $pack = shift; $pack .= "::" unless $pack =~ m!::$!;
# spent 25µs making 50 calls to Devel::InnerPackage::CORE:match, avg 502ns/call
65
662193µs230µs
# spent 19µs (7+11) within Devel::InnerPackage::BEGIN@66 which was called: # once (7µs+11µs) by Catalyst::Component::BEGIN@8 at line 66
no strict 'refs';
# spent 19µs making 1 call to Devel::InnerPackage::BEGIN@66 # spent 11µs making 1 call to strict::unimport
67 my @packs;
6844786µs my @stuff = grep !/^(main|)::$/, keys %{$pack};
# spent 86µs making 447 calls to Devel::InnerPackage::CORE:match, avg 193ns/call
6944764µs for my $cand (grep /::$/, @stuff)
# spent 64µs making 447 calls to Devel::InnerPackage::CORE:match, avg 144ns/call
70 {
71112266µs2847µs $cand =~ s!::$!!;
# spent 47µs making 28 calls to Devel::InnerPackage::CORE:subst, avg 2µs/call
72280s my @children = list_packages($pack.$cand);
# spent 652µs making 28 calls to Devel::InnerPackage::list_packages, avg 23µs/call, recursion: max depth 1, sum of overlapping time 652µs
73
7456129µs push @packs, "$pack$cand" unless $cand =~ /^::/ ||
# spent 122µs making 28 calls to Devel::InnerPackage::_loaded, avg 4µs/call # spent 7µs making 28 calls to Devel::InnerPackage::CORE:match, avg 239ns/call
75 !__PACKAGE__->_loaded($pack.$cand); # or @children;
76 push @packs, @children;
77 }
782875µs2826µs return grep {$_ !~ /::(::ISA::CACHE|SUPER)/} @packs;
# spent 26µs making 28 calls to Devel::InnerPackage::CORE:match, avg 911ns/call
79}
80
81### XXX this is an inlining of the Class-Inspector->loaded()
82### method, but inlined to remove the dependency.
83
# spent 122µs within Devel::InnerPackage::_loaded which was called 28 times, avg 4µs/call: # 28 times (122µs+0s) by Devel::InnerPackage::list_packages at line 74, avg 4µs/call
sub _loaded {
8488119µs my ($class, $name) = @_;
85
862171µs229µs
# spent 18µs (8+11) within Devel::InnerPackage::BEGIN@86 which was called: # once (8µs+11µs) by Catalyst::Component::BEGIN@8 at line 86
no strict 'refs';
# spent 18µs making 1 call to Devel::InnerPackage::BEGIN@86 # spent 10µs making 1 call to strict::unimport
87
88 # Handle by far the two most common cases
89 # This is very fast and handles 99% of cases.
90 return 1 if defined ${"${name}::VERSION"};
91 return 1 if @{"${name}::ISA"};
92
93 # Are there any symbol table entries other than other namespaces
94 foreach ( keys %{"${name}::"} ) {
95817µs next if substr($_, -2, 2) eq '::';
96 return 1 if defined &{"${name}::$_"};
97 }
98
99 # No functions, and it doesn't have a version, and isn't anything.
100 # As an absolute last resort, check for an entry in %INC
101 my $filename = join( '/', split /(?:'|::)/, $name ) . '.pm';
102 return 1 if defined $INC{$filename};
103
104 '';
105}
106
107
108=head1 AUTHOR
109
110Simon Wistow <simon@thegestalt.org>
111
112=head1 COPYING
113
114Copyright, 2005 Simon Wistow
115
116Distributed under the same terms as Perl itself.
117
118=head1 BUGS
119
120None known.
121
122=cut
123
- -
12815µs1;
 
# spent 208µs within Devel::InnerPackage::CORE:match which was called 1000 times, avg 208ns/call: # 447 times (86µs+0s) by Devel::InnerPackage::list_packages at line 68, avg 193ns/call # 447 times (64µs+0s) by Devel::InnerPackage::list_packages at line 69, avg 144ns/call # 50 times (25µs+0s) by Devel::InnerPackage::list_packages at line 64, avg 502ns/call # 28 times (26µs+0s) by Devel::InnerPackage::list_packages at line 78, avg 911ns/call # 28 times (7µs+0s) by Devel::InnerPackage::list_packages at line 74, avg 239ns/call
sub Devel::InnerPackage::CORE:match; # opcode
# spent 47µs within Devel::InnerPackage::CORE:subst which was called 28 times, avg 2µs/call: # 28 times (47µs+0s) by Devel::InnerPackage::list_packages at line 71, avg 2µs/call
sub Devel::InnerPackage::CORE:subst; # opcode