PPI::St...:Package(3)
π NAME π
okay so bestie, gather round, because today we're talking about PPI::Statement::Package β it's literally the object that represents a package statement in your Perl code. yes. that package Foo::Bar; line you write at the top of every file and then never think about again? it has lore. it has a whole class. slay. π
πΈ INHERITANCE πΈ
the family tree, and yes it's giving royal lineage:
PPI::Statement::Package
isa PPI::Statement
isa PPI::Node
isa PPI::Element
so it's a Statement, which is a Node, which is an Element. iconic chain, no notes. π
β¨ DESCRIPTION β¨
here's the tea β β most of the PPI::Statement subclasses get picked based on whatever the first token or word in the statement is. so when PPI bumps into a statement that starts with package, it's like "oh!! okay!!" and converts the whole thing into a PPI::Statement::Package object. automatic. effortless. main character energy. π
but β and this is the important bit, bestie, don't skip it β when you're working with package statements, pls remember that packages only exist within their scope, and proper support for scoping has yet to be completed in PPI. so like, it's not fully there yet. lowkey a work in progress. π
However, there's a vibe check we can pass: if the immediate parent of the package statement is the top level PPI::Document object, then you can consider it to define everything found until the next top-level "file scoped" package statement. periodt. β
and also β a file may contain nested temporary packages, in which case, and I quote the energy here, you are mostly on your own :) good luck babe π«Ά
π METHODS π
PPI::Statement::Package has a bunch of methods on top of the standard PPI::Statement, PPI::Node and PPI::Element methods. the usual squad, plus extras.
π¦ namespace
most package declarations are super simple and just look like:
package Foo::Bar;
the namespace method hands you back the name of the declared package β in the case above, that's 'Foo::Bar'. and it gives it to you exactly as written. it does not try to clean things up or resolve stuff like ::Foo into main::Foo. no editing, no fixing, no notes. raw. untouched. π―
and if the package statement was written any other kind of way? it returns false. that's it. that's the whole thing.
π version
some package declarations come with a version attached, like:
package Foo::Bar 1.23;
package Baz v1.23;
the version method returns the stringified version exactly as seen in the document (if there is one at all), otherwise it gives you back the empty string. no version? empty string. simple as that. β¨
π file_scoped
okay this one is fun. regardless of whether the package is named or not, file_scoped tests whether the package declaration is a top level "file scoped" statement or not, and it figures that out based on its location. it's all about where you are, bestie. π
generally speaking: returns true if it's a "file scoped" package declaration whose immediate parent is the top level Document, or false if it isn't.
and here's the warning bit, don't skip it β if the PPI DOM tree doesn't have aPPI::Documentobject at the root element, this returns false. likewise, it also returns false if the root element is aPPI::Document::Fragment, because a fragment of a file doesn't represent a scope. no scope, no file_scoped. them's the rules. π
π«Ά SUPPORT π«Ά
see the support section in the main module. that's where the help lives, bestie, go look. π
π AUTHOR π
Adam Kennedy <adamk@cpan.org> β we stan. π
β COPYRIGHT β
Copyright 2001 - 2011 Adam Kennedy.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
The full text of the license can be found in the LICENSE file included with this module.
and that's the whole page, bestie!! this was documented for perl v5.42.0, dated 2026-01-17, and it came from the User Contributed Perl Documentation. go forth and declare your packages with confidence. mwah. π πΈβ¨
π¦ where this page comes from
- fedora 44: perl-PPI 1.284-2.fc44 Β· GPL-1.0-or-later OR Artistic-1.0-Perl
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms