| 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 | =head1 METHODS | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | C<PPI::Statement::Package> has a number of methods in addition to the standard | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | L<PPI::Statement>, L<PPI::Node> and L<PPI::Element> methods. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 63 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 63 | ▶ | use PPI::Statement (); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 63 | our $VERSION = '1.260'; # VERSION | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 63 | our @ISA = "PPI::Statement"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | # Lexer clues | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | sub __LEXER__normal() { '' } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | =pod | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | =head2 namespace | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | Most package declarations are simple, and just look something like | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | package Foo::Bar; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | The C<namespace> method returns the name of the declared package, in the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | above case 'Foo::Bar'. It returns this exactly as written and does not | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | attempt to clean up or resolve things like ::Foo to main::Foo. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | If the package statement is done any different way, it returns false. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | sub namespace { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | 4 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
namespace: called CC=3 SCAR=11.7
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 4 | ▶ | my $namespace = $self->schild(1) or return ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | 4 | ▶ | $namespace->isa('PPI::Token::Word') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | ? $namespace->content | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | : ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | =pod | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | =head2 version | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | Some package declarations may include a version: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | package Foo::Bar 1.23; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | package Baz v1.23; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | The C<version> method returns the stringified version as seen in the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | document (if any), otherwise the empty string. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | sub version { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 4 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
version: called CC=3 SCAR=11.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 4 | ▶ | my $version = $self->schild(2) or return ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 4 | ▶ | $version->isa('PPI::Token::Structure') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | ? '' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | : $version->content; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | =pod | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | =head2 file_scoped | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | Regardless of whether it is named or not, the C<file_scoped> method will | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | test to see if the package declaration is a top level "file scoped" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | statement or not, based on its location. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | In general, returns true if it is a "file scoped" package declaration with | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | an immediate parent of the top level Document, or false if not. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | Note that if the PPI DOM tree B<does not> have a PPI::Document object at | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | as the root element, this will return false. Likewise, it will also return | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | false if the root element is a L<PPI::Document::Fragment>, as a fragment of | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | a file does not represent a scope. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | sub file_scoped { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | 4 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
file_scoped: called CC=5 SCAR=17.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | 4 | my ($Parent, $Document) = ($self->parent, $self->top); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | 4 | ▶ | $Parent and $Document and $Parent == $Document | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition55%5/9
$Parent and $Document and $Parent == $Document and $Document->isa("PPI::Document")
$Parent and $Document and $Parent == $Document
$Parent and $Document
MC/DC0%0/4
$Parent and $Document and $Parent == $Document and $Document->isa("PPI::Document")
$Parent
$Document
$Parent == $Document
$Document->isa("PPI::Document")
Truth table0%0/5
A and B and C and D
A= $ParentB= $DocumentC= $Parent == $DocumentD= $Document->isa("PPI::Document")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | and $Document->isa('PPI::Document') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | and ! $Document->isa('PPI::Document::Fragment'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | 63 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | =pod | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | =head1 SUPPORT | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | See the L<support section|PPI/SUPPORT> in the main module. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | =head1 AUTHOR | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | Adam Kennedy E<lt>adamk@cpan.orgE<gt> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | =head1 COPYRIGHT | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | Copyright 2001 - 2011 Adam Kennedy. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | This program is free software; you can redistribute | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | it and/or modify it under the same terms as Perl itself. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | The full text of the license can be found in the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | LICENSE file included with this module. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||