Regex/Element.pm

filter: Statementstmt 42.0% 50 / 119 Branchbran 66.6% 8 / 12 Conditioncond 43.4% 20 / 46 MC/DCmcdc 13.0% 3 / 23 Subroutinesub 40.9% 36 / 88 Podpod 100% 5 / 5 totaltotal 41.6% 122 / 293 CC 30 SCAR 12.5
CC
30
Cov
44%
new
20.0
new
12.0
new
7.7
CRAP 3.5
« Regex.pm ↑ Summary
1 package YAPE::Regex::Element;
2  
3 1 $VERSION = '4.00';
4  
5  
6 24 ▶sub text { exists $_[0]{TEXT} ? $_[0]{TEXT} : "" }
Subroutine text: called CC=2 SCAR=7.6
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
exists $_[0]{'TEXT'} ? : 24 0 24
7 36 ▶sub string { $_[0]->text . "$_[0]{QUANT}$_[0]{NGREED}" }
Subroutine string: called CC=1 SCAR=0.0
Pod documented
8 39 ▶sub fullstring { $_[0]->string }
Subroutine fullstring: called CC=1 SCAR=0.0
Pod documented
9 0 ▶sub quant { "$_[0]{QUANT}$_[0]{NGREED}" }
Subroutine quant: not called CC=1 SCAR=6.9
Pod documented
10 0 ▶sub ngreed { $_[0]{NGREED} }
Subroutine ngreed: not called CC=1 SCAR=6.9
Pod documented
11  
12  
13 package YAPE::Regex::anchor;
14  
15 0 ▶sub new {
Subroutine new: not called CC=1 SCAR=6.9
16 0 my ($class,$match,$q,$ng) = @_;
17 0 bless { TEXT => $match, QUANT => $q, NGREED => $ng }, $class;
18 }
19  
20 0 ▶sub type { 'anchor' }
Subroutine type: not called CC=1 SCAR=6.9
21  
22  
23  
24 package YAPE::Regex::macro;
25  
26 0 ▶sub new {
Subroutine new: not called CC=1 SCAR=6.9
27 0 my ($class,$match,$q,$ng) = @_;
28 0 bless { TEXT => $match, QUANT => $q, NGREED => $ng }, $class;
29 }
30  
31 0 ▶sub text { "\\$_[0]{TEXT}" }
Subroutine text: not called CC=1 SCAR=6.9
32 0 ▶sub type { 'macro' }
Subroutine type: not called CC=1 SCAR=6.9
33  
34  
35  
36 package YAPE::Regex::oct;
37  
38 0 ▶sub new {
Subroutine new: not called CC=1 SCAR=6.9
39 0 my ($class,$match,$q,$ng) = @_;
40 0 bless { TEXT => $match, QUANT => $q, NGREED => $ng }, $class;
41 }
42  
43 0 ▶sub text { "\\$_[0]{TEXT}" }
Subroutine text: not called CC=1 SCAR=6.9
44 0 ▶sub type { 'oct' }
Subroutine type: not called CC=1 SCAR=6.9
45  
46  
47  
48 package YAPE::Regex::hex;
49  
50 1 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
51 1 my ($class,$match,$q,$ng) = @_;
52 1 bless { TEXT => $match, QUANT => $q, NGREED => $ng }, $class;
53 }
54  
55 1 ▶sub text { "\\x$_[0]{TEXT}" }
Subroutine text: called CC=1 SCAR=0.0
56 0 ▶sub type { 'hex' }
Subroutine type: not called CC=1 SCAR=6.9
57  
58  
59  
60 package YAPE::Regex::backref;
61  
62 1 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
63 1 my ($class,$match,$q,$ng) = @_;
64 1 bless { TEXT => $match, QUANT => $q, NGREED => $ng }, $class;
65 }
66  
67 1 ▶sub text { "\\$_[0]{TEXT}" }
Subroutine text: called CC=1 SCAR=0.0
68 0 ▶sub type { 'backref' }
Subroutine type: not called CC=1 SCAR=6.9
69  
70  
71  
72 package YAPE::Regex::ctrl;
73  
74 0 ▶sub new {
Subroutine new: not called CC=1 SCAR=6.9
75 0 my ($class,$match,$q,$ng) = @_;
76 0 bless { TEXT => $match, QUANT => $q, NGREED => $ng }, $class;
77 }
78  
79 0 ▶sub text { "\\c$_[0]{TEXT}" }
Subroutine text: not called CC=1 SCAR=6.9
80 0 ▶sub type { 'ctrl' }
Subroutine type: not called CC=1 SCAR=6.9
81  
82  
83  
84 package YAPE::Regex::named;
85  
86 0 ▶sub new {
Subroutine new: not called CC=1 SCAR=6.9
87 0 my ($class,$match,$q,$ng) = @_;
88 0 bless { TEXT => $match, QUANT => $q, NGREED => $ng }, $class;
89 }
90  
91 0 ▶sub text { "\\N{$_[0]{TEXT}}" }
Subroutine text: not called CC=1 SCAR=6.9
92 0 ▶sub type { 'named' }
Subroutine type: not called CC=1 SCAR=6.9
93  
94  
95  
96 package YAPE::Regex::Cchar;
97  
98 0 ▶sub new {
Subroutine new: not called CC=1 SCAR=6.9
99 0 my ($class,$q,$ng) = @_;
100 0 bless { QUANT => $q, NGREED => $ng }, $class;
101 }
102  
103 0 ▶sub text { '\C' }
Subroutine text: not called CC=1 SCAR=6.9
104 0 ▶sub type { 'Cchar' }
Subroutine type: not called CC=1 SCAR=6.9
105  
106  
107  
108 package YAPE::Regex::slash;
109  
110 0 ▶sub new {
Subroutine new: not called CC=1 SCAR=6.9
111 0 my ($class,$match,$q,$ng) = @_;
112 0 bless { TEXT => $match, QUANT => $q, NGREED => $ng }, $class;
113 }
114  
115 0 ▶sub text { "\\$_[0]{TEXT}" }
Subroutine text: not called CC=1 SCAR=6.9
116 0 ▶sub type { 'slash' }
Subroutine type: not called CC=1 SCAR=6.9
117  
118  
119  
120 package YAPE::Regex::any;
121  
122 0 ▶sub new {
Subroutine new: not called CC=1 SCAR=6.9
123 0 my ($class,$q,$ng) = @_;
124 0 bless { TEXT => '.', QUANT => $q, NGREED => $ng }, $class;
125 }
126  
127 0 ▶sub type { 'any' }
Subroutine type: not called CC=1 SCAR=6.9
128  
129  
130  
131 package YAPE::Regex::class;
132  
133 6 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
134 6 my ($class,$match,$neg,$q,$ng) = @_;
135 6 bless { TEXT => $match, NEG => $neg, QUANT => $q, NGREED => $ng }, $class;
136 }
137  
138 6 ▶sub text {
Subroutine text: called CC=2 SCAR=7.6
139 6 ▶ $_[0]{NEG} =~ /[pP]/ ?
Branch: 1 branch
BranchTrueFalseTotal
$_[0]{'NEG'} =~ /[pP]/ ? : 0 6 6
140 "\\$_[0]{NEG}\{$_[0]{TEXT}\}" :
141 "[$_[0]{NEG}$_[0]{TEXT}]"
142 }
143 0 ▶sub type { 'class' }
Subroutine type: not called CC=1 SCAR=6.9
144  
145  
146  
147 package YAPE::Regex::text;
148  
149 25 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
150 25 my ($class,$match,$q,$ng) = @_;
151 25 bless { TEXT => $match, QUANT => $q, NGREED => $ng }, $class;
152 }
153  
154 0 ▶sub type { 'text' }
Subroutine type: not called CC=1 SCAR=6.9
155  
156  
157  
158 package YAPE::Regex::alt;
159  
160 4 ▶sub new { bless { NGREED => "", QUANT => "" }, $_[0] }
Subroutine new: called CC=1 SCAR=0.0
161 0 ▶sub text { '' }
Subroutine text: not called CC=1 SCAR=6.9
162 3 ▶sub string { '|' }
Subroutine string: called CC=1 SCAR=0.0
163 0 ▶sub type { 'alt' }
Subroutine type: not called CC=1 SCAR=6.9
164  
165  
166  
167 package YAPE::Regex::comment;
168  
169 0 ▶sub new {
Subroutine new: not called CC=1 SCAR=6.9
170 0 my ($class,$text,$X) = @_;
171 0 bless { TEXT => $text, XCOMM => $X }, $class;
172 }
173  
174 0 ▶sub string { $_[0]{XCOMM} ? " # $_[0]{TEXT}" : "(?#$_[0]{TEXT})" }
Subroutine string: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
$_[0]{'XCOMM'} ? : 0 0 0
175 0 ▶sub xcomm { $_[0]{XCOMM} }
Subroutine xcomm: not called CC=1 SCAR=6.9
176 0 ▶sub type { 'comment' }
Subroutine type: not called CC=1 SCAR=6.9
177  
178  
179  
180 package YAPE::Regex::whitespace;
181  
182 0 ▶sub new {
Subroutine new: not called CC=1 SCAR=6.9
183 0 my ($class,$text) = @_;
184 0 bless { TEXT => $text }, $class;
185 }
186  
187 0 ▶sub type { 'whitespace' }
Subroutine type: not called CC=1 SCAR=6.9
188 0 ▶sub string { $_[0]{TEXT} }
Subroutine string: not called CC=1 SCAR=6.9
189  
190  
191  
192 package YAPE::Regex::flags;
193  
194 0 ▶sub new {
Subroutine new: not called CC=3 SCAR=24.8
195 0 my ($class,$add,$sub) = @_;
196 0 ▶ my %mode = map { $_ => 1 } split //, $add ||= "";
Condition0%0/2
$add ||= ""
l!l
00
MC/DC0%0/1
$add ||= ""
$add
Truth table0%0/2
A
A= $add
Aresult
11
00
197 0 ▶ delete @mode{split //, $sub ||= ""};
Condition0%0/2
$sub ||= ""
l!l
00
MC/DC0%0/1
$sub ||= ""
$sub
Truth table0%0/2
A
A= $sub
Aresult
11
00
198 0 $add = join "", sort split //, $add;
199 0 $sub = join "", sort split //, $sub;
200 0 bless { MODE => \%mode, ON => $add, OFF => $sub }, $class;
201 }
202  
203 0 ▶sub string { "(?$_[0]{ON}" . ($_[0]{OFF} && "-$_[0]{OFF}") . ')' }
Subroutine string: not called CC=2 SCAR=17.9
Condition0%0/2
$_[0]{'OFF'} && "-$_[0]{'OFF'}"
!ll
00
MC/DC0%0/1
$_[0]{'OFF'} && "-$_[0]{'OFF'}"
$_[0]{'OFF'}
Truth table0%0/2
A
A= $_[0]{'OFF'}
Aresult
00
11
204 0 ▶sub type { 'flags' }
Subroutine type: not called CC=1 SCAR=6.9
205  
206  
207  
208 package YAPE::Regex::cut;
209  
210 0 ▶sub new {
Subroutine new: not called CC=4 SCAR=30.0
211 0 ▶ bless {
Condition0%0/6
$_[1] || []
l!l
00
$_[2] || ''
l!l
00
$_[3] || ''
l!l
00
MC/DC0%0/1
$_[1] || []
$_[1]
MC/DC0%0/1
$_[2] || ''
$_[2]
MC/DC0%0/1
$_[3] || ''
$_[3]
Truth table0%0/2
A
A= $_[1]
Aresult
11
00
Truth table0%0/2
A
A= $_[2]
Aresult
11
00
Truth table0%0/2
A
A= $_[3]
Aresult
11
00
212 CONTENT => $_[1] || [],
213 QUANT => $_[2] || "",
214 NGREED => $_[3] || "",
215 }, $_[0]
216 }
217  
218 0 ▶sub fullstring {
Subroutine fullstring: not called CC=1 SCAR=6.9
219 join "",
220 $_[0]->string,
221 0 map($_->fullstring, @{ $_[0]{CONTENT} }),
222 ")$_[0]{QUANT}$_[0]{NGREED}"
223 }
224  
225 0 ▶sub string { '(?>' }
Subroutine string: not called CC=1 SCAR=6.9
226 0 ▶sub type { 'cut' }
Subroutine type: not called CC=1 SCAR=6.9
227  
228  
229  
230 package YAPE::Regex::lookahead;
231  
232 3 ▶sub new { bless { POS => $_[1], CONTENT => $_[2] || [] }, $_[0] }
Subroutine new: called CC=2 SCAR=7.6
Condition50%1/2
$_[2] || []
l!l
03
MC/DC0%0/1
$_[2] || []
$_[2]
Truth table50%1/2
A
A= $_[2]
Aresult
11
00
233  
234 3 ▶sub fullstring {
Subroutine fullstring: called CC=1 SCAR=0.0
235 join "",
236 $_[0]->string,
237 3 map($_->fullstring, @{ $_[0]{CONTENT} }),
238 ')'
239 }
240  
241 3 ▶sub string { '(?' . ('!','=')[$_[0]{POS}] }
Subroutine string: called CC=1 SCAR=0.0
242 4 ▶sub type { 'lookahead' }
Subroutine type: called CC=1 SCAR=0.0
243 0 ▶sub pos { $_[0]{POS} }
Subroutine pos: not called CC=1 SCAR=6.9
244  
245  
246  
247 package YAPE::Regex::lookbehind;
248  
249 3 ▶sub new { bless { POS => $_[1], CONTENT => $_[2] || [] }, $_[0] }
Subroutine new: called CC=2 SCAR=7.6
Condition50%1/2
$_[2] || []
l!l
03
MC/DC0%0/1
$_[2] || []
$_[2]
Truth table50%1/2
A
A= $_[2]
Aresult
11
00
250  
251 3 ▶sub fullstring {
Subroutine fullstring: called CC=1 SCAR=0.0
252 join "",
253 $_[0]->string,
254 3 map($_->fullstring, @{ $_[0]{CONTENT} }),
255 ')'
256 }
257  
258 3 ▶sub string { '(?<' . ('!','=')[$_[0]{POS}] }
Subroutine string: called CC=1 SCAR=0.0
259 0 ▶sub type { 'lookbehind' }
Subroutine type: not called CC=1 SCAR=6.9
260 0 ▶sub pos { $_[0]{POS} }
Subroutine pos: not called CC=1 SCAR=6.9
261  
262  
263  
264 package YAPE::Regex::conditional;
265  
266 7 ▶sub new {
Subroutine new: called CC=6 SCAR=20.5
267 7 ▶ bless {
Condition60%6/10
$_[1] || []
l!l
16
$_[2] || []
l!l
07
$_[3] || []
l!l
07
$_[4] || ''
l!l
07
$_[5] || ''
l!l
07
MC/DC100%1/1
$_[1] || []
$_[1]
MC/DC0%0/1
$_[2] || []
$_[2]
MC/DC0%0/1
$_[3] || []
$_[3]
MC/DC0%0/1
$_[4] || ''
$_[4]
MC/DC0%0/1
$_[5] || ''
$_[5]
Truth table100%2/2
A
A= $_[1]
Aresult
11
00
Truth table50%1/2
A
A= $_[2]
Aresult
11
00
Truth table50%1/2
A
A= $_[3]
Aresult
11
00
Truth table50%1/2
A
A= $_[4]
Aresult
11
00
Truth table50%1/2
A
A= $_[5]
Aresult
11
00
268 OPTS => 1,
269 CONTENT => $_[1] || [],
270 TRUE => $_[2] || [],
271 FALSE => $_[3] || [],
272 QUANT => $_[4] || "",
273 NGREED => $_[5] || "",
274 }, $_[0];
275 }
276  
277 7 ▶sub fullstring {
Subroutine fullstring: called CC=2 SCAR=6.9
278 join "",
279 $_[0]->string,
280 7 ▶ map($_->fullstring, @{ $_[0]{TRUE} }),
Branch: 1 branch
BranchTrueFalseTotal
$_[0]{'OPTS'} == 2 ? : 1 6 7
281 $_[0]{OPTS} == 2 ? (
282 7 '|', map($_->fullstring, @{ $_[0]{FALSE} }),
283 ) : (),
284 ")$_[0]{QUANT}$_[0]{NGREED}";
285 }
286  
287 7 ▶sub string {
Subroutine string: called CC=2 SCAR=6.9
288 '(?' . (ref $_[0]{CONTENT} ?
289 7 ▶ $_[0]{CONTENT}[0]->fullstring :
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0]{'CONTENT'} ? : 6 1 7
290 "($_[0]{CONTENT})"
291 )
292 }
293 0 ▶sub backref { $_[0]{CONTENT} }
Subroutine backref: not called CC=1 SCAR=6.9
294 8 ▶sub type { 'cond' }
Subroutine type: called CC=1 SCAR=0.0
295  
296  
297  
298 package YAPE::Regex::group;
299  
300 13 ▶sub new {
Subroutine new: called CC=6 SCAR=18.6
301 13 ▶ my $on = join "", sort split //, $_[1] || "";
Condition100%2/2
$_[1] || ''
l!l
112
MC/DC100%1/1
$_[1] || ''
$_[1]
Truth table100%2/2
A
A= $_[1]
Aresult
11
00
302 13 ▶ my $off = join "", sort split //, $_[2] || "";
Condition100%2/2
$_[2] || ''
l!l
121
MC/DC100%1/1
$_[2] || ''
$_[2]
Truth table100%2/2
A
A= $_[2]
Aresult
11
00
303 13 ▶ bless {
Condition50%3/6
$_[3] || []
l!l
013
$_[4] || ''
l!l
013
$_[5] || ''
l!l
013
MC/DC0%0/1
$_[3] || []
$_[3]
MC/DC0%0/1
$_[4] || ''
$_[4]
MC/DC0%0/1
$_[5] || ''
$_[5]
Truth table50%1/2
A
A= $_[3]
Aresult
11
00
Truth table50%1/2
A
A= $_[4]
Aresult
11
00
Truth table50%1/2
A
A= $_[5]
Aresult
11
00
304 ON => $on,
305 OFF => $off,
306 CONTENT => $_[3] || [],
307 QUANT => $_[4] || "",
308 NGREED => $_[5] || "",
309 }, $_[0]
310 }
311  
312 11 ▶sub fullstring {
Subroutine fullstring: called CC=1 SCAR=0.0
313 join "",
314 $_[0]->string,
315 11 map($_->fullstring, @{ $_[0]{CONTENT} }),
316 ")$_[0]{QUANT}$_[0]{NGREED}"
317 }
318 11 ▶sub string { $_[0]{OFF} ? "(?$_[0]{ON}-$_[0]{OFF}:" : "(?$_[0]{ON}:" }
Subroutine string: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
$_[0]{'OFF'} ? : 10 1 11
319 12 ▶sub type { 'group' }
Subroutine type: called CC=1 SCAR=0.0
320  
321  
322  
323 package YAPE::Regex::capture;
324  
325 2 ▶sub new {
Subroutine new: called CC=4 SCAR=16.6
326 2 ▶ bless {
Condition50%3/6
$_[1] || []
l!l
02
$_[2] || ''
l!l
02
$_[3] || ''
l!l
02
MC/DC0%0/1
$_[1] || []
$_[1]
MC/DC0%0/1
$_[2] || ''
$_[2]
MC/DC0%0/1
$_[3] || ''
$_[3]
Truth table50%1/2
A
A= $_[1]
Aresult
11
00
Truth table50%1/2
A
A= $_[2]
Aresult
11
00
Truth table50%1/2
A
A= $_[3]
Aresult
11
00
327 CONTENT => $_[1] || [],
328 QUANT => $_[2] || "",
329 NGREED => $_[3] || "",
330 }, $_[0]
331 }
332  
333 2 ▶sub fullstring {
Subroutine fullstring: called CC=1 SCAR=0.0
334 join "",
335 $_[0]->string,
336 2 map($_->fullstring, @{ $_[0]{CONTENT} }),
337 ")$_[0]{QUANT}$_[0]{NGREED}"
338 }
339  
340 2 ▶sub string { '(' }
Subroutine string: called CC=1 SCAR=0.0
341 4 ▶sub type { 'capture' }
Subroutine type: called CC=1 SCAR=0.0
342  
343  
344  
345 package YAPE::Regex::code;
346  
347 2 ▶sub new { bless { CONTENT => $_[1], QUANT => "", NGREED => "", }, $_[0] }
Subroutine new: called CC=1 SCAR=0.0
348 2 ▶sub text { "(?$_[0]{CONTENT})" }
Subroutine text: called CC=1 SCAR=0.0
349 0 ▶sub type { 'code' }
Subroutine type: not called CC=1 SCAR=6.9
350  
351  
352  
353 package YAPE::Regex::later;
354  
355 2 ▶sub new { bless { CONTENT => $_[1], QUANT => "", NGREED => "", }, $_[0] }
Subroutine new: called CC=1 SCAR=0.0
356 2 ▶sub text { "(??$_[0]{CONTENT})" }
Subroutine text: called CC=1 SCAR=0.0
357 0 ▶sub type { 'later' }
Subroutine type: not called CC=1 SCAR=6.9
358  
359  
360  
361 package YAPE::Regex::close;
362  
363 30 ▶sub new { bless { QUANT => $_[1] || "", NGREED => $_[2] || "" }, $_[0] }
Subroutine new: called CC=3 SCAR=12.7
Condition50%2/4
$_[1] || ''
l!l
030
$_[2] || ''
l!l
030
MC/DC0%0/1
$_[1] || ''
$_[1]
MC/DC0%0/1
$_[2] || ''
$_[2]
Truth table50%1/2
A
A= $_[1]
Aresult
11
00
Truth table50%1/2
A
A= $_[2]
Aresult
11
00
364 0 ▶sub string { ")$_[0]{QUANT}$_[0]{NGREED}" }
Subroutine string: not called CC=1 SCAR=6.9
365 0 ▶sub type { 'close' }
Subroutine type: not called CC=1 SCAR=6.9
366  
367  
368 1 1;
369  
370  
371 =head1 NAME
372  
373 YAPE::Regex::Element - sub-classes for YAPE::Regex elements
374  
375 =head1 VERSION
376  
377 This document refers to YAPE::Regex::Element version 4.00.
378  
379 =head1 SYNOPSIS
380  
381 use YAPE::Regex 'MyExt::Mod';
382 # this sets up inheritence in MyExt::Mod
383 # see YAPE::Regex documentation
384  
385 =head1 C<YAPE> MODULES
386  
387 The C<YAPE> hierarchy of modules is an attempt at a unified means of parsing
388 and extracting content. It attempts to maintain a generic interface, to
389 promote simplicity and reusability. The API is powerful, yet simple. The
390 modules do tokenization (which can be intercepted) and build trees, so that
391 extraction of specific nodes is doable.
392  
393 =head1 DESCRIPTION
394  
395 This module provides the classes for the C<YAPE::Regex> objects. The base
396 class for these objects is C<YAPE::Regex::Element>. The objects classes are
397 numerous.
398  
399 =head2 Methods for C<YAPE::Regex::Element>
400  
401 This class contains fallback methods for the other classes.
402  
403 =over 4
404  
405 =item * C<my $str = $obj-E<gt>text;>
406  
407 Returns a string representation of the content of the regex node I<itself>, not
408 any nodes contained in it. This is C<undef> for non-text nodes.
409  
410 =item * C<my $str = $obj-E<gt>string;>
411  
412 Returns a string representation of the regex node I<itself>, not any nodes
413 contained in it.
414  
415 =item * C<my $str = $obj-E<gt>fullstring;>
416  
417 Returns a string representation of the regex node, including any nodes contained
418 in it.
419  
420 =item * C<my $quant = $obj-E<gt>quant;>
421  
422 Returns a string with the quantity, and a C<?> if the node is non-greedy. The
423 quantity is one of C<*>, C<+>, C<?>, C<{I<M>,I<N>}>, or an empty string.
424  
425 =item * C<my $ng = $obj-E<gt>ngreed;>
426  
427 Returns a C<?> if the node is non-greedy, and an empty string otherwise.
428  
429 =back
430  
431 =head2 Methods for C<YAPE::Regex::anchor>
432  
433 This class represents anchors. Objects have the following methods:
434  
435 =over 4
436  
437 =item * C<my $anchor = YAPE::Regex::anchor-E<gt>new($type,$q,$ng);>
438  
439 Creates a C<YAPE::Regex::anchor> object. Takes three arguments: the anchor
440 (C<^>, C<\A>, C<$>, C<\Z>, C<\z>, C<\B>, C<\b>, or C<\G>), the quantity, and
441 the non-greedy flag. The quantity I<should> be an empty string.
442  
443 my $anc = YAPE::Regex::anchor->new('\A', '', '?');
444 # /\A?/
445  
446 =item * C<my $type = $anchor-E<gt>type;>
447  
448 Returns the string C<anchor>.
449  
450 =back
451  
452 =head2 Methods for C<YAPE::Regex::macro>
453  
454 This class represents character-class macros. Objects have the following
455 methods:
456  
457 =over 4
458  
459 =item * C<my $macro = YAPE::Regex::macro-E<gt>new($type,$q,$ng);>
460  
461 Creates a C<YAPE::Regex::macro> object. Takes three arguments: the macro
462 (C<w>, C<W>, C<d>, C<D>, C<s>, or C<S>), the quantity, and the non-greedy
463 flag.
464  
465 my $macro = YAPE::Regex::macro->new('s', '{3,5}');
466 # /\s{3,5}/
467  
468 =item * C<my $text = $macro-E<gt>text;>
469  
470 Returns the macro.
471  
472 print $macro->text; # '\s'
473  
474 =item * C<my $type = $macro-E<gt>type;>
475  
476 Returns the string C<macro>.
477  
478 =back
479  
480 =head2 Methods for C<YAPE::Regex::oct>
481  
482 This class represents octal escapes. Objects have the following methods:
483  
484 =over 4
485  
486 =item * C<my $oct = YAPE::Regex::oct-E<gt>new($type,$q,$ng);>
487  
488 Creates a C<YAPE::Regex::oct> object. Takes three arguments: the octal number
489 (as a string), the quantity, and the non-greedy flag.
490  
491 my $oct = YAPE::Regex::oct->new('040');
492 # /\040/
493  
494 =item * C<my $text = $oct-E<gt>text;>
495  
496 Returns the octal escape.
497  
498 print $oct->text; # '\040'
499  
500 =item * C<my $type = $oct-E<gt>type;>
501  
502 Returns the string C<oct>.
503  
504 =back
505  
506 =head2 Methods for C<YAPE::Regex::hex>
507  
508 This class represents hexadecimal escapes. Objects have the following methods:
509  
510 =over 4
511  
512 =item * C<my $hex = YAPE::Regex::hex-E<gt>new($type,$q,$ng);>
513  
514 Creates a C<YAPE::Regex::hex> object. Takes three arguments: the hexadecimal
515 number (as a string), the quantity, and the non-greedy flag.
516  
517 my $hex = YAPE::Regex::hex->new('20','{2,}');
518 # /\x20{2,}/
519  
520 =item * C<my $text = $hex-E<gt>text;>
521  
522 Returns the hexadecimal escape.
523  
524 print $hex->text; # '\x20'
525  
526 =item * C<my $type = $hex-E<gt>type;>
527  
528 Returns the string C<hex>.
529  
530 =back
531  
532 =head2 Methods for C<YAPE::Regex::utf8hex>
533  
534 This class represents UTF hexadecimal escapes. Objects have the following
535 methods:
536  
537 =over 4
538  
539 =item * C<my $hex = YAPE::Regex::utf8hex-E<gt>new($type,$q,$ng);>
540  
541 Creates a C<YAPE::Regex::utf8hex> object. Takes three arguments: the
542 hexadecimal number (as a string), the quantity, and the non-greedy flag.
543  
544 my $utf8hex = YAPE::Regex::utf8hex->new('beef','{0,4}');
545 # /\x{beef}{2,}/
546  
547 =item * C<my $text = $utf8hex-E<gt>text;>
548  
549 Returns the hexadecimal escape.
550  
551 print $utf8hex->text; # '\x{beef}'
552  
553 =item * C<my $type = $utf8hex-E<gt>type;>
554  
555 Returns the string C<utf8hex>.
556  
557 =back
558  
559 =head2 Methods for C<YAPE::Regex::backref>
560  
561 This class represents back-references. Objects have the following methods:
562  
563 =over 4
564  
565 =item * C<my $bref = YAPE::Regex::bref-E<gt>new($type,$q,$ng);>
566  
567 Creates a C<YAPE::Regex::bref> object. Takes three arguments: the number of
568 the back-reference, the quantity, and the non-greedy flag.
569  
570 my $bref = YAPE::Regex::bref->new(2,'','?');
571 # /\2?/
572  
573 =item * C<my $text = $bref-E<gt>text;>
574  
575 Returns the backescape.
576  
577 print $bref->text; # '\2'
578  
579 =item * C<my $type = $bref-E<gt>type;>
580  
581 Returns the string C<backref>.
582  
583 =back
584  
585 =head2 Methods for C<YAPE::Regex::ctrl>
586  
587 This class represents control character escapes. Objects have the following
588 methods:
589  
590 =over 4
591  
592 =item * C<my $ctrl = YAPE::Regex::ctrl-E<gt>new($type,$q,$ng);>
593  
594 Creates a C<YAPE::Regex::ctrl> object. Takes three arguments: the control
595 character, the quantity, and the non-greedy flag.
596  
597 my $ctrl = YAPE::Regex::ctrl->new('M');
598 # /\cM/
599  
600 =item * C<my $text = $ctrl-E<gt>text;>
601  
602 Returns the control character escape.
603  
604 print $ctrl->text; # '\cM'
605  
606 =item * C<my $type = $ctrl-E<gt>type;>
607  
608 Returns the string C<ctrl>.
609  
610 =back
611  
612 =head2 Methods for C<YAPE::Regex::named>
613  
614 This class represents named characters. Objects have the following methods:
615  
616 =over 4
617  
618 =item * C<my $ctrl = YAPE::Regex::named-E<gt>new($type,$q,$ng);>
619  
620 Creates a C<YAPE::Regex::named> object. Takes three arguments: the name of the
621 character, the quantity, and the non-greedy flag.
622  
623 my $named = YAPE::Regex::named->new('GREEK SMALL LETTER BETA');
624 # /\N{GREEK SMALL LETTER BETA}/
625  
626 =item * C<my $text = $named-E<gt>text;>
627  
628 Returns the character escape text.
629  
630 print $named->text; # '\N{GREEK SMALL LETTER BETA}'
631  
632 =item * C<my $type = $named-E<gt>type;>
633  
634 Returns the string C<named>.
635  
636 =back
637  
638 =head2 Methods for C<YAPE::Regex::Cchar>
639  
640 This class represents C characters. Objects have the following methods:
641  
642 =over 4
643  
644 =item * C<my $ctrl = YAPE::Regex::Cchar-E<gt>new($q,$ng);>
645  
646 Creates a C<YAPE::Regex::Cchar> object. Takes two arguments: the quantity and
647 the non-greedy flag.
648  
649 my $named = YAPE::Regex::Char->new(2);
650 # /\C{2}/
651  
652 =item * C<my $text = $Cchar-E<gt>text;>
653  
654 Returns the escape sequence.
655  
656 print $Cchar->text; # '\C'
657  
658 =item * C<my $type = $Cchar-E<gt>type;>
659  
660 Returns the string C<Cchar>.
661  
662 =back
663  
664 =head2 Methods for C<YAPE::Regex::slash>
665  
666 This class represents any other escaped characters. Objects have the following
667 methods:
668  
669 =over 4
670  
671 =item * C<my $slash = YAPE::Regex::slash-E<gt>new($type,$q,$ng);>
672  
673 Creates a C<YAPE::Regex::slash> object. Takes three arguments: the backslashed
674 character, the quantity, and the non-greedy flag.
675  
676 my $slash = YAPE::Regex::slash->new('t','','?');
677 # /\t?/
678  
679 =item * C<my $text = $slash-E<gt>text;>
680  
681 Returns the escaped character.
682  
683 print $slash->text; # '\t'
684  
685 =item * C<my $type = $slash-E<gt>type;>
686  
687 Returns the string C<slash>.
688  
689 =back
690  
691 =head2 Methods for C<YAPE::Regex::any>
692  
693 This class represents the dot metacharacter. Objects have the following methods:
694  
695 =over 4
696  
697 =item * C<my $any = YAPE::Regex::any-E<gt>new($q,$ng);>
698  
699 Creates a C<YAPE::Regex::any> object. Takes two arguments: the quantity, and
700 the non-greedy flag.
701  
702 my $any = YAPE::Regex::any->new('{1,3}');
703 # /.{1,3}/
704  
705 =item * C<my $type = $any-E<gt>type;>
706  
707 Returns the string C<any>.
708  
709 =back
710  
711 =head2 Methods for C<YAPE::Regex::class>
712  
713 This class represents character classes. Objects have the following methods:
714  
715 =over 4
716  
717 =item * C<my $class = YAPE::Regex::class-E<gt>new($chars,$neg,$q,$ng);>
718  
719 Creates a C<YAPE::Regex::class> object. Takes four arguments: the characters
720 in the class, a C<^> if the class is negated (an empty string otherwise), the
721 quantity, and the non-greedy flag.
722  
723 my $class = YAPE::Regex::class->new('aeiouy','^');
724 # /[^aeiouy]/
725  
726 =item * C<my $text = $class-E<gt>text;>
727  
728 Returns the character class.
729  
730 print $class->text; # [^aeiouy]
731  
732 =item * C<my $type = $class-E<gt>type;>
733  
734 Returns the string C<class>.
735  
736 =back
737  
738 =head2 Methods for C<YAPE::Regex::hex>
739  
740 This class represents hexadecimal escapes. Objects have the following methods:
741  
742 =over 4
743  
744 =item * C<my $text = YAPE::Regex::text-E<gt>new($text,$q,$ng);>
745  
746 Creates a C<YAPE::Regex::text> object. Takes three arguments: the text, the
747 quantity, and the non-greedy flag. The quantity and non-greedy modifier should
748 only be present for I<single-character> text, because of the way the parser
749 renders the quantity and non-greedy modifier.
750  
751 my $text = YAPE::Regex::text->new('alphabet','');
752 # /alphabet/
753
754 my $text = YAPE::Regex::text->new('x','?','?');
755 # /x??/
756  
757 =item * C<my $type = $text-E<gt>type;>
758  
759 Returns the string C<text>.
760  
761 =back
762  
763 =head2 Methods for C<YAPE::Regex::alt>
764  
765 This class represents alternation. Objects have the following methods:
766  
767 =over 4
768  
769 =item * C<my $alt = YAPE::Regex::alt-E<gt>new;>
770  
771 Creates a C<YAPE::Regex::alt> object.
772  
773 my $alt = YAPE::Regex::alt->new;
774 # /|/
775  
776 =item * C<my $type = $oct-E<gt>type;>
777  
778 Returns the string C<alt>.
779  
780 =back
781  
782 =head2 Methods for C<YAPE::Regex::comment>
783  
784 This class represents in-line comments. Objects have the following methods:
785  
786 =over 4
787  
788 =item * C<my $comment = YAPE::Regex::comment-E<gt>new($comment,$x);>
789  
790 Creates a C<YAPE::Regex::comment> object. Takes two arguments: the text of the
791 comment, and whether or not the C</x> regex modifier is in effect for this
792 comment. Note that Perl's regex engine will stop a C<(?#...)> comment at the
793 first C<)>, regardless of what you do.
794  
795 my $comment = YAPE::Regex::comment->new(
796 "match an optional string of digits"
797 );
798 # /(?#match an optional string of digits)/
799  
800 my $comment = YAPE::Regex::comment->new(
801 "match an optional string of digits",
802 1
803 );
804 # /# match an optional string of digits/
805  
806 =item * C<my $type = $comment-E<gt>type;>
807  
808 Returns the string C<comment>.
809  
810 =item * C<my $x_on = $comment-E<gt>xcomm;>
811  
812 Returns true or false, depending on whether the comment is under the C</x> regex
813 modifier.
814  
815 =back
816  
817 =head2 Methods for C<YAPE::Regex::whitespace>
818  
819 This class represents whitespace under the C</x> regex modifier. Objects have
820 the following methods:
821  
822 =over 4
823  
824 =item * C<my $ws = YAPE::Regex::whitespace-E<gt>new($text);>
825  
826 Creates a C<YAPE::Regex::whitespace> object. Takes one argument: the text of
827 the whitespace.
828  
829 my $ws = YAPE::Regex::whitespace->new(' ');
830 # / /x
831  
832 =item * C<my $text = $ws-E<gt>text;>
833  
834 Returns the whitespace.
835  
836 print $ws->text; # ' '
837  
838 =item * C<my $type = $ws-E<gt>type;>
839  
840 Returns the string C<whitespace>.
841  
842 =back
843  
844 =head2 Methods for C<YAPE::Regex::flags>
845  
846 This class represents C<(?ismx)> flags. Objects have the following methods:
847  
848 =over 4
849  
850 =item * C<my $flags = YAPE::Regex::flags-E<gt>new($add,$sub);>
851  
852 Creates a C<YAPE::Regex::flags> object. Takes two arguments: a string of the
853 modes to have on, and a string of the modes to explicitly turn off. The flags
854 are displayed in alphabetical order.
855  
856 my $flags = YAPE::Regex::flags->new('is','m');
857 # /(?is-m)/
858  
859 =item * C<my $type = $flags-E<gt>type;>
860  
861 Returns the string C<flags>.
862  
863 =back
864  
865 =head2 Methods for C<YAPE::Regex::cut>
866  
867 This class represents the cut assertion. Objects have the following methods:
868  
869 =over 4
870  
871 =item * C<my $look = YAPE::Regex::cut-E<gt>new(\@nodes);>
872  
873 Creates a C<YAPE::Regex::cut> object. Takes one arguments: a reference to an
874 array of objects to be contained in the cut.
875  
876 my $REx = YAPE::Regex::class->new('aeiouy','','+');
877 my $look = YAPE::Regex::cut->new(0,[$REx]);
878 # /(?>[aeiouy]+)/
879  
880 =item * C<my $type = $cut-E<gt>type;>
881  
882 Returns the string C<cut>.
883  
884 =back
885  
886 =head2 Methods for C<YAPE::Regex::lookahead>
887  
888 This class represents lookaheads. Objects have the following methods:
889  
890 =over 4
891  
892 =item * C<my $look = YAPE::Regex::lookahead-E<gt>new($pos,\@nodes);>
893  
894 Creates a C<YAPE::Regex::lookahead> object. Takes two arguments: a boolean
895 value indicating whether or not the lookahead is positive, and a reference to an
896 array of objects to be contained in the lookahead.
897  
898 my $REx = YAPE::Regex::class->new('aeiouy');
899 my $look = YAPE::Regex::lookahead->new(0,[$REx]);
900 # /(?![aeiouy])/
901  
902 =item * C<my $pos = $look-E<gt>pos;>
903  
904 Returns true if the lookahead is positive.
905  
906 print $look->pos ? 'pos' : 'neg'; # 'neg'
907  
908 =item * C<my $type = $look-E<gt>type;>
909  
910 Returns the string C<lookahead(pos)> or C<lookahead(neg)>.
911  
912 =back
913  
914 =head2 Methods for C<YAPE::Regex::lookbehind>
915  
916 This class represents lookbehinds. Objects have the following methods:
917  
918 =over 4
919  
920 =item * C<my $look = YAPE::Regex::lookbehind-E<gt>new($pos,\@nodes);>
921  
922 Creates a C<YAPE::Regex::lookbehind> object. Takes two arguments: a boolean
923 value indicating whether or not the lookbehind is positive, and a reference to
924 an array of objects to be contained in the lookbehind.
925  
926 my $REx = YAPE::Regex::class->new('aeiouy','^');
927 my $look = YAPE::Regex::lookbehind->new(1,[$REx]);
928 # /(?<=[^aeiouy])/
929  
930 =item * C<my $pos = $look-E<gt>pos;>
931  
932 Returns true if the lookbehind is positive.
933  
934 print $look->pos ? 'pos' : 'neg'; # 'pos'
935  
936 =item * C<my $type = $look-E<gt>type;>
937  
938 Returns the string C<lookbehind(pos)> or C<lookbehind(neg)>.
939  
940 =back
941  
942 =head2 Methods for C<YAPE::Regex::conditional>
943  
944 This class represents conditionals. Objects have the following methods:
945  
946 =over 4
947  
948 =item * C<my $cond = YAPE::Regex::conditional-E<gt>new($br,$t,$f,$q,$ng);>
949  
950 Creates a C<YAPE::Regex::hex> object. Takes five arguments: the number of the
951 back-reference (that's all that's supported in the current version), an array
952 reference to the "true" pattern, an array reference to the "false" pattern, and
953 the quantity and non-greedy flag.
954  
955 my $cond = YAPE::Regex::conditional->new(
956 2,
957 [],
958 [ YAPE::Regex::text->new('foo') ],
959 '?',
960 );
961 # /(?(2)|foo)?/
962  
963 =item * C<my $br = $cond-E<gt>backref;>
964  
965 Returns the number of the back-reference the conditional depends on.
966  
967 print $br->backref; # 2
968  
969 =item * C<my $type = $cond-E<gt>type;>
970  
971 Returns the string C<conditional(I<N>)>, where I<N> is the number of the
972 back-reference.
973  
974 =back
975  
976 =head2 Methods for C<YAPE::Regex::group>
977  
978 This class represents non-capturing groups. Objects have the following methods:
979  
980 =over 4
981  
982 =item * C<my $group = YAPE::Regex::group-E<gt>new($on,$off,\@nodes,$q,$ng);>
983  
984 Creates a C<YAPE::Regex::group> object. Takes five arguments: the modes turned
985 on, the modes explicitly turned off, a reference to an array of objects in the
986 group, the quantity, and the non-greedy flag. The modes are displayed in
987 alphabetical order.
988  
989 my $group = YAPE::Regex::group->new(
990 'i',
991 's',
992 [
993 YAPE::Regex::macro->new('d', '{2}'),
994 YAPE::Regex::macro->new('s'),
995 YAPE::Regex::macro->new('d', '{2}'),
996 ],
997 '?',
998 );
999 # /(?i-s:\d{2}\s\d{2})?/
1000  
1001 =item * C<my $type = $group-E<gt>type;>
1002  
1003 Returns the string C<group>.
1004  
1005 =back
1006  
1007 =head2 Methods for C<YAPE::Regex::capture>
1008  
1009 This class represents capturing groups. Objects have the following methods:
1010  
1011 =over 4
1012  
1013 =item * C<my $capture = YAPE::Regex::capture-E<gt>new(\@nodes,$q,$ng);>
1014  
1015 Creates a C<YAPE::Regex::capture> object. Takes three arguments: a reference
1016 to an array of objects in the group, the quantity, and the non-greedy flag.
1017  
1018 my $capture = YAPE::Regex::capture->new(
1019 [
1020 YAPE::Regex::macro->new('d', '{2}'),
1021 YAPE::Regex::macro->new('s'),
1022 YAPE::Regex::macro->new('d', '{2}'),
1023 ],
1024 );
1025 # /(\d{2}\s\d{2})/
1026  
1027 =item * C<my $type = $capture-E<gt>type;>
1028  
1029 Returns the string C<capture>.
1030  
1031 =back
1032  
1033 =head2 Methods for C<YAPE::Regex::code>
1034  
1035 This class represents code blocks. Objects have the following methods:
1036  
1037 =over 4
1038  
1039 =item * C<my $code = YAPE::Regex::code-E<gt>new($block);>
1040  
1041 Creates a C<YAPE::Regex::code> object. Takes one arguments: a string holding
1042 a block of code.
1043  
1044 my $code = YAPE::Regex::code->new(q({ push @poss, $1 }));
1045 # /(?{ push @poss, $1 })/
1046  
1047 =item * C<my $type = $code-E<gt>type;>
1048  
1049 Returns the string C<code>.
1050  
1051 =back
1052  
1053 =head2 Methods for C<YAPE::Regex::later>
1054  
1055 This class represents closed parentheses. Objects have the following methods:
1056  
1057 =over 4
1058  
1059 =item * C<my $later = YAPE::Regex::later-E<gt>new($block);>
1060  
1061 Creates a C<YAPE::Regex::later> object. Takes one arguments: a string holding
1062 a block of code.
1063  
1064 my $later = YAPE::Regex::later->new(q({ push @poss, $1 }));
1065 # /(?{{ push @poss, $1 }})/
1066  
1067 =item * C<my $type = $later-E<gt>type;>
1068  
1069 Returns the string C<later>.
1070  
1071 =back
1072  
1073 =head2 Methods for C<YAPE::Regex::close>
1074  
1075 This class represents closed parentheses. Objects have the following methods:
1076  
1077 =over 4
1078  
1079 =item * C<my $close = YAPE::Regex::close-E<gt>new($q,$ng);>
1080  
1081 Creates a C<YAPE::Regex::close> object. Takes two arguments: the quantity, and
1082 the non-greedy flag. This object is never needed in the tree; however, they are
1083 returned in the parsing stage, so that you know when they've been reached.
1084  
1085 my $close = YAPE::Regex::close->new('?','?');
1086 # /)??/
1087  
1088 =item * C<my $type = $close-E<gt>type;>
1089  
1090 Returns the string C<close>.
1091  
1092 =back
1093  
1094 =head1 TO DO
1095  
1096 This is a listing of things to add to future versions of this module.
1097  
1098 =over 4
1099  
1100 =item * None!
1101  
1102 =back
1103  
1104 =head1 BUGS
1105  
1106 Following is a list of known or reported bugs.
1107  
1108 =over 4
1109  
1110 =item * This documentation might be incomplete.
1111  
1112 =back
1113  
1114 =head1 SUPPORT
1115  
1116 Visit C<YAPE>'s web site at F<http://www.pobox.com/~japhy/YAPE/>.
1117  
1118 =head1 SEE ALSO
1119  
1120 The C<YAPE::Regex> documentation, for information on the main class.
1121  
1122 =head1 AUTHOR
1123  
1124 The original author is Jeff "japhy" Pinyan (CPAN ID: PINYAN).
1125  
1126 Gene Sullivan (gsullivan@cpan.org) is a co-maintainer.
1127  
1128 =head1 LICENSE
1129  
1130 This module is free software; you can redistribute it and/or modify
1131 it under the same terms as Perl itself. See L<perlartistic>.
1132  
1133 =cut
« Regex.pm ↑ Summary