1 package PPI::Statement::Package;
7 PPI::Statement::Package - A package statement
11 PPI::Statement::Package
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>
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
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.
31 A file may, however, contain nested temporary package, in which case you
32 are mostly on your own :)
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.
42 use PPI::Statement ();
44 use vars qw{$VERSION @ISA};
47 @ISA = 'PPI::Statement';
54 Most package declarations are simple, and just look something like
58 The C<namespace> method returns the name of the declared package, in the
59 above case 'Foo::Bar'. It returns this exactly as written and does not
60 attempt to clean up or resolve things like ::Foo to main::Foo.
62 If the package statement is done any different way, it returns false.
68 my $namespace = $self->schild(1) or return '';
69 $namespace->isa('PPI::Token::Word')
78 Regardless of whether it is named or not, the C<file_scoped> method will
79 test to see if the package declaration is a top level "file scoped"
80 statement or not, based on its location.
82 In general, returns true if it is a "file scoped" package declaration with
83 an immediate parent of the top level Document, or false if not.
85 Note that if the PPI DOM tree B<does not> have a PPI::Document object at
86 as the root element, this will return false. Likewise, it will also return
87 false if the root element is a L<PPI::Document::Fragment>, as a fragment of
88 a file does not represent a scope.
94 my ($Parent, $Document) = ($self->parent, $self->top);
95 $Parent and $Document and $Parent == $Document
96 and $Document->isa('PPI::Document')
97 and ! $Document->isa('PPI::Document::Fragment');
106 See the L<support section|PPI/SUPPORT> in the main module.
110 Adam Kennedy E<lt>adamk@cpan.orgE<gt>
114 Copyright 2001 - 2009 Adam Kennedy.
116 This program is free software; you can redistribute
117 it and/or modify it under the same terms as Perl itself.
119 The full text of the license can be found in the
120 LICENSE file included with this module.