PPI::Structure(3)
β¨ PPI::Structure β¨
okay bestie, gather round, because we're talking about PPI::Structure from the User Contributed Perl Documentation collection π
this is the base class for Perl braced structures, and ngl it's lowkey one of the most important little guys in the whole PPI fam.
π«Ά INHERITANCE π«Ά
the family tree is giving royal lineage, fr fr:
PPI::Structure
isa PPI::Node
isa PPI::Element
so yeah, it's a PPI::Node, which is itself a PPI::Element. iconic bloodline honestly π
πΈ DESCRIPTION πΈ
PPI::Structure is the root class for all Perl bracing structures. we're talking every form of:
[ ... ]{ ... }( ... )
and yes, it also covers the messy cases where only one half of the pair exists. no judgment, we've all been there π
heads up bestie: the class PPI::Structure itself is completely abstract, and no objects of that type should actually exist in the tree. it's giving "concept, not content" β¨
π¦ Elements vs Children π¦
a PPI::Structure has a genuinely unusual existence. like, main character energy. unlike a PPI::Document or a PPI::Statement β which both simply contain other elements β a structure both contains and consists of content.
that is, the brace tokens are not considered to be "children" of the structure, but they are part of it. periodt.
in practice, this means:
- while the
->elementsand->tokensmethods (and related ones) will return a list with the brace tokens at either end - the
->childrenmethod explicitly will not return the brace
the way that one method just opts out of the whole situation... relatable π
π STRUCTURE CLASSES π
okay so, excluding the transient PPI::Structure::Unknown that exists briefly inside the parser (blink and you'll miss her π), there are eight types of structure. let's meet the girlies:
π PPI::Structure::List
this covers all round braces used for:
- function arguments
foreachloops- literal lists
- braces used for precedence-ordering purposes
π PPI::Structure::For
although it's not used for the foreach loop list, this one is used for the special case of the round-brace three-part semicolon-separated for loop expression β yep, the traditional C style for loop. vintage but she still slays π₯
π PPI::Structure::Given
this is for the expression being matched in switch statements. matching, but make it given β¨
π PPI::Structure::When
this is for the matching expression in when statements. when the when is when-ing π
π PPI::Structure::Condition
this round-brace structure covers boolean conditional braces, such as for if and while blocks. she's the "should we even do this" girlie π§
π PPI::Structure::Block
this curly-brace and common structure is used for all forms of code blocks. that includes those for if, do and similar, as well as grep, map, sort, sub and (labelled or anonymous) scoping blocks. the hardest working babe in the whole module, no cap π
π PPI::Structure::Constructor
this class covers brace structures used for the construction of anonymous ARRAY and HASH references. building things out of thin air, we love a creator π
π PPI::Structure::Subscript
this class covers square-braces and curly-braces used after a -> pointer to access the subscript of an ARRAY or HASH. it's giving "indexing, but make it chic" π
π METHODS π
ngl, PPI::Structure 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 π«Ά
β start
for lack of better terminology (like open and close) that has not already been in use for some other more important purpose, the two individual braces for the structure are known within PPI as the "start" and "finish" braces (at least for method purposes).
the start method returns the start brace for the structure β i.e. the opening brace β¨
returns the brace as a PPI::Token::Structure, or undef if the structure does not have a starting brace.
under normal parsing circumstances this should never occur, but it may happen due to manipulation of the PDOM tree. so like... don't go poking the tree, bestie π
β finish
the finish method returns the finish brace for the structure β i.e. the closing brace β¨
returns the brace as a PPI::Token::Structure, or undef if the structure does not have a finishing brace.
this can be quite common if the document is not complete β for example, from an editor where the user may be halfway through typing a subroutine. we've all got half-finished subs lying around, it's fine, it's a vibe π
β braces
the braces method is a utility method which returns the brace type, regardless of whether both or just one of the braces is defined. she doesn't gatekeep π
returns one of the three strings:
'[]''{}''()'
or undef on error β primarily not having a start brace, as mentioned above.
β complete
the complete method is a convenience method that returns:
- true if both braces are defined for the structure
- false if only one brace is defined
unlike the top levelcompletemethod, which checks for completeness in depth, the structurecompletemethod ONLY confirms completeness for the braces, and does not recurse downwards. surface level queen, and honestly? valid π
π SUPPORT π
see the support section in the main module. (iykyk π«Ά)
π 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 cap π this was PPI::Structure(3) from perl v5.42.0, dated 2026-01-17. go forth and parse those braces, you absolute icon πβ¨π¦
π¦ 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