| Filename | /Users/timbo/perl5/perlbrew/perls/perl-5.18.2/lib/site_perl/5.18.2/PPI/Statement/Package.pm |
| Statements | Executed 441 statements in 1.82ms |
| Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
|---|---|---|---|---|---|
| 144 | 1 | 1 | 4.16ms | 6.42ms | PPI::Statement::Package::namespace |
| 1 | 1 | 1 | 12µs | 24µs | PPI::Statement::Package::BEGIN@67 |
| 1 | 1 | 1 | 8µs | 8µs | PPI::Statement::Package::BEGIN@71 |
| 1 | 1 | 1 | 6µs | 33µs | PPI::Statement::Package::BEGIN@70 |
| 1 | 1 | 1 | 3µs | 3µs | PPI::Statement::Package::BEGIN@68 |
| 0 | 0 | 0 | 0s | 0s | PPI::Statement::Package::file_scoped |
| Line | State ments |
Time on line |
Calls | Time in subs |
Code |
|---|---|---|---|---|---|
| 1 | package PPI::Statement::Package; | ||||
| 2 | |||||
| 3 | =pod | ||||
| 4 | |||||
| 5 | =head1 NAME | ||||
| 6 | |||||
| 7 | PPI::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 | |||||
| 18 | Most L<PPI::Statement> subclasses are assigned based on the value of the | ||||
| 19 | first token or word found in the statement. When PPI encounters a statement | ||||
| 20 | starting with 'package', it converts it to a C<PPI::Statement::Package> | ||||
| 21 | object. | ||||
| 22 | |||||
| 23 | When working with package statements, please remember that packages only | ||||
| 24 | exist within their scope, and proper support for scoping has yet to be | ||||
| 25 | completed in PPI. | ||||
| 26 | |||||
| 27 | However, if the immediate parent of the package statement is the | ||||
| 28 | top level L<PPI::Document> object, then it can be considered to define | ||||
| 29 | everything found until the next top-level "file scoped" package statement. | ||||
| 30 | |||||
| 31 | A file may, however, contain nested temporary package, in which case you | ||||
| 32 | are mostly on your own :) | ||||
| 33 | |||||
| 34 | |||||
| 35 | =begin testing hash_constructors_dont_contain_packages_rt52259 2 | ||||
| 36 | |||||
| 37 | my $Document = PPI::Document->new(\<<'END_PERL'); | ||||
| 38 | { package => "", }; | ||||
| 39 | +{ package => "", }; | ||||
| 40 | { 'package' => "", }; | ||||
| 41 | +{ 'package' => "", }; | ||||
| 42 | { 'package' , "", }; | ||||
| 43 | +{ 'package' , "", }; | ||||
| 44 | END_PERL | ||||
| 45 | |||||
| 46 | isa_ok( $Document, 'PPI::Document' ); | ||||
| 47 | |||||
| 48 | my $packages = $Document->find('PPI::Statement::Package'); | ||||
| 49 | my $test_name = 'Found no package statements in hash constructors - RT #52259'; | ||||
| 50 | if (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 | |||||
| 62 | C<PPI::Statement::Package> has a number of methods in addition to the standard | ||||
| 63 | L<PPI::Statement>, L<PPI::Node> and L<PPI::Element> methods. | ||||
| 64 | |||||
| 65 | =cut | ||||
| 66 | |||||
| 67 | 2 | 19µs | 2 | 36µ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 # spent 24µs making 1 call to PPI::Statement::Package::BEGIN@67
# spent 12µs making 1 call to strict::import |
| 68 | 2 | 22µs | 1 | 3µ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 # spent 3µs making 1 call to PPI::Statement::Package::BEGIN@68 |
| 69 | |||||
| 70 | 2 | 27µs | 2 | 60µ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 # 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 | ||||
| 72 | 1 | 400ns | $VERSION = '1.215'; | ||
| 73 | 1 | 8µs | @ISA = 'PPI::Statement'; | ||
| 74 | 1 | 98µs | 1 | 8µs | } # spent 8µs making 1 call to PPI::Statement::Package::BEGIN@71 |
| 75 | |||||
| 76 | =pod | ||||
| 77 | |||||
| 78 | =head2 namespace | ||||
| 79 | |||||
| 80 | Most package declarations are simple, and just look something like | ||||
| 81 | |||||
| 82 | package Foo::Bar; | ||||
| 83 | |||||
| 84 | The C<namespace> method returns the name of the declared package, in the | ||||
| 85 | above case 'Foo::Bar'. It returns this exactly as written and does not | ||||
| 86 | attempt to clean up or resolve things like ::Foo to main::Foo. | ||||
| 87 | |||||
| 88 | If 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 | ||||
| 93 | 144 | 59µs | my $self = shift; | ||
| 94 | 144 | 611µs | 288 | 1.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 |
| 95 | 144 | 971µs | 288 | 342µ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 | |||||
| 104 | Regardless of whether it is named or not, the C<file_scoped> method will | ||||
| 105 | test to see if the package declaration is a top level "file scoped" | ||||
| 106 | statement or not, based on its location. | ||||
| 107 | |||||
| 108 | In general, returns true if it is a "file scoped" package declaration with | ||||
| 109 | an immediate parent of the top level Document, or false if not. | ||||
| 110 | |||||
| 111 | Note that if the PPI DOM tree B<does not> have a PPI::Document object at | ||||
| 112 | as the root element, this will return false. Likewise, it will also return | ||||
| 113 | false if the root element is a L<PPI::Document::Fragment>, as a fragment of | ||||
| 114 | a file does not represent a scope. | ||||
| 115 | |||||
| 116 | =cut | ||||
| 117 | |||||
| 118 | sub 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 | |||||
| 126 | 1 | 2µs | 1; | ||
| 127 | |||||
| 128 | =pod | ||||
| 129 | |||||
| 130 | =head1 SUPPORT | ||||
| 131 | |||||
| 132 | See the L<support section|PPI/SUPPORT> in the main module. | ||||
| 133 | |||||
| 134 | =head1 AUTHOR | ||||
| 135 | |||||
| 136 | Adam Kennedy E<lt>adamk@cpan.orgE<gt> | ||||
| 137 | |||||
| 138 | =head1 COPYRIGHT | ||||
| 139 | |||||
| 140 | Copyright 2001 - 2011 Adam Kennedy. | ||||
| 141 | |||||
| 142 | This program is free software; you can redistribute | ||||
| 143 | it and/or modify it under the same terms as Perl itself. | ||||
| 144 | |||||
| 145 | The full text of the license can be found in the | ||||
| 146 | LICENSE file included with this module. | ||||
| 147 | |||||
| 148 | =cut |