1PPI::Statement(3) User Contributed Perl Documentation PPI::Statement(3)
2
3
4
6 PPI::Statement - The base class for Perl statements
7
9 PPI::Statement
10 isa PPI::Node
11 isa PPI::Element
12
14 PPI::Statement is the root class for all Perl statements. This includes
15 (from perlsyn) "Declarations", "Simple Statements" and "Compound State‐
16 ments".
17
18 The class PPI::Statement itself represents a "Simple Statement" as
19 defined in the perlsyn manpage.
20
22 Please note that unless documented themselves, these classes are yet to
23 be frozen/finalised. Names may change slightly or be added or removed.
24
25 PPI::Statement::Scheduled
26
27 This covers all "scheduled" blocks, chunks of code that are executed
28 separately from the main body of the code, at a particular time. This
29 includes all "BEGIN", "CHECK", "INIT" and "END" blocks.
30
31 PPI::Statement::Package
32
33 A package declaration, as defined in perlfunc.
34
35 PPI::Statement::Include
36
37 A statement that loads or unloads another module.
38
39 This includes 'use', 'no', and 'require' statements.
40
41 PPI::Statement::Sub
42
43 A named subroutine declaration, or forward declaration
44
45 PPI::Statement::Variable
46
47 A variable declaration statement. This could be either a straight dec‐
48 laration or also be an expression.
49
50 This includes all 'my', 'local' and 'out' statements.
51
52 PPI::Statement::Compound
53
54 This covers the whole family of 'compound' statements, as described in
55 perlsyn.
56
57 This includes all statements starting with 'if', 'unless', 'for',
58 'foreach' and 'while'. Note that this does NOT include 'do', as it is
59 treated differently.
60
61 All compound statements have implicit ends. That is, they do not end
62 with a ';' statement terminator.
63
64 PPI::Statement::Break
65
66 A statement that breaks out of a structure.
67
68 This includes all of 'redo', 'next', 'last' and 'return' statements.
69
70 PPI::Statement::Data
71
72 A special statement which encompasses an entire "__DATA__" block,
73 including the initial '__DATA__' token itself and the entire contents.
74
75 PPI::Statement::End
76
77 A special statement which encompasses an entire __END__ block, includ‐
78 ing the initial '__END__' token itself and the entire contents, includ‐
79 ing any parsed PPI::Token::POD that may occur in it.
80
81 PPI::Statement::Expression
82
83 PPI::Statement::Expression is a little more speculative, and is
84 intended to help represent the special rules relating to "expressions"
85 such as in:
86
87 # Several examples of expression statements
88
89 # Boolean conditions
90 if ( expression ) { ... }
91
92 # Lists, such as for arguments
93 Foo->bar( expression )
94
95 PPI::Statement::Null
96
97 A null statement is a special case for where we encounter two consecu‐
98 tive statement terminators. ( ;; )
99
100 The second terminator is given an entire statement of its own, but one
101 that serves no purpose. Hence a 'null' statement.
102
103 Theoretically, assuming a correct parsing of a perl file, all null
104 statements are superfluous and should be able to be removed without
105 damage to the file.
106
107 But don't do that, in case PPI has parsed something wrong.
108
109 PPI::Statement::UnmatchedBrace
110
111 Because PPI is intended for use when parsing incorrect or incomplete
112 code, the problem arises of what to do with a stray closing brace.
113
114 Rather than die, it is allocated its own "unmatched brace" statement,
115 which really means "unmatched closing brace". An unmatched open brace
116 at the end of a file would become a structure with no contents and no
117 closing brace.
118
119 If the document loaded is intended to be correct and valid, finding a
120 PPI::Statement::UnmatchedBrace in the PDOM is generally indicative of a
121 misparse.
122
123 PPI::Statement::Unknown
124
125 This is used temporarily mid-parsing to hold statements for which the
126 lexer cannot yet determine what class it should be, usually because
127 there are insufficient clues, or it might be more than one thing.
128
129 You should never encounter these in a fully parsed PDOM tree.
130
132 "PPI::Statement" itself has very few methods. Most of the time, you
133 will be working with the more generic PPI::Element or PPI::Node meth‐
134 ods, or one of the methods that are subclass-specific.
135
136 label
137
138 One factor common to most statements is their ability to be labeled.
139
140 The "label" method returns the label for a statement, if one has been
141 defined, but without the trailing colon. Take the following example
142
143 MYLABEL: while ( 1 .. 10 ) { last MYLABEL if $_ > 5 }
144
145 For the above statement, the "label" method would return 'MYLABEL'.
146
147 Returns false if the statement does not have a label.
148
149 stable
150
151 Much like the PPI::Document method of the same name, the ->stable
152 method converts a statement to source and back again, to determine if a
153 modified statement is still legal, and won't be interpreted in a dif‐
154 ferent way.
155
156 Returns true if the statement is stable, false if not, or "undef" on
157 error.
158
160 - Complete, freeze and document the remaining classes
161
163 See the support section in the main module.
164
166 Adam Kennedy <adamk@cpan.org>
167
169 Copyright 2001 - 2006 Adam Kennedy.
170
171 This program is free software; you can redistribute it and/or modify it
172 under the same terms as Perl itself.
173
174 The full text of the license can be found in the LICENSE file included
175 with this module.
176
177
178
179perl v5.8.8 2006-09-23 PPI::Statement(3)