Filename | /usr/share/perl5/Devel/InnerPackage.pm |
Statements | Executed 39 statements in 736µs |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
1 | 1 | 1 | 743µs | 838µs | BEGIN@4 | Devel::InnerPackage::
1 | 1 | 1 | 172µs | 1.23ms | BEGIN@7 | Devel::InnerPackage::
4 | 1 | 1 | 31µs | 32µs | list_packages | Devel::InnerPackage::
1 | 1 | 1 | 17µs | 32µs | BEGIN@3 | Devel::InnerPackage::
1 | 1 | 1 | 7µs | 15µs | BEGIN@87 | Devel::InnerPackage::
1 | 1 | 1 | 6µs | 30µs | BEGIN@5 | Devel::InnerPackage::
1 | 1 | 1 | 6µs | 15µs | BEGIN@67 | Devel::InnerPackage::
4 | 1 | 1 | 2µs | 2µs | CORE:match (opcode) | Devel::InnerPackage::
0 | 0 | 0 | 0s | 0s | _loaded | Devel::InnerPackage::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | package Devel::InnerPackage; | ||||
2 | |||||
3 | 2 | 39µs | 2 | 46µs | # spent 32µs (17+15) within Devel::InnerPackage::BEGIN@3 which was called:
# once (17µs+15µs) by Module::Pluggable::Object::BEGIN@8 at line 3 # spent 32µs making 1 call to Devel::InnerPackage::BEGIN@3
# spent 15µs making 1 call to strict::import |
4 | 2 | 115µs | 2 | 894µs | # spent 838µs (743+96) within Devel::InnerPackage::BEGIN@4 which was called:
# once (743µs+96µs) by Module::Pluggable::Object::BEGIN@8 at line 4 # spent 838µs making 1 call to Devel::InnerPackage::BEGIN@4
# spent 55µs making 1 call to base::import |
5 | 2 | 24µs | 2 | 54µs | # spent 30µs (6+24) within Devel::InnerPackage::BEGIN@5 which was called:
# once (6µs+24µs) by Module::Pluggable::Object::BEGIN@8 at line 5 # spent 30µs making 1 call to Devel::InnerPackage::BEGIN@5
# spent 24µs making 1 call to vars::import |
6 | |||||
7 | 2 | 238µs | 2 | 1.23ms | # spent 1.23ms (172µs+1.05) within Devel::InnerPackage::BEGIN@7 which was called:
# once (172µs+1.05ms) by Module::Pluggable::Object::BEGIN@8 at line 7 # spent 1.23ms making 1 call to Devel::InnerPackage::BEGIN@7
# spent 4µs making 1 call to if::import |
8 | |||||
9 | 1 | 400ns | $VERSION = '0.4'; | ||
10 | 1 | 700ns | @EXPORT_OK = qw(list_packages); | ||
11 | |||||
12 | =pod | ||||
13 | |||||
14 | =head1 NAME | ||||
15 | |||||
16 | Devel::InnerPackage - find all the inner packages of a package | ||||
17 | |||||
18 | =head1 SYNOPSIS | ||||
19 | |||||
20 | use Foo::Bar; | ||||
21 | use Devel::InnerPackage qw(list_packages); | ||||
22 | |||||
23 | my @inner_packages = list_packages('Foo::Bar'); | ||||
24 | |||||
25 | |||||
26 | =head1 DESCRIPTION | ||||
27 | |||||
28 | |||||
29 | Given a file like this | ||||
30 | |||||
31 | |||||
32 | package Foo::Bar; | ||||
33 | |||||
34 | sub foo {} | ||||
35 | |||||
36 | |||||
37 | package Foo::Bar::Quux; | ||||
38 | |||||
39 | sub quux {} | ||||
40 | |||||
41 | package Foo::Bar::Quirka; | ||||
42 | |||||
43 | sub quirka {} | ||||
44 | |||||
45 | 1; | ||||
46 | |||||
47 | then | ||||
48 | |||||
49 | list_packages('Foo::Bar'); | ||||
50 | |||||
51 | will return | ||||
52 | |||||
53 | Foo::Bar::Quux | ||||
54 | Foo::Bar::Quirka | ||||
55 | |||||
56 | =head1 METHODS | ||||
57 | |||||
58 | =head2 list_packages <package name> | ||||
59 | |||||
60 | Return a list of all inner packages of that package. | ||||
61 | |||||
62 | =cut | ||||
63 | |||||
64 | # spent 32µs (31+2) within Devel::InnerPackage::list_packages which was called 4 times, avg 8µs/call:
# 4 times (31µs+2µs) by Module::Pluggable::Object::handle_innerpackages at line 351 of Module/Pluggable/Object.pm, avg 8µs/call | ||||
65 | 8 | 13µs | 4 | 2µs | my $pack = shift; $pack .= "::" unless $pack =~ m!::$!; # spent 2µs making 4 calls to Devel::InnerPackage::CORE:match, avg 450ns/call |
66 | |||||
67 | 2 | 158µs | 2 | 25µs | # spent 15µs (6+9) within Devel::InnerPackage::BEGIN@67 which was called:
# once (6µs+9µs) by Module::Pluggable::Object::BEGIN@8 at line 67 # spent 15µs making 1 call to Devel::InnerPackage::BEGIN@67
# spent 9µs making 1 call to strict::unimport |
68 | 4 | 500ns | my @packs; | ||
69 | 4 | 8µs | my @stuff = grep !/^(main|)::$/, keys %{$pack}; | ||
70 | 4 | 5µs | for my $cand (grep /::$/, @stuff) | ||
71 | { | ||||
72 | $cand =~ s!::$!!; | ||||
73 | my @children = list_packages($pack.$cand); | ||||
74 | |||||
75 | push @packs, "$pack$cand" unless $cand =~ /^::/ || | ||||
76 | !__PACKAGE__->_loaded($pack.$cand); # or @children; | ||||
77 | push @packs, @children; | ||||
78 | } | ||||
79 | 4 | 10µs | return grep {$_ !~ /::(::ISA::CACHE|SUPER)/} @packs; | ||
80 | } | ||||
81 | |||||
82 | ### XXX this is an inlining of the Class-Inspector->loaded() | ||||
83 | ### method, but inlined to remove the dependency. | ||||
84 | sub _loaded { | ||||
85 | my ($class, $name) = @_; | ||||
86 | |||||
87 | 2 | 123µs | 2 | 24µs | # spent 15µs (7+8) within Devel::InnerPackage::BEGIN@87 which was called:
# once (7µs+8µs) by Module::Pluggable::Object::BEGIN@8 at line 87 # spent 15µs making 1 call to Devel::InnerPackage::BEGIN@87
# spent 8µs making 1 call to strict::unimport |
88 | |||||
89 | # Handle by far the two most common cases | ||||
90 | # This is very fast and handles 99% of cases. | ||||
91 | return 1 if defined ${"${name}::VERSION"}; | ||||
92 | return 1 if @{"${name}::ISA"}; | ||||
93 | |||||
94 | # Are there any symbol table entries other than other namespaces | ||||
95 | foreach ( keys %{"${name}::"} ) { | ||||
96 | next if substr($_, -2, 2) eq '::'; | ||||
97 | return 1 if defined &{"${name}::$_"}; | ||||
98 | } | ||||
99 | |||||
100 | # No functions, and it doesn't have a version, and isn't anything. | ||||
101 | # As an absolute last resort, check for an entry in %INC | ||||
102 | my $filename = join( '/', split /(?:'|::)/, $name ) . '.pm'; | ||||
103 | return 1 if defined $INC{$filename}; | ||||
104 | |||||
105 | ''; | ||||
106 | } | ||||
107 | |||||
108 | |||||
109 | =head1 AUTHOR | ||||
110 | |||||
111 | Simon Wistow <simon@thegestalt.org> | ||||
112 | |||||
113 | =head1 COPYING | ||||
114 | |||||
115 | Copyright, 2005 Simon Wistow | ||||
116 | |||||
117 | Distributed under the same terms as Perl itself. | ||||
118 | |||||
119 | =head1 BUGS | ||||
120 | |||||
121 | None known. | ||||
122 | |||||
123 | =cut | ||||
124 | |||||
- - | |||||
129 | 1 | 2µs | 1; | ||
# spent 2µs within Devel::InnerPackage::CORE:match which was called 4 times, avg 450ns/call:
# 4 times (2µs+0s) by Devel::InnerPackage::list_packages at line 65, avg 450ns/call |