Filename | /Users/edenc/perl5/lib/perl5/Devel/InnerPackage.pm |
Statements | Executed 549 statements in 2.67ms |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
50 | 3 | 3 | 1.84ms | 2.22ms | list_packages (recurses: max depth 1, inclusive time 652µs) | Devel::InnerPackage::
1000 | 5 | 1 | 208µs | 208µs | CORE:match (opcode) | Devel::InnerPackage::
28 | 1 | 1 | 122µs | 122µs | _loaded | Devel::InnerPackage::
28 | 1 | 1 | 47µs | 47µs | CORE:subst (opcode) | Devel::InnerPackage::
1 | 1 | 1 | 15µs | 19µs | BEGIN@3 | Devel::InnerPackage::
1 | 1 | 1 | 9µs | 79µs | BEGIN@4 | Devel::InnerPackage::
1 | 1 | 1 | 8µs | 18µs | BEGIN@86 | Devel::InnerPackage::
1 | 1 | 1 | 7µs | 19µs | BEGIN@66 | Devel::InnerPackage::
1 | 1 | 1 | 7µs | 48µs | BEGIN@5 | Devel::InnerPackage::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | package Devel::InnerPackage; | ||||
2 | |||||
3 | 2 | 26µs | 2 | 23µ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 # spent 19µs making 1 call to Devel::InnerPackage::BEGIN@3
# spent 4µs making 1 call to strict::import |
4 | 2 | 27µs | 2 | 150µ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 # spent 79µs making 1 call to Devel::InnerPackage::BEGIN@4
# spent 71µs making 1 call to base::import |
5 | 2 | 86µs | 2 | 89µ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 # spent 48µs making 1 call to Devel::InnerPackage::BEGIN@5
# spent 41µs making 1 call to vars::import |
6 | |||||
7 | 1 | 800ns | $VERSION = '0.4'; | ||
8 | 1 | 800ns | @EXPORT_OK = qw(list_packages); | ||
9 | |||||
10 | =pod | ||||
11 | |||||
12 | =head1 NAME | ||||
13 | |||||
14 | |||||
15 | Devel::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 | |||||
28 | Given 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 | |||||
46 | then | ||||
47 | |||||
48 | list_packages('Foo::Bar'); | ||||
49 | |||||
50 | will return | ||||
51 | |||||
52 | Foo::Bar::Quux | ||||
53 | Foo::Bar::Quirka | ||||
54 | |||||
55 | =head1 METHODS | ||||
56 | |||||
57 | =head2 list_packages <package name> | ||||
58 | |||||
59 | Return 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 | ||||
64 | 300 | 1.68ms | 50 | 25µs | my $pack = shift; $pack .= "::" unless $pack =~ m!::$!; # spent 25µs making 50 calls to Devel::InnerPackage::CORE:match, avg 502ns/call |
65 | |||||
66 | 2 | 193µs | 2 | 30µ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 # spent 19µs making 1 call to Devel::InnerPackage::BEGIN@66
# spent 11µs making 1 call to strict::unimport |
67 | my @packs; | ||||
68 | 447 | 86µs | my @stuff = grep !/^(main|)::$/, keys %{$pack}; # spent 86µs making 447 calls to Devel::InnerPackage::CORE:match, avg 193ns/call | ||
69 | 447 | 64µs | for my $cand (grep /::$/, @stuff) # spent 64µs making 447 calls to Devel::InnerPackage::CORE:match, avg 144ns/call | ||
70 | { | ||||
71 | 112 | 266µs | 28 | 47µs | $cand =~ s!::$!!; # spent 47µs making 28 calls to Devel::InnerPackage::CORE:subst, avg 2µs/call |
72 | 28 | 0s | 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 | |||||
74 | 56 | 129µ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 | } | ||||
78 | 28 | 75µs | 28 | 26µ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 | ||||
84 | 88 | 119µs | my ($class, $name) = @_; | ||
85 | |||||
86 | 2 | 171µs | 2 | 29µ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 # 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}::"} ) { | ||||
95 | 8 | 17µ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 | |||||
110 | Simon Wistow <simon@thegestalt.org> | ||||
111 | |||||
112 | =head1 COPYING | ||||
113 | |||||
114 | Copyright, 2005 Simon Wistow | ||||
115 | |||||
116 | Distributed under the same terms as Perl itself. | ||||
117 | |||||
118 | =head1 BUGS | ||||
119 | |||||
120 | None known. | ||||
121 | |||||
122 | =cut | ||||
123 | |||||
- - | |||||
128 | 1 | 5µs | 1; | ||
# 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 | |||||
# 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 |