← 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:12 2016

Filename/Users/timbo/perl5/perlbrew/perls/perl-5.18.2/lib/site_perl/5.18.2/PPI/Statement/Package.pm
StatementsExecuted 441 statements in 1.82ms
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
144114.16ms6.42msPPI::Statement::Package::::namespacePPI::Statement::Package::namespace
11112µs24µsPPI::Statement::Package::::BEGIN@67PPI::Statement::Package::BEGIN@67
1118µs8µsPPI::Statement::Package::::BEGIN@71PPI::Statement::Package::BEGIN@71
1116µs33µsPPI::Statement::Package::::BEGIN@70PPI::Statement::Package::BEGIN@70
1113µs3µsPPI::Statement::Package::::BEGIN@68PPI::Statement::Package::BEGIN@68
0000s0sPPI::Statement::Package::::file_scopedPPI::Statement::Package::file_scoped
Call graph for these subroutines as a Graphviz dot language file.
Line State
ments
Time
on line
Calls Time
in subs
Code
1package PPI::Statement::Package;
2
3=pod
4
5=head1 NAME
6
7PPI::Statement::Package - A package statement
8
9=head1 INHERITANCE
10
11 PPI::Statement::Package
12 isa PPI::Statement
13 isa PPI::Node
14 isa PPI::Element
15
16=head1 DESCRIPTION
17
18Most L<PPI::Statement> subclasses are assigned based on the value of the
19first token or word found in the statement. When PPI encounters a statement
20starting with 'package', it converts it to a C<PPI::Statement::Package>
21object.
22
23When working with package statements, please remember that packages only
24exist within their scope, and proper support for scoping has yet to be
25completed in PPI.
26
27However, if the immediate parent of the package statement is the
28top level L<PPI::Document> object, then it can be considered to define
29everything found until the next top-level "file scoped" package statement.
30
31A file may, however, contain nested temporary package, in which case you
32are mostly on your own :)
33
34
35=begin testing hash_constructors_dont_contain_packages_rt52259 2
36
37my $Document = PPI::Document->new(\<<'END_PERL');
38{ package => "", };
39+{ package => "", };
40{ 'package' => "", };
41+{ 'package' => "", };
42{ 'package' , "", };
43+{ 'package' , "", };
44END_PERL
45
46isa_ok( $Document, 'PPI::Document' );
47
48my $packages = $Document->find('PPI::Statement::Package');
49my $test_name = 'Found no package statements in hash constructors - RT #52259';
50if (not $packages) {
51 pass $test_name;
52} elsif ( not is(scalar @{$packages}, 0, $test_name) ) {
53 diag 'Package statements found:';
54 diag $_->parent()->parent()->content() foreach @{$packages};
55}
56
57=end testing
58
59
60=head1 METHODS
61
62C<PPI::Statement::Package> has a number of methods in addition to the standard
63L<PPI::Statement>, L<PPI::Node> and L<PPI::Element> methods.
64
65=cut
66
67219µs236µs
# spent 24µs (12+12) within PPI::Statement::Package::BEGIN@67 which was called: # once (12µs+12µs) by PPI::Statement::BEGIN@169 at line 67
use strict;
# spent 24µs making 1 call to PPI::Statement::Package::BEGIN@67 # spent 12µs making 1 call to strict::import
68222µs13µs
# spent 3µs within PPI::Statement::Package::BEGIN@68 which was called: # once (3µs+0s) by PPI::Statement::BEGIN@169 at line 68
use PPI::Statement ();
# spent 3µs making 1 call to PPI::Statement::Package::BEGIN@68
69
70227µs260µs
# spent 33µs (6+27) within PPI::Statement::Package::BEGIN@70 which was called: # once (6µs+27µs) by PPI::Statement::BEGIN@169 at line 70
use vars qw{$VERSION @ISA};
# spent 33µs making 1 call to PPI::Statement::Package::BEGIN@70 # spent 27µs making 1 call to vars::import
71
# spent 8µs within PPI::Statement::Package::BEGIN@71 which was called: # once (8µs+0s) by PPI::Statement::BEGIN@169 at line 74
BEGIN {
721400ns $VERSION = '1.215';
7318µs @ISA = 'PPI::Statement';
74198µs18µs}
# spent 8µs making 1 call to PPI::Statement::Package::BEGIN@71
75
76=pod
77
78=head2 namespace
79
80Most package declarations are simple, and just look something like
81
82 package Foo::Bar;
83
84The C<namespace> method returns the name of the declared package, in the
85above case 'Foo::Bar'. It returns this exactly as written and does not
86attempt to clean up or resolve things like ::Foo to main::Foo.
87
88If the package statement is done any different way, it returns false.
89
90=cut
91
92
# spent 6.42ms (4.16+2.25) within PPI::Statement::Package::namespace which was called 144 times, avg 45µs/call: # 144 times (4.16ms+2.25ms) by Perl::Critic::Policy::Modules::RequireFilenameMatchesPackage::violates at line 50 of Perl/Critic/Policy/Modules/RequireFilenameMatchesPackage.pm, avg 45µs/call
sub namespace {
9314459µs my $self = shift;
94144611µs2881.91ms my $namespace = $self->schild(1) or return '';
# spent 1.83ms making 144 calls to PPI::Node::schild, avg 13µs/call # spent 85µs making 144 calls to PPI::Util::TRUE, avg 588ns/call
95144971µs288342µs $namespace->isa('PPI::Token::Word')
# spent 228µs making 144 calls to PPI::Token::content, avg 2µs/call # spent 113µs making 144 calls to UNIVERSAL::isa, avg 786ns/call
96 ? $namespace->content
97 : '';
98}
99
100=pod
101
102=head2 file_scoped
103
104Regardless of whether it is named or not, the C<file_scoped> method will
105test to see if the package declaration is a top level "file scoped"
106statement or not, based on its location.
107
108In general, returns true if it is a "file scoped" package declaration with
109an immediate parent of the top level Document, or false if not.
110
111Note that if the PPI DOM tree B<does not> have a PPI::Document object at
112as the root element, this will return false. Likewise, it will also return
113false if the root element is a L<PPI::Document::Fragment>, as a fragment of
114a file does not represent a scope.
115
116=cut
117
118sub file_scoped {
119 my $self = shift;
120 my ($Parent, $Document) = ($self->parent, $self->top);
121 $Parent and $Document and $Parent == $Document
122 and $Document->isa('PPI::Document')
123 and ! $Document->isa('PPI::Document::Fragment');
124}
125
12612µs1;
127
128=pod
129
130=head1 SUPPORT
131
132See the L<support section|PPI/SUPPORT> in the main module.
133
134=head1 AUTHOR
135
136Adam Kennedy E<lt>adamk@cpan.orgE<gt>
137
138=head1 COPYRIGHT
139
140Copyright 2001 - 2011 Adam Kennedy.
141
142This program is free software; you can redistribute
143it and/or modify it under the same terms as Perl itself.
144
145The full text of the license can be found in the
146LICENSE file included with this module.
147
148=cut