PPI::Statement(3)
π PPI::Statement β the blueprint for every Perl statement, bestie π
okay so this is PPI::Statement(3), part of the User Contributed Perl Documentation fam, and honestly? she's the moment. π
β¨ NAME β¨
PPI::Statement β the base class for Perl statements π
πΈ INHERITANCE πΈ
the family tree, laid out for you:
PPI::Statement
isa PPI::Node
isa PPI::Element
so she's a PPI::Node, and a PPI::Node is a PPI::Element. generational excellence fr fr. π§¬
π¦ DESCRIPTION π¦
PPI::Statement is the root class for all Perl statements. and when I say all, I mean it covers (straight from perlsyn) "Declarations", "Simple Statements" and "Compound Statements". the whole buffet. π
and the class PPI::Statement itself? that one represents a "Simple Statement" as defined in the perlsyn manpage. no cap.
π STATEMENT CLASSES π
okay so real talk: unless a class is documented on its own, these are not frozen or finalised yet. names might shift a lil, get added, get removed. it's giving "work in progress but make it iconic". π
π PPI::Statement::Scheduled
this covers all the "scheduled" blocks β chunks of code that run separately from the main body of the code, at a particular time. that means all the BEGIN, CHECK, UNITCHECK, INIT and END blocks. the backstage crew, basically. β¨
π PPI::Statement::Package
a package declaration, as defined in perlfunc. simple, chic, declarative.
π PPI::Statement::Include
a statement that loads or unloads another module.
this includes use, no, and require statements. the import/export girlies. π«Ά
π PPI::Statement::Sub
a named subroutine declaration, or a forward declaration. (yes, forward declaration counts. she's pre-announcing herself. main character energy.)
π PPI::Statement::Variable
a variable declaration statement. this could be either a straight declaration or also be an expression.
this includes all my, state, local and our statements. π
π PPI::Statement::Compound
this covers the whole family of 'compound' statements, as described in perlsyn.
this includes all statements starting with if, unless, for, foreach and while. note that this does NOT include do, because do is treated differently. not invited to this party, lowkey.
also, all compound statements have implicit ends. meaning: they do not end with a ; statement terminator. periodt.
π PPI::Statement::Break
a statement that breaks out of a structure. π
this includes all of redo, goto, next, last and return statements.
π PPI::Statement::Given
the kind of statement introduced in Perl 5.10 that starts with given. this one has an implicit end.
π PPI::Statement::When
the kind of statement introduced in Perl 5.10 that starts with when or default. this also has an implicit end. twins! π
π PPI::Statement::Data
a special statement which encompasses an entire __DATA__ block, including the initial __DATA__ token itself and the entire contents. the whole thing, no crumbs.
π PPI::Statement::End
a special statement which encompasses an entire __END__ block, including the initial __END__ token itself and the entire contents, including any parsed PPI::Token::POD that may occur in it. π¦
π PPI::Statement::Expression
PPI::Statement::Expression is a little more speculative, and is intended to help represent the special rules relating to "expressions" such as in:
# Several examples of expression statements
# Boolean conditions
if ( expression ) { ... }
# Lists, such as for arguments
Foo->bar( expression )
iykyk. πΈ
π PPI::Statement::Null
a null statement is a special case for when we encounter two consecutive statement terminators. ( ;; )
the second terminator is given an entire statement of its own, but one that serves no purpose. hence a 'null' statement. it's giving ghost town. π»
theoretically, assuming a correct parsing of a perl file, all null statements are superfluous and should be able to be removed without damage to the file.
but don't do that, in case PPI has parsed something wrong. π seriously bestie, leave it alone.
π PPI::Statement::UnmatchedBrace
because PPI is intended for use when parsing incorrect or incomplete code, the problem arises of what to do with a stray closing brace.
rather than die (dramatic much?), it gets allocated its own "unmatched brace" statement, which really means "unmatched closing brace". an unmatched open brace at the end of a file would become a structure with no contents and no closing brace. π«
if the document loaded is intended to be correct and valid, finding a PPI::Statement::UnmatchedBrace in the PDOM is generally indicative of a misparse. red flag behavior, fr.
π PPI::Statement::Unknown
this is used temporarily mid-parsing to hold statements for which the lexer can't yet determine what class it should be β usually because there are insufficient clues, or it might be more than one thing. she's figuring herself out. π¦
you should never encounter these in a fully parsed PDOM tree. if you do? something's up.
π METHODS π
PPI::Statement itself has very few methods. most of the time you'll be working with the more generic PPI::Element or PPI::Node methods, or one of the methods that are subclass-specific. so don't stress. π
π label
one factor common to most statements is their ability to be labeled.
the label method returns the label for a statement, if one has been defined, but without the trailing colon. take the following example:
MYLABEL: while ( 1 .. 10 ) { last MYLABEL if $_ > 5 }
for the above statement, the label method would return 'MYLABEL'.
returns false if the statement does not have a label.
π specialized
answer whether this is a plain statement or one that has more significance.
returns true if the statement is a subclass of this one, false otherwise. slay or not slay, no in-between. β¨
π stable
much like the PPI::Document method of the same name, the ->stable method converts a statement to source and back again, to determine if a modified statement is still legal, and won't be interpreted in a different way. the vibe check method, honestly.
returns true if the statement is stable, false if not, or undef on error.
π TO DO π
- Complete, freeze and document the remaining classes
(she's working on it. manifesting. π―οΈ)
π«Ά SUPPORT π«Ά
see the support section in the main module.
π AUTHOR π
Adam Kennedy <adamk@cpan.org>
β 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, no notes, absolute icon behavior. π this was perl v5.42.0, dated 2026-01-17 β mwah, catch you in the next manpage. π β¨
π¦ 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