← Index
NYTProf Performance Profile   « line view »
For /Users/timbo/perl5/perlbrew/perls/perl-5.18.2/bin/perlcritic
  Run on Sat Mar 19 22:12:22 2016
Reported on Sat Mar 19 22:14:11 2016

Filename/Users/timbo/perl5/perlbrew/perls/perl-5.18.2/lib/site_perl/5.18.2/Devel/InnerPackage.pm
StatementsExecuted 15 statements in 597µs
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
111178µs662µsDevel::InnerPackage::::BEGIN@7Devel::InnerPackage::BEGIN@7
11111µs22µsDevel::InnerPackage::::BEGIN@3Devel::InnerPackage::BEGIN@3
1118µs18µsDevel::InnerPackage::::BEGIN@67Devel::InnerPackage::BEGIN@67
1117µs17µsDevel::InnerPackage::::BEGIN@87Devel::InnerPackage::BEGIN@87
1117µs58µsDevel::InnerPackage::::BEGIN@4Devel::InnerPackage::BEGIN@4
1116µs34µsDevel::InnerPackage::::BEGIN@5Devel::InnerPackage::BEGIN@5
0000s0sDevel::InnerPackage::::_loadedDevel::InnerPackage::_loaded
0000s0sDevel::InnerPackage::::list_packagesDevel::InnerPackage::list_packages
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
3220µs233µs
# spent 22µs (11+11) within Devel::InnerPackage::BEGIN@3 which was called: # once (11µs+11µs) by Module::Pluggable::Object::BEGIN@8 at line 3
use strict;
# spent 22µs making 1 call to Devel::InnerPackage::BEGIN@3 # spent 11µs making 1 call to strict::import
4222µs2110µs
# spent 58µs (7+51) within Devel::InnerPackage::BEGIN@4 which was called: # once (7µs+51µs) by Module::Pluggable::Object::BEGIN@8 at line 4
use base qw(Exporter);
# spent 58µs making 1 call to Devel::InnerPackage::BEGIN@4 # spent 51µs making 1 call to base::import
5224µs261µs
# spent 34µs (6+27) within Devel::InnerPackage::BEGIN@5 which was called: # once (6µs+27µs) by Module::Pluggable::Object::BEGIN@8 at line 5
use vars qw($VERSION @EXPORT_OK);
# spent 34µs making 1 call to Devel::InnerPackage::BEGIN@5 # spent 28µs making 1 call to vars::import
6
72233µs2664µs
# spent 662µs (178+484) within Devel::InnerPackage::BEGIN@7 which was called: # once (178µs+484µs) by Module::Pluggable::Object::BEGIN@8 at line 7
use if $] > 5.017, 'deprecate';
# spent 662µs making 1 call to Devel::InnerPackage::BEGIN@7 # spent 3µs making 1 call to if::import
8
91700ns$VERSION = '0.4';
101700ns@EXPORT_OK = qw(list_packages);
11
12=pod
13
14=head1 NAME
15
16Devel::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
29Given 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
47then
48
49 list_packages('Foo::Bar');
50
51will return
52
53 Foo::Bar::Quux
54 Foo::Bar::Quirka
55
56=head1 METHODS
57
58=head2 list_packages <package name>
59
60Return a list of all inner packages of that package.
61
62=cut
63
64sub list_packages {
65 my $pack = shift; $pack .= "::" unless $pack =~ m!::$!;
66
672163µs228µs
# spent 18µs (8+10) within Devel::InnerPackage::BEGIN@67 which was called: # once (8µs+10µs) by Module::Pluggable::Object::BEGIN@8 at line 67
no strict 'refs';
# spent 18µs making 1 call to Devel::InnerPackage::BEGIN@67 # spent 10µs making 1 call to strict::unimport
68 my @packs;
69 my @stuff = grep !/^(main|)::$/, keys %{$pack};
70 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 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.
84sub _loaded {
85 my ($class, $name) = @_;
86
872130µs227µs
# spent 17µs (7+10) within Devel::InnerPackage::BEGIN@87 which was called: # once (7µs+10µs) by Module::Pluggable::Object::BEGIN@8 at line 87
no strict 'refs';
# spent 17µs making 1 call to Devel::InnerPackage::BEGIN@87 # spent 10µ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
111Simon Wistow <simon@thegestalt.org>
112
113=head1 COPYING
114
115Copyright, 2005 Simon Wistow
116
117Distributed under the same terms as Perl itself.
118
119=head1 BUGS
120
121None known.
122
123=cut
124
- -
12912µs1;