1PPI::Structure(3)     User Contributed Perl Documentation    PPI::Structure(3)
2
3
4

NAME

6       PPI::Structure - The base class for Perl braced structures
7

INHERITANCE

9         PPI::Structure
10         isa PPI::Node
11             isa PPI::Element
12

DESCRIPTION

14       PPI::Structure is the root class for all Perl bracing structures. This
15       covers all forms of " [ ... ] ", " { ... } ", and " ( ... ) " brace
16       types, and includes cases where only one half of the pair exist.
17
18       The class PPI::Structure itself is full abstract and no objects of that
19       type should actually exist in the tree.
20
21   Elements vs Children
22       A PPI::Structure has an unusual existence. Unlike a PPI::Document or
23       PPI::Statement, which both simply contain other elements, a structure
24       both contains and consists of content.
25
26       That is, the brace tokens are not considered to be "children" of the
27       structure, but are part of it.
28
29       In practice, this will mean that while the ->elements and ->tokens
30       methods (and related) will return a list with the brace tokens at
31       either end, the ->children method explicitly will not return the brace.
32

STRUCTURE CLASSES

34       Excluding the transient PPI::Structure::Unknown that exists briefly
35       inside the parser, there are eight types of structure.
36
37   PPI::Structure::List
38       This covers all round braces used for function arguments, in "foreach"
39       loops, literal lists, and braces used for precedence-ordering purposes.
40
41   PPI::Structure::For
42       Although not used for the "foreach" loop list, this is used for the
43       special case of the round-brace three-part semicolon-separated "for"
44       loop expression (the traditional C style for loop).
45
46   PPI::Structure::Given
47       This is for the expression being matched in switch statements.
48
49   PPI::Structure::When
50       This is for the matching expression in "when" statements.
51
52   PPI::Structure::Condition
53       This round-brace structure covers boolean conditional braces, such as
54       for "if" and "while" blocks.
55
56   PPI::Structure::Block
57       This curly-brace and common structure is used for all form of code
58       blocks. This includes those for "if", "do" and similar, as well as
59       "grep", "map", "sort", "sub" and (labelled or anonymous) scoping
60       blocks.
61
62   PPI::Structure::Constructor
63       This class covers brace structures used for the construction of
64       anonymous "ARRAY" and "HASH" references.
65
66   PPI::Structure::Subscript
67       This class covers square-braces and curly-braces used after a ->
68       pointer to access the subscript of an "ARRAY" or "HASH".
69

METHODS

71       "PPI::Structure" itself has very few methods. Most of the time, you
72       will be working with the more generic PPI::Element or PPI::Node
73       methods, or one of the methods that are subclass-specific.
74
75   start
76       For lack of better terminology (like "open" and "close") that has not
77       already in use for some other more important purpose, the two
78       individual braces for the structure are known within PPI as the "start"
79       and "finish" braces (at least for method purposes).
80
81       The "start" method returns the start brace for the structure (i.e. the
82       opening brace).
83
84       Returns the brace as a PPI::Token::Structure or "undef" if the
85       structure does not have a starting brace.
86
87       Under normal parsing circumstances this should never occur, but may
88       happen due to manipulation of the PDOM tree.
89
90   finish
91       The "finish" method returns the finish brace for the structure (i.e.
92       the closing brace).
93
94       Returns the brace as a PPI::Token::Structure or "undef" if the
95       structure does not have a finishing brace. This can be quite common if
96       the document is not complete (for example, from an editor where the
97       user may be halfway through typeing a subroutine).
98
99   braces
100       The "braces" method is a utility method which returns the brace type,
101       regardless of whether both or just one of the braces is defined.
102
103       Returns one of the three strings '[]', '{}', or '()', or "undef" on
104       error (primarily not having a start brace, as mentioned above).
105

complete

107       The "complete" method is a convenience method that returns true if the
108       both braces are defined for the structure, or false if only one brace
109       is defined.
110
111       Unlike the top level "complete" method which checks for completeness in
112       depth, the structure complete method ONLY confirms completeness for the
113       braces, and does not recurse downwards.
114

SUPPORT

116       See the support section in the main module.
117

AUTHOR

119       Adam Kennedy <adamk@cpan.org>
120
122       Copyright 2001 - 2011 Adam Kennedy.
123
124       This program is free software; you can redistribute it and/or modify it
125       under the same terms as Perl itself.
126
127       The full text of the license can be found in the LICENSE file included
128       with this module.
129
130
131
132perl v5.32.0                      2020-07-28                 PPI::Structure(3)
Impressum