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   last_element
95       This method returns the last element in the node.
96
97   perl_version_introduced
98       This method returns the maximum value of "perl_version_introduced"
99       returned by any of its elements. In other words, it returns the minimum
100       version of Perl under which this node is valid. If there are no
101       elements, 5.000 is returned, since that is the minimum value of Perl
102       supported by this package.
103
104   perl_version_removed
105       This method returns the minimum defined value of "perl_version_removed"
106       returned by any of the node's elements. In other words, it returns the
107       lowest version of Perl in which this node is "not" valid. If there are
108       no elements, or if no element has a defined "perl_version_removed",
109       "undef" is returned.
110
111   schild
112       This method returns the significant child at the given index; that is,
113       "$node->schild(0)" returns the first significant child,
114       "$node->schild(1)" returns the second significant child, and so on.
115       Negative indices count from the end.
116
117   schildren
118       This method returns the significant children of the node.
119

SUPPORT

121       Support is by the author. Please file bug reports at
122       <https://rt.cpan.org>, or in electronic mail to the author.
123

AUTHOR

125       Thomas R. Wyant, III wyant at cpan dot org
126
128       Copyright (C) 2009-2020 by Thomas R. Wyant, III
129
130       This program is free software; you can redistribute it and/or modify it
131       under the same terms as Perl 5.10.0. For more details, see the full
132       text of the licenses in the directory LICENSES.
133
134       This program is distributed in the hope that it will be useful, but
135       without any warranty; without even the implied warranty of
136       merchantability or fitness for a particular purpose.
137
138
139
140perl v5.30.1                      2020-02-10             PPIx::Regexp::Node(3)
Impressum