1PPIx::Regexp::Node(3) User Contributed Perl DocumentationPPIx::Regexp::Node(3)
2
3
4

NAME

6       PPIx::Regexp::Node - Represent a container
7

SYNOPSIS

9        use PPIx::Regexp::Dumper;
10        PPIx::Regexp::Dumper->new( 'qr{(foo)}' )->print();
11

INHERITANCE

13       "PPIx::Regexp::Node" is a PPIx::Regexp::Element.
14
15       "PPIx::Regexp::Node" is the parent of PPIx::Regexp,
16       PPIx::Regexp::Node::Range and PPIx::Regexp::Structure.
17

DESCRIPTION

19       This class represents a structural element that contains other classes.
20       It is an abstract class, not instantiated by the lexer.
21

METHODS

23       This class provides the following public methods. Methods not
24       documented here are private, and unsupported in the sense that the
25       author reserves the right to change or remove them without notice.
26
27   child
28        my $kid = $node->child( 0 );
29
30       This method returns the child at the given index. The indices start
31       from zero, and negative indices are from the end of the list, so that
32       "$node->child( -1 )" returns the last child of the node.
33
34   children
35       This method returns the children of the Node. If called in scalar
36       context it returns the number of children.
37
38   contains
39        print $node->contains( $elem ) ? "yes\n" : "no\n";
40
41       This method returns true if the given element is contained in the node,
42       or false otherwise.
43
44   elements
45       This method returns the elements in the Node. For a
46       "PPIx::Regexp::Node" proper, it is the same as "children()".
47
48   find
49        my $rslt = $node->find( 'PPIx::Regexp::Token::Literal' );
50        my $rslt = $node->find( 'Token::Literal' );
51        my $rslt = $node->find( sub {
52            return $_[1]->isa( 'PPIx::Regexp::Token::Literal' )
53                && $_[1]->ordinal < ord(' ');
54            } );
55
56       This method finds things.
57
58       If given a string as argument, it is assumed to be a class name
59       (possibly without the leading 'PPIx::Regexp::'), and all elements of
60       the given class are found.
61
62       If given a code reference, that code reference is called once for each
63       element, and passed $self and the element. The code should return true
64       to accept the element, false to reject it, and ( for subclasses of
65       "PPIx::Regexp::Node") "undef" to prevent recursion into the node. If
66       the code throws an exception, you get nothing back from this method.
67
68       Either way, the return is a reference to the list of things found, a
69       false (but defined) value if nothing was found, or "undef" if an error
70       occurred.
71
72   find_parents
73        my $rslt = $node->find_parents( sub {
74            return $_[1]->isa( 'PPIx::Regexp::Token::Operator' )
75                && $_[1]->content() eq '|';
76            } );
77
78       This convenience method takes the same arguments as "find", but instead
79       of the found objects themselves returns their parents. No parent will
80       appear more than once in the output.
81
82       This method returns a reference to the array of parents if any were
83       found. If no parents were found the return is false but defined. If an
84       error occurred the return is "undef".
85
86   find_first
87       This method has the same arguments as "find", but returns either a
88       reference to the first element found, a false (but defined) value if no
89       elements were found, or "undef" if an error occurred.
90
91   first_element
92       This method returns the first element in the node.
93
94   first_token
95       This method returns the first token in the node. If there is none, it
96       returns nothing.
97
98   last_element
99       This method returns the last element in the node.
100
101   last_token
102       This method returns the last token in the node. If there is none, it
103       returns nothing.
104
105   is_matcher
106       This method returns a true value if any of the node's children does.
107       Otherwise it returns "undef" if any of the node's children does.
108       Otherwise it returns a false (but defined) value.
109
110   perl_version_introduced
111       This method returns the maximum value of "perl_version_introduced"
112       returned by any of its elements. In other words, it returns the minimum
113       version of Perl under which this node is valid. If there are no
114       elements, 5.000 is returned, since that is the minimum value of Perl
115       supported by this package.
116
117   perl_version_removed
118       This method returns the minimum defined value of "perl_version_removed"
119       returned by any of the node's elements. In other words, it returns the
120       lowest version of Perl in which this node is "not" valid. If there are
121       no elements, or if no element has a defined "perl_version_removed",
122       "undef" is returned.
123
124   schild
125       This method returns the significant child at the given index; that is,
126       "$node->schild(0)" returns the first significant child,
127       "$node->schild(1)" returns the second significant child, and so on.
128       Negative indices count from the end.
129
130   schildren
131       This method returns the significant children of the Node. If called in
132       scalar context it returns the number of significant children.
133

SUPPORT

135       Support is by the author. Please file bug reports at
136       <https://rt.cpan.org/Public/Dist/Display.html?Name=PPIx-Regexp>,
137       <https://github.com/trwyant/perl-PPIx-Regexp/issues>, or in electronic
138       mail to the author.
139

AUTHOR

141       Thomas R. Wyant, III wyant at cpan dot org
142
144       Copyright (C) 2009-2021 by Thomas R. Wyant, III
145
146       This program is free software; you can redistribute it and/or modify it
147       under the same terms as Perl 5.10.0. For more details, see the full
148       text of the licenses in the directory LICENSES.
149
150       This program is distributed in the hope that it will be useful, but
151       without any warranty; without even the implied warranty of
152       merchantability or fitness for a particular purpose.
153
154
155
156perl v5.34.0                      2021-10-25             PPIx::Regexp::Node(3)
Impressum