Regexp/Parser/Objects.pm

filter: Statementstmt 75.0% 647 / 862 Branchbran 49.5% 117 / 236 Conditioncond 64.8% 48 / 74 MC/DCmcdc 45.4% 20 / 44 Subroutinesub 78.0% 178 / 228 Podpod n/a totaltotal 69.9% 1010 / 1444 CC 147 SCAR 20.2
CC
147
Cov
69%
insert
90.0
merge
30.0
insert
20.9
CRAP 7.5
« Perl6/Rule/Parser.pm ↑ Summary Regexp/Parser/Handlers.pm »
1 {
2 package Regexp::Parser::__object__;
3  
4 0 ▶ sub class {
Subroutine class: not called CC=1 SCAR=6.9
5 0 my $self = shift;
6 0 Carp::carp("class() deprecated; use family() instead");
7 0 $self->family(@_);
8 }
9  
10 0 ▶ sub flags {
Subroutine flags: not called CC=1 SCAR=6.9
11 0 my $self = shift;
12 0 $self->{flags};
13 }
14  
15 844 ▶ sub family {
Subroutine family: called CC=1 SCAR=0.0
16 844 my $self = shift;
17 844 $self->{family};
18 }
19  
20 284 ▶ sub type {
Subroutine type: called CC=1 SCAR=0.0
21 284 my $self = shift;
22 284 $self->{type};
23 }
24  
25 108 ▶ sub qr {
Subroutine qr: called CC=1 SCAR=0.0
26 108 my $self = shift;
27 108 $self->visual(@_);
28 }
29  
30 269 ▶ sub visual {
Subroutine visual: called CC=2 SCAR=6.9
31 269 my $self = shift;
32 269 ▶ exists $self->{vis} ? $self->{vis} : '';
Branch: 1 branch
BranchTrueFalseTotal
exists $self->{'vis'} ? : 247 22 269
33 }
34  
35 255 ▶ sub raw {
Subroutine raw: called CC=2 SCAR=7.2
36 255 my $self = shift;
37 255 ▶ exists $self->{raw} ? $self->{raw} : $self->visual(@_);
Branch: 1 branch
BranchTrueFalseTotal
exists $self->{'raw'} ? : 255 0 255
38 }
39  
40 74 ▶ sub data {
Subroutine data: called CC=1 SCAR=0.0
41 74 my $self = shift;
42 74 return $self->{data};
43 }
44  
45 16 ▶ sub ender {
Subroutine ender: called CC=2 SCAR=8.4
46 16 my $self = shift;
47 16 ▶ unless ($self->{down}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"down"}) 0 16 16
48 0 Carp::carp("ender() ignored for ", $self->family, "/", $self->type);
49 0 return;
50 }
51 16 [ 'tail' ];
52 }
53  
54 92 ▶ sub walk {
Subroutine walk: called CC=1 SCAR=0.0
55 92 my $self = shift;
56 92 return;
57 }
58  
59 1419 ▶ sub omit {
Subroutine omit: called CC=2 SCAR=6.9
60 1419 my $self = shift;
61 1419 ▶ $self->{omit} = shift if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 27 1392 1419
62 1419 $self->{omit};
63 }
64  
65 1133 ▶ sub insert {
Subroutine insert: called CC=2 SCAR=7.0
66 1133 my ($self, $tree) = @_;
67 1133 my $rx = $self->{rx};
68 1133 my $merged = 0;
69 1133 ▶ return if $self->omit;
Branch: 1 branch
BranchTrueFalseTotal
if $self->omit 0 1133 1133
70 1133 push @$tree, $self;
71 1133 $self->merge;
72 }
73  
74 307 ▶ sub merge {
Subroutine merge: called CC=1 SCAR=0.0
75 307 my ($self) = @_;
76 307 return;
77 }
78 }
79  
80  
81 {
82 # \A ^ \B \b \G \Z \z $
83 19 package Regexp::Parser::anchor;
84 19 our @ISA = qw( Regexp::Parser::__object__ );
85 19 push @Regexp::Parser::bol::ISA, __PACKAGE__;
86 19 push @Regexp::Parser::bound::ISA, __PACKAGE__;
87 19 push @Regexp::Parser::gpos::ISA, __PACKAGE__;
88 19 push @Regexp::Parser::eol::ISA, __PACKAGE__;
89  
90 67 ▶ sub new {
Subroutine new: called CC=3 SCAR=11.0
91 67 my ($class, $rx, $type, $vis, $boundary_type) = @_;
92 67 ▶ Carp::croak("anchor is an abstract class") if $class =~ /::anchor$/;
Branch: 1 branch
BranchTrueFalseTotal
if $class =~ /::anchor$/ 0 67 67
93  
94 my $self = bless {
95 rx => $rx,
96 67 ▶ flags => $rx->{flags}[-1],
Branch: 1 branch
BranchTrueFalseTotal
$boundary_type ? : 27 40 67
97 family => 'anchor',
98 type => $type,
99 vis => $vis,
100 zerolen => 1,
101 ($boundary_type ? (boundary_type => $boundary_type) : ()),
102 }, $class;
103 67 return $self;
104 }
105  
106 13 ▶ sub boundary_type {
Subroutine boundary_type: called CC=1 SCAR=0.0
107 13 my $self = shift;
108 13 return $self->{boundary_type};
109 }
110 }
111  
112  
113 {
114 # . \C
115 19 package Regexp::Parser::reg_any;
116 19 our @ISA = qw( Regexp::Parser::__object__ );
117  
118 11 ▶ sub new {
Subroutine new: called CC=1 SCAR=0.0
119 11 my ($class, $rx, $type, $vis) = @_;
120 my $self = bless {
121 rx => $rx,
122 11 flags => $rx->{flags}[-1],
123 family => 'reg_any',
124 type => $type,
125 vis => $vis,
126 }, $class;
127 11 return $self;
128 }
129 }
130  
131  
132 {
133 # \w \W
134 19 package Regexp::Parser::alnum;
135 19 our @ISA = qw( Regexp::Parser::__object__ );
136  
137 25 ▶ sub new {
Subroutine new: called CC=1 SCAR=0.0
138 25 my ($class, $rx, $neg) = @_;
139 my $self = bless {
140 rx => $rx,
141 25 flags => $rx->{flags}[-1],
142 neg => $neg,
143 }, $class;
144 25 return $self;
145 }
146  
147 0 ▶ sub neg {
Subroutine neg: not called CC=2 SCAR=17.9
148 0 my $self = shift;
149 0 ▶ $self->{neg} = shift if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 0 0
150 0 $self->{neg};
151 }
152  
153 52 ▶ sub family { 'alnum' }
Subroutine family: called CC=1 SCAR=0.0
154  
155 3 ▶ sub type {
Subroutine type: called CC=2 SCAR=7.2
156 3 my $self = shift;
157 3 ▶ ($self->{neg} ? 'n' : '') . $self->family;
Branch: 1 branch
BranchTrueFalseTotal
$self->{'neg'} ? : 0 3 3
158 }
159  
160 23 ▶ sub visual {
Subroutine visual: called CC=2 SCAR=6.9
161 23 my $self = shift;
162 23 ▶ $self->{neg} ? '\W' : '\w';
Branch: 1 branch
BranchTrueFalseTotal
$self->{'neg'} ? : 4 19 23
163 }
164 }
165  
166  
167 {
168 # \s \S
169 19 package Regexp::Parser::space;
170 19 our @ISA = qw( Regexp::Parser::__object__ );
171  
172 16 ▶ sub new {
Subroutine new: called CC=1 SCAR=0.0
173 16 my ($class, $rx, $neg) = @_;
174 my $self = bless {
175 rx => $rx,
176 16 flags => $rx->{flags}[-1],
177 neg => $neg,
178 }, $class;
179 16 return $self;
180 }
181  
182 0 ▶ sub neg {
Subroutine neg: not called CC=2 SCAR=17.9
183 0 my $self = shift;
184 0 ▶ $self->{neg} = shift if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 0 0
185 0 $self->{neg};
186 }
187  
188 0 ▶ sub type {
Subroutine type: not called CC=2 SCAR=17.9
189 0 my $self = shift;
190 0 ▶ ($self->{neg} ? 'n' : '') . $self->family;
Branch: 1 branch
BranchTrueFalseTotal
$self->{'neg'} ? : 0 0 0
191 }
192  
193 32 ▶ sub family { 'space' }
Subroutine family: called CC=1 SCAR=0.0
194  
195 12 ▶ sub visual {
Subroutine visual: called CC=2 SCAR=6.9
196 12 my $self = shift;
197 12 ▶ $self->{neg} ? '\S' : '\s';
Branch: 1 branch
BranchTrueFalseTotal
$self->{'neg'} ? : 4 8 12
198 }
199 }
200  
201  
202 {
203 # \d \D
204 19 package Regexp::Parser::digit;
205 19 our @ISA = qw( Regexp::Parser::__object__ );
206  
207 29 ▶ sub new {
Subroutine new: called CC=1 SCAR=0.0
208 29 my ($class, $rx, $neg) = @_;
209 my $self = bless {
210 rx => $rx,
211 29 flags => $rx->{flags}[-1],
212 neg => $neg,
213 }, $class;
214 29 return $self;
215 }
216  
217 0 ▶ sub neg {
Subroutine neg: not called CC=2 SCAR=17.9
218 0 my $self = shift;
219 0 ▶ $self->{neg} = shift if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 0 0
220 0 $self->{neg};
221 }
222  
223 2 ▶ sub type {
Subroutine type: called CC=2 SCAR=7.2
224 2 my $self = shift;
225 2 ▶ ($self->{neg} ? 'n' : '') . $self->family;
Branch: 1 branch
BranchTrueFalseTotal
$self->{'neg'} ? : 0 2 2
226 }
227  
228 84 ▶ sub family { 'digit' }
Subroutine family: called CC=1 SCAR=0.0
229  
230 46 ▶ sub visual {
Subroutine visual: called CC=2 SCAR=6.9
231 46 my $self = shift;
232 46 ▶ $self->{neg} ? '\D' : '\d';
Branch: 1 branch
BranchTrueFalseTotal
$self->{'neg'} ? : 12 34 46
233 }
234 }
235  
236  
237 {
238 19 package Regexp::Parser::anyof;
239 19 our @ISA = qw( Regexp::Parser::__object__ );
240  
241 44 ▶ sub new {
Subroutine new: called CC=1 SCAR=0.0
242 44 my ($class, $rx, $neg, @data) = @_;
243 my $self = bless {
244 rx => $rx,
245 44 flags => $rx->{flags}[-1],
246 family => 'anyof',
247 type => 'anyof',
248 neg => $neg,
249 data => \@data,
250 down => 1,
251 }, $class;
252 44 return $self;
253 }
254  
255 0 ▶ sub qr {
Subroutine qr: not called CC=1 SCAR=6.9
256 0 my $self = shift;
257 0 join "", $self->raw, map($_->qr, @{ $self->{data} }), "]";
258 }
259  
260 47 ▶ sub visual {
Subroutine visual: called CC=1 SCAR=0.0
261 47 my $self = shift;
262 47 join "", $self->raw, map($_->visual, @{ $self->{data} }), "]";
263 }
264  
265 47 ▶ sub raw {
Subroutine raw: called CC=2 SCAR=6.9
266 47 my $self = shift;
267 47 ▶ join "", "[", $self->{neg} ? "^" : "";
Branch: 1 branch
BranchTrueFalseTotal
$self->{'neg'} ? : 4 43 47
268 }
269  
270 0 ▶ sub neg {
Subroutine neg: not called CC=2 SCAR=17.9
271 0 my $self = shift;
272 0 ▶ $self->{neg} = shift if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 0 0
273 0 $self->{neg};
274 }
275  
276 1 ▶ sub ender {
Subroutine ender: called CC=1 SCAR=0.0
277 1 my $self = shift;
278 1 [ 'anyof_close' ];
279 }
280  
281 0 ▶ sub data {
Subroutine data: not called CC=4 SCAR=30.0
282 0 my $self = shift;
283 0 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
284 0 my $how = shift;
285 0 ▶ if ($how eq '=') { $self->{data} = \@_ }
Branch: 2 branches
BranchTrueFalseTotal
if ($how eq '=') { } 0 0 0
elsif ($how eq '+') { } 0 0 0
286 0 elsif ($how eq '+') { push @{ $self->{data} }, @_ }
287 else {
288 0 my $t = $self->type;
289 0 Carp::croak("\$$t->data([+=], \@data)");
290 }
291 }
292 0 $self->{data};
293 }
294  
295 1 ▶ sub walk {
Subroutine walk: called CC=2 SCAR=7.0
296 1 my ($self, $ws, $d) = @_;
297 1 unshift @$ws, $self->{rx}->object(@{ $self->ender });
298 1 ▶ unshift @$ws, sub { -1 }, @{ $self->{data} }, sub { +1 } if $d;
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
BranchTrueFalseTotal
if $d 1 0 1
299 }
300  
301 44 ▶ sub insert {
Subroutine insert: called CC=1 SCAR=0.0
302 44 my ($self, $tree) = @_;
303 44 my $rx = $self->{rx};
304 44 push @$tree, $self;
305 44 push @{ $rx->{stack} }, $tree;
306 44 $rx->{tree} = $self->{data};
307 }
308 }
309  
310  
311 {
312 19 package Regexp::Parser::anyof_char;
313 19 our @ISA = qw( Regexp::Parser::__object__ );
314  
315 166 ▶ sub new {
Subroutine new: called CC=2 SCAR=6.9
316 166 my ($class, $rx, $data, $vis) = @_;
317 166 ▶ $vis = $data if not defined $vis;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $vis 102 64 166
318 my $self = bless {
319 rx => $rx,
320 166 flags => $rx->{flags}[-1],
321 family => 'anyof_char',
322 type => 'anyof_char',
323 data => $data,
324 vis => $vis,
325 }, $class;
326 }
327 }
328  
329  
330 {
331 19 package Regexp::Parser::anyof_range;
332 19 our @ISA = qw( Regexp::Parser::__object__ );
333  
334 10 ▶ sub new {
Subroutine new: called CC=1 SCAR=0.0
335 10 my ($class, $rx, $lhs, $rhs) = @_;
336 my $self = bless {
337 rx => $rx,
338 10 flags => $rx->{flags}[-1],
339 family => 'anyof_range',
340 type => 'anyof_range',
341 data => [$lhs, $rhs],
342 }, $class;
343 }
344  
345 0 ▶ sub qr {
Subroutine qr: not called CC=1 SCAR=6.9
346 0 my $self = shift;
347 0 join "-", $self->{data}[0]->qr, $self->{data}[1]->qr;
348 }
349  
350 15 ▶ sub visual {
Subroutine visual: called CC=1 SCAR=0.0
351 15 my $self = shift;
352 15 join "-", $self->{data}[0]->visual, $self->{data}[1]->visual;
353 }
354 }
355  
356  
357 {
358 19 package Regexp::Parser::anyof_class;
359 19 our @ISA = qw( Regexp::Parser::__object__ );
360  
361 54 ▶ sub new {
Subroutine new: called CC=2 SCAR=6.9
362 54 my ($class, $rx, $type, $neg, $how) = @_;
363 my $self = bless {
364 rx => $rx,
365 54 flags => $rx->{flags}[-1],
366 family => 'anyof_class',
367 }, $class;
368  
369 54 ▶ if (ref $type) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $type) { } 36 18 54
370 36 $self->{data} = $type;
371 }
372 else {
373 18 $self->{type} = $type;
374 18 $self->{data} = 'POSIX';
375 18 $self->{neg} = $neg;
376 18 $self->{how} = $how;
377 }
378  
379 54 return $self;
380 }
381  
382 2 ▶ sub type {
Subroutine type: called CC=4 SCAR=21.7
383 2 my $self = shift;
384 2 ▶ if (ref $self->{data}) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $self->{'data'}) { } 2 0 2
385 2 $self->{data}->type;
386 }
387 else {
388 my $how = ref $self->{how} eq 'SCALAR' ?
389 0 ${ $self->{how} } :
390 0 ▶ $self->{how};
Branch: 1 branch
BranchTrueFalseTotal
ref $self->{'how'} eq 'SCALAR' ? : 0 0 0
391 join "", $how, ($self->{neg} ? '^' : ''),
392 0 ▶ $self->{type}, $how;
Branch: 1 branch
BranchTrueFalseTotal
$self->{'neg'} ? : 0 0 0
393 }
394 }
395  
396 0 ▶ sub neg {
Subroutine neg: not called CC=4 SCAR=30.0
397 0 my $self = shift;
398 0 ▶ if (ref $self->{data}) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $self->{'data'}) { } 0 0 0
399 0 ▶ $self->{data}->neg = shift if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 0 0
400 0 $self->{data}->neg;
401 }
402 else {
403 0 ▶ $self->{neg} = shift if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 0 0
404 0 $self->{neg};
405 }
406 }
407  
408 28 ▶ sub visual {
Subroutine visual: called CC=4 SCAR=13.9
409 28 my $self = shift;
410 28 ▶ if (ref $self->{data}) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $self->{'data'}) { } 21 7 28
411 21 $self->{data}->visual;
412 }
413 else {
414 my $how = ref $self->{how} eq 'SCALAR' ?
415 7 ${ $self->{how} } :
416 7 ▶ $self->{how};
Branch: 1 branch
BranchTrueFalseTotal
ref $self->{'how'} eq 'SCALAR' ? : 7 0 7
417 join "", "[", $how, ($self->{neg} ? '^' : ''),
418 7 ▶ $self->{type}, $how, "]";
Branch: 1 branch
BranchTrueFalseTotal
$self->{'neg'} ? : 2 5 7
419 }
420 }
421 }
422  
423  
424 {
425 19 package Regexp::Parser::anyof_close;
426 19 our @ISA = qw( Regexp::Parser::__object__ );
427  
428 45 ▶ sub new {
Subroutine new: called CC=1 SCAR=0.0
429 45 my ($class, $rx) = @_;
430 my $self = bless {
431 rx => $rx,
432 45 flags => $rx->{flags}[-1],
433 family => 'close',
434 type => 'anyof_close',
435 raw => ']',
436 omit => 1,
437 up => 1,
438 }, $class;
439 45 return $self;
440 }
441  
442 44 ▶ sub insert {
Subroutine insert: called CC=1 SCAR=0.0
443 44 my $self = shift;
444 44 my $rx = $self->{rx};
445 44 $rx->{tree} = pop @{ $rx->{stack} };
446 44 return $self;
447 }
448 }
449  
450  
451 {
452 19 package Regexp::Parser::prop;
453 19 our @ISA = qw( Regexp::Parser::__object__ );
454  
455 5 ▶ sub new {
Subroutine new: called CC=2 SCAR=6.9
456 5 my ($class, $rx, $type, $neg) = @_;
457 my $self = bless {
458 rx => $rx,
459 5 ▶ flags => $rx->{flags}[-1],
Branch: 1 branch
BranchTrueFalseTotal
$neg ? : 2 3 5
460 family => 'prop',
461 type => $type,
462 data => '',
463 neg => ($neg ? 1 : 0),
464 }, $class;
465 5 return $self;
466 }
467  
468 5 ▶ sub type {
Subroutine type: called CC=1 SCAR=0.0
469 5 my $self = shift;
470 5 $self->{type};
471 }
472  
473 0 ▶ sub neg {
Subroutine neg: not called CC=2 SCAR=17.9
474 0 my $self = shift;
475 0 ▶ $self->{neg} = shift if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 0 0
476 0 $self->{neg};
477 }
478  
479 5 ▶ sub visual {
Subroutine visual: called CC=2 SCAR=6.9
480 5 my $self = shift;
481 5 ▶ sprintf "\\%s{%s}", $self->{neg} ? 'P' : 'p', $self->type;
Branch: 1 branch
BranchTrueFalseTotal
$self->{'neg'} ? : 2 3 5
482 }
483 }
484  
485  
486 {
487 19 package Regexp::Parser::clump;
488 19 our @ISA = qw( Regexp::Parser::__object__ );
489  
490 2 ▶ sub new {
Subroutine new: called CC=1 SCAR=0.0
491 2 my ($class, $rx, $vis) = @_;
492 my $self = bless {
493 rx => $rx,
494 2 flags => $rx->{flags}[-1],
495 family => 'clump',
496 type => 'clump',
497 vis => $vis,
498 }, $class;
499 }
500 }
501  
502  
503 {
504 19 package Regexp::Parser::branch;
505 19 our @ISA = qw( Regexp::Parser::__object__ );
506  
507 127 ▶ sub new {
Subroutine new: called CC=1 SCAR=0.0
508 127 my ($class, $rx) = @_;
509 my $self = bless {
510 rx => $rx,
511 127 flags => $rx->{flags}[-1],
512 data => [[]],
513 family => 'branch',
514 type => 'branch',
515 raw => '|',
516 branch => 1,
517 }, $class;
518 }
519  
520 3 ▶ sub qr {
Subroutine qr: called CC=1 SCAR=0.0
521 3 my $self = shift;
522 3 join $self->raw, map join("", map $_->qr, @$_), @{ $self->{data} };
523 }
524  
525 100 ▶ sub visual {
Subroutine visual: called CC=1 SCAR=0.0
526 100 my $self = shift;
527 100 join $self->raw, map join("", map $_->visual, @$_), @{ $self->{data} };
528 }
529  
530 0 ▶ sub merge {
Subroutine merge: not called CC=5 SCAR=34.0
531 0 my ($self) = @_;
532 0 my $tree = $self->{rx}{tree};
533 0 ▶ return unless @$tree;
Branch: 1 branch
BranchTrueFalseTotal
unless @$tree 0 0 0
534  
535 0 ▶ push @$tree, $self unless $tree->[-1] == $self;
Branch: 1 branch
BranchTrueFalseTotal
unless $tree->[-1] == $self 0 0 0
536 0 ▶ return unless @$tree > 1;
Branch: 1 branch
BranchTrueFalseTotal
unless @$tree > 1 0 0 0
537 0 my $prev = $tree->[-2];
538 0 ▶ return unless $prev->type eq $self->type;
Branch: 1 branch
BranchTrueFalseTotal
unless $prev->type eq $self->type 0 0 0
539 0 push @{ $prev->{data} }, @{ $self->{data} };
540 0 pop @$tree;
541 0 return 1;
542 }
543  
544 27 ▶ sub walk {
Subroutine walk: called CC=3 SCAR=11.0
545 27 my ($self, $ws, $d) = @_;
546 27 ▶ if ($d) {
Branch: 1 branch
BranchTrueFalseTotal
if ($d) 27 0 27
547 27 my $br = $self->{rx}->object($self->type);
548 27 $br->omit(1);
549 27 for (reverse @{ $self->data }) {
550 39 ▶ unshift @$ws, $br, sub { -1 }, @$_, sub { +1 };
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
551 }
552 27 shift @$ws;
553 }
554 }
555  
556 71 ▶ sub insert {
Subroutine insert: called CC=13 SCAR=26.0
557 71 my ($self, $tree) = @_;
558 71 my $rx = $self->{rx};
559 71 my $st = $rx->{stack};
560  
561 # this is a branch inside an IFTHEN
562 71 ▶ if (@$st and @{ $st->[-1] } and $st->[-1][-1]->type eq 'ifthen') {
Branch: 2 branches
BranchTrueFalseTotal
if (@$st and @{$st->[-1];} and $st->[-1][-1]->type eq 'ifthen') { } 24 47 71
elsif (@$st and @{$st->[-1];} and $st->[-1][-1]->family eq $self->family) { } 8 39 47
Condition83%5/6
@$st and @{$st->[-1];} and $st->[-1][-1]->type eq "ifthen"
!ll&&!rl&&r
93824
@$st and @{$st->[-1];}
!ll&&!rl&&r
9062
MC/DC66%2/3
@$st and @{$st->[-1];} and $st->[-1][-1]->type eq "ifthen"
@$st @{$st->[-1];} $st->[-1][-1]->type eq "ifthen"
Truth table75%3/4
A and B and C
A= @$stB= @{$st->[-1];}C= $st->[-1][-1]->type eq "ifthen"
ABCresult
0XX0
10X0
1100
1111
563 24 my $ifthen = $st->[-1][-1];
564 24 my $cond = shift @{ $ifthen->{data} };
565 24 $ifthen->{data} = [ [ @{ $ifthen->{data} } ], $cond ];
566 24 $rx->{tree} = $ifthen->{data};
567 }
568  
569 # if this is the 2nd or 3rd (etc) branch...
570 38 ▶ elsif (@$st and @{ $st->[-1] } and $st->[-1][-1]->family eq $self->family) {
Condition83%5/6
@$st and @{$st->[-1];} and $st->[-1][-1]->family eq $self->family
!ll&&!rl&&r
9308
@$st and @{$st->[-1];}
!ll&&!rl&&r
9038
MC/DC66%2/3
@$st and @{$st->[-1];} and $st->[-1][-1]->family eq $self->family
@$st @{$st->[-1];} $st->[-1][-1]->family eq $self->family
Truth table75%3/4
A and B and C
A= @$stB= @{$st->[-1];}C= $st->[-1][-1]->family eq $self->family
ABCresult
0XX0
10X0
1100
1111
571 8 my $br = $st->[-1][-1];
572 8 $br->{data}[-1] = [ @$tree ];
573 8 for (@{ $br->{data}[-1] }) {
574 8 ▶ last unless $br->{zerolen} &&= $_->{zerolen};
Branch: 1 branch
BranchTrueFalseTotal
unless $br->{"zerolen"} &&= $_->{"zerolen"} 8 0 8
Condition33%1/3
$br->{"zerolen"} &&= $_->{"zerolen"}
!ll&&!rl&&r
800
MC/DC0%0/2
$br->{"zerolen"} &&= $_->{"zerolen"}
$br->{"zerolen"} $_->{"zerolen"}
Truth table33%1/3
A &&= B
A= $br->{"zerolen"}B= $_->{"zerolen"}
ABresult
0X0
100
111
575 }
576 8 push @{ $br->{data} }, [];
577 8 $rx->{tree} = $br->{data}[-1];
578 }
579  
580 # if this is the first branch
581 else {
582 39 $self->{data}[-1] = [ @$tree ];
583 39 push @{ $self->{data} }, [];
584 39 @$tree = $self;
585 39 $tree->[-1]{zerolen} = 1;
586 39 for (@{ $tree->[-1]{data}[0] }) {
587 39 ▶ last unless $tree->[-1]{zerolen} &&= $_->{zerolen};
Branch: 1 branch
BranchTrueFalseTotal
unless $tree->[-1]{"zerolen"} &&= $_->{"zerolen"} 39 0 39
Condition33%1/3
$tree->[-1]{"zerolen"} &&= $_->{"zerolen"}
!ll&&!rl&&r
0390
MC/DC0%0/2
$tree->[-1]{"zerolen"} &&= $_->{"zerolen"}
$tree->[-1]{"zerolen"} $_->{"zerolen"}
Truth table33%1/3
A &&= B
A= $tree->[-1]{"zerolen"}B= $_->{"zerolen"}
ABresult
0X0
100
111
588 }
589 39 push @$st, $tree;
590 39 $rx->{tree} = $self->{data}[-1];
591 }
592 }
593 }
594  
595  
596 {
597 19 package Regexp::Parser::exact;
598 19 our @ISA = qw( Regexp::Parser::__object__ );
599  
600 826 ▶ sub new {
Subroutine new: called CC=2 SCAR=6.9
601 826 my ($class, $rx, $data, $vis) = @_;
602 826 ▶ $vis = $data if not defined $vis;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $vis 686 140 826
603 my $self = bless {
604 rx => $rx,
605 826 flags => $rx->{flags}[-1],
606 family => 'exact',
607 data => [$data],
608 vis => [$vis],
609 }, $class;
610 826 return $self;
611 }
612  
613 574 ▶ sub visual {
Subroutine visual: called CC=1 SCAR=0.0
614 574 my $self = shift;
615 574 join "", @{ $self->{vis} };
616 }
617  
618 893 ▶ sub type {
Subroutine type: called CC=2 SCAR=6.9
619 893 my $self = shift;
620 893 ▶ $self->{flags} & $self->{rx}->FLAG_i ? "exactf" : "exact";
Branch: 1 branch
BranchTrueFalseTotal
$self->{'flags'} & $self->{'rx'}->FLAG_i ? : 61 832 893
621 }
622  
623 2 ▶ sub data {
Subroutine data: called CC=1 SCAR=0.0
624 2 my $self = shift;
625 2 join "", @{ $self->{data} };
626 }
627  
628 826 ▶ sub merge {
Subroutine merge: called CC=5 SCAR=16.1
629 826 my ($self) = @_;
630 826 my $tree = $self->{rx}{tree};
631 826 ▶ return unless @$tree;
Branch: 1 branch
BranchTrueFalseTotal
unless @$tree 0 826 826
632  
633 826 ▶ push @$tree, $self unless $tree->[-1] == $self;
Branch: 1 branch
BranchTrueFalseTotal
unless $tree->[-1] == $self 0 826 826
634 826 ▶ return unless @$tree > 1;
Branch: 1 branch
BranchTrueFalseTotal
unless @$tree > 1 343 483 826
635 483 my $prev = $tree->[-2];
636 483 ▶ return unless $prev->type eq $self->type;
Branch: 1 branch
BranchTrueFalseTotal
unless $prev->type eq $self->type 118 365 483
637
638 365 push @{ $prev->{data} }, @{ $self->{data} };
639 365 push @{ $prev->{vis} }, @{ $self->{vis} };
640 365 pop @$tree;
641 365 return 1;
642 }
643 }
644  
645  
646 {
647 19 package Regexp::Parser::quant;
648 19 our @ISA = qw( Regexp::Parser::__object__ );
649  
650 121 ▶ sub new {
Subroutine new: called CC=1 SCAR=0.0
651 121 my ($class, $rx, $min, $max, $data) = @_;
652 my $self = bless {
653 rx => $rx,
654 121 flags => $rx->{flags}[-1],
655 family => 'quant',
656 data => $data,
657 min => $min,
658 max => $max,
659 }, $class;
660 121 return $self;
661 }
662  
663 214 ▶ sub min {
Subroutine min: called CC=1 SCAR=0.0
664 214 my $self = shift;
665 214 $self->{min};
666 }
667  
668 214 ▶ sub max {
Subroutine max: called CC=1 SCAR=0.0
669 214 my $self = shift;
670 214 $self->{max};
671 }
672  
673 27 ▶ sub type {
Subroutine type: called CC=5 SCAR=16.1
674 27 my $self = shift;
675 27 my ($min, $max) = ($self->min, $self->max);
676 27 ▶ if ($min == 0 and $max eq '') { 'star' }
Branch: 2 branches
BranchTrueFalseTotal
if ($min == 0 and $max eq '') { } 7 20 27
elsif ($min == 1 and $max eq '') { } 10 10 20
Condition100%3/3
$min == 0 and $max eq ""
!ll&&!rl&&r
1917
MC/DC100%2/2
$min == 0 and $max eq ""
$min == 0 $max eq ""
Truth table100%3/3
A and B
A= $min == 0B= $max eq ""
ABresult
0X0
100
111
677 10 ▶ elsif ($min == 1 and $max eq '') { 'plus' }
Condition66%2/3
$min == 1 and $max eq ""
!ll&&!rl&&r
10010
MC/DC50%1/2
$min == 1 and $max eq ""
$min == 1 $max eq ""
Truth table66%2/3
A and B
A= $min == 1B= $max eq ""
ABresult
0X0
100
111
678 10 else { 'curly' }
679 }
680  
681 187 ▶ sub raw {
Subroutine raw: called CC=9 SCAR=22.0
682 187 my $self = shift;
683 187 my ($min, $max) = ($self->min, $self->max);
684 187 ▶ if ($min == 0 and $max eq '') { '*' }
Branch: 4 branches
BranchTrueFalseTotal
if ($min == 0 and $max eq '') { } 50 137 187
elsif ($min == 1 and $max eq '') { } 97 40 137
elsif ($min == 0 and $max == 1) { } 9 31 40
elsif ($max ne '' and $min == $max) { } 6 25 31
Condition100%3/3
$min == 0 and $max eq ""
!ll&&!rl&&r
128950
MC/DC100%2/2
$min == 0 and $max eq ""
$min == 0 $max eq ""
Truth table100%3/3
A and B
A= $min == 0B= $max eq ""
ABresult
0X0
100
111
685 97 ▶ elsif ($min == 1 and $max eq '') { '+' }
Condition66%2/3
$min == 1 and $max eq ""
!ll&&!rl&&r
40097
MC/DC50%1/2
$min == 1 and $max eq ""
$min == 1 $max eq ""
Truth table66%2/3
A and B
A= $min == 1B= $max eq ""
ABresult
0X0
100
111
686 9 ▶ elsif ($min == 0 and $max == 1) { '?' }
Condition66%2/3
$min == 0 and $max == 1
!ll&&!rl&&r
3109
MC/DC50%1/2
$min == 0 and $max == 1
$min == 0 $max == 1
Truth table66%2/3
A and B
A= $min == 0B= $max == 1
ABresult
0X0
100
111
687 6 ▶ elsif ($max ne '' and $min == $max) { "{$min}" }
Condition100%3/3
$max ne "" and $min == $max
!ll&&!rl&&r
1876
MC/DC100%2/2
$max ne "" and $min == $max
$max ne "" $min == $max
Truth table100%3/3
A and B
A= $max ne ""B= $min == $max
ABresult
0X0
100
111
688 25 else { "{$min,$max}" }
689 }
690  
691 51 ▶ sub qr {
Subroutine qr: called CC=1 SCAR=0.0
692 51 my $self = shift;
693 51 join "", $self->{data}->qr, $self->raw;
694 }
695  
696 136 ▶ sub visual {
Subroutine visual: called CC=1 SCAR=0.0
697 136 my $self = shift;
698 136 join "", $self->{data}->visual, $self->raw;
699 }
700  
701 0 ▶ sub data {
Subroutine data: not called CC=4 SCAR=30.0
702 0 my $self = shift;
703 0 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
704 0 my $how = shift;
705 0 ▶ if ($how eq '=') { $self->{data} = \@_ }
Branch: 2 branches
BranchTrueFalseTotal
if ($how eq '=') { } 0 0 0
elsif ($how eq '+') { } 0 0 0
706 0 elsif ($how eq '+') { push @{ $self->{data} }, @_ }
707 else {
708 0 my $t = $self->type;
709 0 Carp::croak("\$$t->data([+=], \@data)");
710 }
711 }
712 0 $self->{data};
713 }
714  
715 19 ▶ sub walk {
Subroutine walk: called CC=2 SCAR=6.9
716 19 my ($self, $ws, $d) = @_;
717 19 ▶ unshift @$ws, sub { -1 }, $self->{data}, sub { +1 } if $d;
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
BranchTrueFalseTotal
if $d 15 4 19
718 }
719  
720 121 ▶ sub insert {
Subroutine insert: called CC=13 SCAR=30.4
721 121 my ($self, $tree) = @_;
722 121 my $rx = $self->{rx};
723  
724 # quantifiers must follow something
725 121 ▶ $rx->error($rx->RPe_EQUANT)
Branch: 1 branch
BranchTrueFalseTotal
if @$tree == 0 or $tree->[-1]->family eq "flags" 3 118 121
Condition66%2/3
@$tree == 0 or $tree->[-1]->family eq "flags"
l!l&&r!l&&!r
30118
MC/DC50%1/2
@$tree == 0 or $tree->[-1]->family eq "flags"
@$tree == 0 $tree->[-1]->family eq "flags"
Truth table66%2/3
A or B
A= @$tree == 0B= $tree->[-1]->family eq "flags"
ABresult
1X1
011
000
726 if @$tree == 0 or $tree->[-1]->family eq "flags";
727  
728 # quantifiers must NOT follow quantifiers
729 118 ▶ $rx->error($rx->RPe_NESTED)
Branch: 1 branch
BranchTrueFalseTotal
if $tree->[-1]->family eq "quant" 4 114 118
730 if $tree->[-1]->family eq "quant";
731  
732 # on /abc+/, we extract the 'c' from the 'exact' node
733 114 ▶ if ($tree->[-1]->family eq "exact" and @{ $tree->[-1]->{data} } > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tree->[-1]->family eq 'exact' and @{$tree->[-1]{'data'};} > 1) { } 0 114 114
Condition66%2/3
$tree->[-1]->family eq "exact" and @{$tree->[-1]{"data"};} > 1
!ll&&!rl&&r
73410
MC/DC0%0/2
$tree->[-1]->family eq "exact" and @{$tree->[-1]{"data"};} > 1
$tree->[-1]->family eq "exact" @{$tree->[-1]{"data"};} > 1
Truth table66%2/3
A and B
A= $tree->[-1]->family eq "exact"B= @{$tree->[-1]{"data"};} > 1
ABresult
0X0
100
111
734 0 my $d = pop @{ $tree->[-1]->{data} };
735 0 my $v = pop @{ $tree->[-1]->{vis} };
736 0 my $q = $rx->object(exact => $d, $v);
737 0 $q->{flags} = $tree->[-1]->{flags};
738 0 $self->{data} = $q;
739 0 push @$tree, $self;
740 }
741 else {
742 # quantifier on (?{ ... }) is pointless;
743 # bounded quantifier (but not ?) on a
744 # zero-width assertion is unexpected
745 114 ▶ if (
Branch: 2 branches
BranchTrueFalseTotal
if ($tree->[-1]->family eq 'assertion' and $tree->[-1]->type eq 'eval' or $tree->[-1]{'zerolen'} and not $self->{'min'} == 0 && $self->{'max'} == 1) { } 2 112 114
elsif ($tree->[-1]{'zerolen'} and $self->{'max'} eq '') { } 0 224 224
Condition75%9/12
$tree->[-1]->family eq "assertion" and $tree->[-1]->type eq "eval" or $tree->[-1]{"zerolen"} and not $self->{"min"} == 0 && $self->{"max"} == 1
l!l&&r!l&&!r
11112
$tree->[-1]->family eq "assertion" and $tree->[-1]->type eq "eval"
!ll&&!rl&&r
11031
$tree->[-1]{"zerolen"} and not $self->{"min"} == 0 && $self->{"max"} == 1
!ll&&!rl&&r
11201
$self->{'min'} == 0 && $self->{'max'} == 1
!ll&&!rl&&r
010
MC/DC60%3/5
$tree->[-1]->family eq "assertion" and $tree->[-1]->type eq "eval" or $tree->[-1]{"zerolen"} and not $self->{"min"} == 0 && $self->{"max"} == 1
$tree->[-1]->family eq "assertion" $tree->[-1]->type eq "eval" $tree->[-1]{"zerolen"} $self->{'min'} == 0 $self->{'max'} == 1
Truth table44%4/9
A and B or C and not(D && E)
A= $tree->[-1]->family eq "assertion"B= $tree->[-1]->type eq "eval"C= $tree->[-1]{"zerolen"}D= $self->{'min'} == 0E= $self->{'max'} == 1
ABCDEresult
11XXX1
0X10X1
0X1101
1010X1
101101
0X0XX0
0X1110
100XX0
101110
746 ($tree->[-1]->family eq "assertion" and $tree->[-1]->type eq "eval") or
747 ($tree->[-1]->{zerolen} and !($self->{min} == 0 and $self->{max} == 1))
748 ) {
749 2 $rx->awarn($rx->RPe_ZQUANT);
750 }
751  
752 # unbounded quantifier on a zero-width
753 # assertion can match a null string a lot
754 ▶ elsif ($tree->[-1]->{zerolen} and $self->{max} eq '') {
Condition33%1/3
$tree->[-1]{"zerolen"} and $self->{"max"} eq ""
!ll&&!rl&&r
11200
MC/DC0%0/2
$tree->[-1]{"zerolen"} and $self->{"max"} eq ""
$tree->[-1]{"zerolen"} $self->{"max"} eq ""
Truth table33%1/3
A and B
A= $tree->[-1]{"zerolen"}B= $self->{"max"} eq ""
ABresult
0X0
100
111
755 0 $rx->awarn($rx->RPe_NULNUL, $tree->[-1]->visual . $self->raw);
756 }
757  
758 114 $self->{data} = $tree->[-1];
759 114 $tree->[-1] = $self;
760 }
761 }
762 }
763  
764  
765 {
766 # ( non-capturing
767 19 package Regexp::Parser::group;
768 19 our @ISA = qw( Regexp::Parser::__object__ );
769  
770 57 ▶ sub new {
Subroutine new: called CC=1 SCAR=0.0
771 57 my ($class, $rx, $on, $off, @data) = @_;
772 my $self = bless {
773 rx => $rx,
774 57 flags => $rx->{flags}[-1],
775 family => 'group',
776 type => 'group',
777 data => \@data,
778 on => $on,
779 off => $off,
780 down => 1,
781 }, $class;
782 }
783  
784 6 ▶ sub on {
Subroutine on: called CC=1 SCAR=0.0
785 6 my $self = shift;
786 6 $self->{on};
787 }
788  
789 0 ▶ sub off {
Subroutine off: not called CC=1 SCAR=6.9
790 0 my $self = shift;
791 0 $self->{off};
792 }
793  
794 63 ▶ sub raw {
Subroutine raw: called CC=3 SCAR=11.0
795 63 my $self = shift;
796 63 ▶ if ($self->{on} =~ /^\^/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"on"} =~ /^\^/) 4 59 63
797 4 return join "", "(?", $self->{on}, ":";
798 }
799 join "", "(?", $self->{on},
800 59 ▶ (length $self->{off} ? "-" : ""), $self->{off}, ":";
Branch: 1 branch
BranchTrueFalseTotal
length $self->{'off'} ? : 6 53 59
801 }
802  
803 6 ▶ sub qr {
Subroutine qr: called CC=1 SCAR=0.0
804 6 my $self = shift;
805 6 join "", $self->raw, map($_->qr, @{ $self->{data} }), ")";
806 }
807  
808 57 ▶ sub visual {
Subroutine visual: called CC=1 SCAR=0.0
809 57 my $self = shift;
810 57 join "", $self->raw, map($_->visual, @{ $self->{data} }), ")";
811 }
812  
813 0 ▶ sub data {
Subroutine data: not called CC=4 SCAR=30.0
814 0 my $self = shift;
815 0 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
816 0 my $how = shift;
817 0 ▶ if ($how eq '=') { $self->{data} = \@_ }
Branch: 2 branches
BranchTrueFalseTotal
if ($how eq '=') { } 0 0 0
elsif ($how eq '+') { } 0 0 0
818 0 elsif ($how eq '+') { push @{ $self->{data} }, @_ }
819 else {
820 0 my $t = $self->type;
821 0 Carp::croak("\$$t->data([+=], \@data)");
822 }
823 }
824 0 $self->{data};
825 }
826  
827 1 ▶ sub walk {
Subroutine walk: called CC=2 SCAR=7.0
828 1 my ($self, $ws, $d) = @_;
829 1 unshift @$ws, $self->{rx}->object(@{ $self->ender });
830 1 ▶ unshift @$ws, sub { -1 }, @{ $self->{data} }, sub { +1 } if $d;
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
BranchTrueFalseTotal
if $d 1 0 1
831 }
832  
833 57 ▶ sub insert {
Subroutine insert: called CC=1 SCAR=0.0
834 57 my ($self, $tree) = @_;
835 57 my $rx = $self->{rx};
836 57 push @$tree, $self;
837 57 push @{ $rx->{stack} }, $tree;
838 57 $rx->{tree} = $self->{data};
839 }
840 }
841  
842  
843 {
844 # ( capturing
845 19 package Regexp::Parser::open;
846 19 our @ISA = qw( Regexp::Parser::__object__ );
847  
848 85 ▶ sub new {
Subroutine new: called CC=1 SCAR=0.0
849 85 my ($class, $rx, $nparen, @data) = @_;
850 my $self = bless {
851 rx => $rx,
852 85 flags => $rx->{flags}[-1],
853 family => 'open',
854 nparen => $nparen,
855 data => \@data,
856 raw => '(',
857 down => 1,
858 }, $class;
859 85 $self->{rx}{captures}[$nparen - 1] = $self;
860 85 return $self;
861 }
862  
863 15 ▶ sub type {
Subroutine type: called CC=1 SCAR=0.0
864 15 my $self = shift;
865 15 $self->family . $self->nparen;
866 }
867  
868 105 ▶ sub nparen {
Subroutine nparen: called CC=1 SCAR=0.0
869 105 my $self = shift;
870 105 $self->{nparen};
871 }
872  
873 15 ▶ sub qr {
Subroutine qr: called CC=1 SCAR=0.0
874 15 my $self = shift;
875 15 join "", $self->raw, map($_->qr, @{ $self->{data} }), ")";
876 }
877  
878 74 ▶ sub visual {
Subroutine visual: called CC=1 SCAR=0.0
879 74 my $self = shift;
880 74 join "", $self->raw, map($_->visual, @{ $self->{data} }), ")";
881 }
882  
883 0 ▶ sub ender {
Subroutine ender: not called CC=1 SCAR=6.9
884 0 my $self = shift;
885 0 [ close => $self->nparen ];
886 }
887  
888 0 ▶ sub data {
Subroutine data: not called CC=4 SCAR=30.0
889 0 my $self = shift;
890 0 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
891 0 my $how = shift;
892 0 ▶ if ($how eq '=') { $self->{data} = \@_ }
Branch: 2 branches
BranchTrueFalseTotal
if ($how eq '=') { } 0 0 0
elsif ($how eq '+') { } 0 0 0
893 0 elsif ($how eq '+') { push @{ $self->{data} }, @_ }
894 else {
895 0 my $t = $self->type;
896 0 Carp::croak("\$$t->data([+=], \@data)");
897 }
898 }
899 0 $self->{data};
900 }
901  
902 0 ▶ sub walk {
Subroutine walk: not called CC=2 SCAR=17.9
903 0 my ($self, $ws, $d) = @_;
904 0 unshift @$ws, $self->{rx}->object(@{ $self->ender });
905 0 ▶ unshift @$ws, sub { -1 }, @{ $self->{data} }, sub { +1 } if $d;
Subroutine __ANON__: not called CC=1 SCAR=6.9
Subroutine __ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
if $d 0 0 0
906 }
907  
908 85 ▶ sub insert {
Subroutine insert: called CC=1 SCAR=0.0
909 85 my ($self, $tree) = @_;
910 85 my $rx = $self->{rx};
911 85 push @$tree, $self;
912 85 push @{ $rx->{stack} }, $tree;
913 85 $rx->{tree} = $self->{data};
914 }
915 }
916  
917  
918 {
919 # ) closing
920 19 package Regexp::Parser::close;
921 19 our @ISA = qw( Regexp::Parser::__object__ );
922  
923 264 ▶ sub new {
Subroutine new: called CC=1 SCAR=0.0
924 264 my ($class, $rx, $nparen) = @_;
925 my $self = bless {
926 rx => $rx,
927 264 flags => $rx->{flags}[-1],
928 family => 'close',
929 nparen => $nparen,
930 raw => ')',
931 omit => 1,
932 up => 1,
933 }, $class;
934 264 return $self;
935 }
936  
937 5 ▶ sub type {
Subroutine type: called CC=1 SCAR=0.0
938 5 my $self = shift;
939 5 $self->family . $self->nparen;
940 }
941  
942 5 ▶ sub nparen {
Subroutine nparen: called CC=1 SCAR=0.0
943 5 my $self = shift;
944 5 $self->{nparen};
945 }
946  
947 259 ▶ sub insert {
Subroutine insert: called CC=9 SCAR=22.0
948 259 my ($self, $tree) = @_;
949 259 my $rx = $self->{rx};
950  
951 do {
952 289 ▶ $tree = pop @{ $rx->{stack} }
Branch: 1 branch
BranchTrueFalseTotal
$tree = pop @{$$rx{"stack"};} or $rx->error($rx->RPe_RPAREN) 289 0 289
953 or $rx->error($rx->RPe_RPAREN)
954 259 ▶ } until $tree->[-1]->{down};
Branch: 1 branch
BranchTrueFalseTotal
$tree->[-1]{"down"} or do { do { $tree = pop @{$$rx{"stack"};} or $rx->error($rx->RPe_RPAREN) } } 259 30 289
955  
956 259 $rx->{tree} = $tree;
957  
958 259 ▶ $self->{nparen} = $tree->[-1]->nparen
Branch: 1 branch
BranchTrueFalseTotal
if $self->family eq "close" and $tree->[-1]->can("nparen") 114 145 259
Condition66%2/3
$self->family eq "close" and $tree->[-1]->can("nparen")
!ll&&!rl&&r
0145114
MC/DC50%1/2
$self->family eq "close" and $tree->[-1]->can("nparen")
$self->family eq "close" $tree->[-1]->can("nparen")
Truth table66%2/3
A and B
A= $self->family eq "close"B= $tree->[-1]->can("nparen")
ABresult
0X0
100
111
959 if $self->family eq 'close' and $tree->[-1]->can('nparen');
960  
961 259 ▶ if ($tree->[-1]->{ifthen}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tree->[-1]{'ifthen'}) { } 31 228 259
962 31 my $ifthen = $tree->[-1];
963 31 my $br = $rx->object(branch =>);
964 31 my $cond;
965  
966 31 ▶ if (ref $ifthen->{data}[0] eq "ARRAY") {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $ifthen->{'data'}[0] eq 'ARRAY') { } 24 7 31
967 24 (my($true), $cond) = splice @{ $ifthen->{data} }, 0, 2;
968 24 $br->{data} = [ $true, $ifthen->{data} ];
969 }
970 else {
971 7 $cond = shift @{ $ifthen->{data} };
972 7 $br->{data} = [ $ifthen->{data} ];
973 }
974  
975 31 $ifthen->{data} = [ $cond, $br ];
976 $ifthen->{zerolen} =
977 31 !grep !(grep $_->{zerolen}, @$_), @{ $ifthen->{data}[1]{data} };
978 }
979 else {
980 $tree->[-1]->{zerolen} ||=
981 228 ▶ !grep !$_->{zerolen}, @{ $tree->[-1]->{data} };
Condition66%2/3
$tree->[-1]{"zerolen"} ||= !grep((!$_->{"zerolen"}), @{$$tree[-1]{"data"};})
l!l&&r!l&&!r
390189
MC/DC50%1/2
$tree->[-1]{"zerolen"} ||= !grep((!$_->{"zerolen"}), @{$$tree[-1]{"data"};})
$tree->[-1]{"zerolen"} !grep((!$_->{"zerolen"}), @{$$tree[-1]{"data"};})
Truth table66%2/3
A ||= not(B)
A= $tree->[-1]{"zerolen"}B= !grep((!$_->{"zerolen"}), @{$$tree[-1]{"data"};})
ABresult
1X1
011
000
982 }
983  
984 259 ▶ push @$tree, $self unless $self->omit;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->omit 0 259 259
985 }
986 }
987  
988  
989 {
990 # ) for non-captures
991 19 package Regexp::Parser::tail;
992 19 our @ISA = qw( Regexp::Parser::__object__ );
993  
994 16 ▶ sub new {
Subroutine new: called CC=1 SCAR=0.0
995 16 my ($class, $rx) = @_;
996 my $self = bless {
997 rx => $rx,
998 16 flags => $rx->{flags}[-1],
999 family => 'close',
1000 type => 'tail',
1001 raw => ')',
1002 omit => 1,
1003 up => 1,
1004 }, $class;
1005 16 return $self;
1006 }
1007  
1008 0 ▶ sub insert {
Subroutine insert: not called CC=9 SCAR=45.0
1009 0 my ($self, $tree) = @_;
1010 0 my $rx = $self->{rx};
1011  
1012 do {
1013 0 ▶ $rx->{tree} = pop @{ $rx->{stack} }
Branch: 1 branch
BranchTrueFalseTotal
$rx->{"tree"} = pop @{$$rx{"stack"};} or $rx->error($rx->RPe_RPAREN) 0 0 0
1014 or $rx->error($rx->RPe_RPAREN)
1015 0 ▶ } until $tree->[-1]->{down};
Branch: 1 branch
BranchTrueFalseTotal
$tree->[-1]{"down"} or do { do { $rx->{"tree"} = pop @{$$rx{"stack"};} or $rx->error($rx->RPe_RPAREN) } } 0 0 0
1016  
1017 0 ▶ $self->{nparen} = $tree->[-1]->nparen
Branch: 1 branch
BranchTrueFalseTotal
if $self->family eq "close" and $tree->[-1]->can("nparen") 0 0 0
Condition0%0/3
$self->family eq "close" and $tree->[-1]->can("nparen")
!ll&&!rl&&r
000
MC/DC0%0/2
$self->family eq "close" and $tree->[-1]->can("nparen")
$self->family eq "close" $tree->[-1]->can("nparen")
Truth table0%0/3
A and B
A= $self->family eq "close"B= $tree->[-1]->can("nparen")
ABresult
0X0
100
111
1018 if $self->family eq 'close' and $tree->[-1]->can('nparen');
1019  
1020 0 ▶ if ($tree->[-1]->{ifthen}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tree->[-1]{'ifthen'}) { } 0 0 0
1021 0 my $ifthen = $tree->[-1];
1022 0 my $br = $rx->object(branch =>);
1023 0 my $cond;
1024  
1025 0 ▶ if (ref $ifthen->{data}[0] eq "ARRAY") {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $ifthen->{'data'}[0] eq 'ARRAY') { } 0 0 0
1026 0 (my($true), $cond) = splice @{ $ifthen->{data} }, 0, 2;
1027 0 $br->{data} = [ $true, $ifthen->{data} ];
1028 }
1029 else {
1030 0 $cond = shift @{ $ifthen->{data} };
1031 0 $br->{data} = [ $ifthen->{data} ];
1032 }
1033  
1034 0 $ifthen->{data} = [ $cond, $br ];
1035 $ifthen->{zerolen} =
1036 0 !grep !(grep $_->{zerolen}, @$_), @{ $ifthen->{data}[1]{data} };
1037 }
1038 else {
1039 $tree->[-1]->{zerolen} ||=
1040 0 ▶ !grep !$_->{zerolen}, @{ $tree->[-1]->{data} };
Condition0%0/3
$tree->[-1]{"zerolen"} ||= !grep((!$_->{"zerolen"}), @{$$tree[-1]{"data"};})
l!l&&r!l&&!r
000
MC/DC0%0/2
$tree->[-1]{"zerolen"} ||= !grep((!$_->{"zerolen"}), @{$$tree[-1]{"data"};})
$tree->[-1]{"zerolen"} !grep((!$_->{"zerolen"}), @{$$tree[-1]{"data"};})
Truth table0%0/3
A ||= not(B)
A= $tree->[-1]{"zerolen"}B= !grep((!$_->{"zerolen"}), @{$$tree[-1]{"data"};})
ABresult
1X1
011
000
1041 }
1042  
1043 0 ▶ push @$tree, $self unless $self->omit;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->omit 0 0 0
1044 }
1045 }
1046  
1047  
1048 {
1049 # \1 (backrefs)
1050 19 package Regexp::Parser::ref;
1051 19 our @ISA = qw( Regexp::Parser::__object__ );
1052  
1053 16 ▶ sub new {
Subroutine new: called CC=2 SCAR=7.1
1054 16 my ($class, $rx, $nparen, $vis) = @_;
1055 my $self = bless {
1056 rx => $rx,
1057 16 ▶ flags => $rx->{flags}[-1],
Branch: 1 branch
BranchTrueFalseTotal
$vis ? : 16 0 16
1058 family => 'ref',
1059 nparen => $nparen,
1060 ($vis ? (vis => $vis) : ()),
1061 }, $class;
1062 16 return $self;
1063 }
1064  
1065 0 ▶ sub type {
Subroutine type: not called CC=2 SCAR=17.9
1066 0 my $self = shift;
1067 0 ▶ ($self->{flags} & $self->{rx}->FLAG_i ? 'reff' : 'ref') . $self->nparen;
Branch: 1 branch
BranchTrueFalseTotal
$self->{'flags'} & $self->{'rx'}->FLAG_i ? : 0 0 0
1068 }
1069  
1070 0 ▶ sub nparen {
Subroutine nparen: not called CC=1 SCAR=6.9
1071 0 my $self = shift;
1072 0 $self->{nparen};
1073 }
1074  
1075 13 ▶ sub visual {
Subroutine visual: called CC=2 SCAR=7.2
1076 13 my $self = shift;
1077 13 ▶ exists $self->{vis} ? $self->{vis} : "\\$self->{nparen}";
Branch: 1 branch
BranchTrueFalseTotal
exists $self->{'vis'} ? : 13 0 13
1078 }
1079  
1080 6 ▶ sub qr {
Subroutine qr: called CC=1 SCAR=0.0
1081 6 my $self = shift;
1082 # Always emit \N format for qr() regardless of visual form
1083 6 "\\$self->{nparen}";
1084 }
1085 }
1086  
1087  
1088 {
1089 # \g{name} named backreference (Perl 5.10+)
1090 19 package Regexp::Parser::gref;
1091 19 our @ISA = qw( Regexp::Parser::__object__ );
1092  
1093 0 ▶ sub new {
Subroutine new: not called CC=1 SCAR=6.9
1094 0 my ($class, $rx, $name, $vis) = @_;
1095 my $self = bless {
1096 rx => $rx,
1097 0 flags => $rx->{flags}[-1],
1098 family => 'ref',
1099 type => 'gref',
1100 name => $name,
1101 vis => $vis,
1102 }, $class;
1103 0 return $self;
1104 }
1105  
1106 0 ▶ sub name {
Subroutine name: not called CC=1 SCAR=6.9
1107 0 my $self = shift;
1108 0 $self->{name};
1109 }
1110  
1111 0 ▶ sub visual {
Subroutine visual: not called CC=1 SCAR=6.9
1112 0 my $self = shift;
1113 0 $self->{vis};
1114 }
1115  
1116 0 ▶ sub qr {
Subroutine qr: not called CC=1 SCAR=6.9
1117 0 my $self = shift;
1118 0 "\\g{$self->{name}}";
1119 }
1120 }
1121  
1122  
1123 {
1124 19 package Regexp::Parser::assertion;
1125 19 our @ISA = qw( Regexp::Parser::__object__ );
1126  
1127 19 push @Regexp::Parser::ifmatch::ISA, __PACKAGE__;
1128 19 push @Regexp::Parser::unlessm::ISA, __PACKAGE__;
1129 19 push @Regexp::Parser::suspend::ISA, __PACKAGE__;
1130 19 push @Regexp::Parser::ifthen::ISA, __PACKAGE__;
1131 19 push @Regexp::Parser::eval::ISA, __PACKAGE__;
1132 19 push @Regexp::Parser::logical::ISA, __PACKAGE__;
1133 19 push @Regexp::Parser::script_run::ISA, __PACKAGE__;
1134 19 push @Regexp::Parser::asr::ISA, __PACKAGE__;
1135  
1136 6 ▶ sub qr {
Subroutine qr: called CC=1 SCAR=0.0
1137 6 my $self = shift;
1138 6 join "", $self->raw, map($_->qr, @{ $self->{data} }), ")";
1139 }
1140  
1141 54 ▶ sub visual {
Subroutine visual: called CC=1 SCAR=0.0
1142 54 my $self = shift;
1143 54 join "", $self->raw, map($_->visual, @{ $self->{data} }), ")";
1144 }
1145  
1146 0 ▶ sub data {
Subroutine data: not called CC=4 SCAR=30.0
1147 0 my $self = shift;
1148 0 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
1149 0 my $how = shift;
1150 0 ▶ if ($how eq '=') { $self->{data} = \@_ }
Branch: 2 branches
BranchTrueFalseTotal
if ($how eq '=') { } 0 0 0
elsif ($how eq '+') { } 0 0 0
1151 0 elsif ($how eq '+') { push @{ $self->{data} }, @_ }
1152 else {
1153 0 my $t = $self->type;
1154 0 Carp::croak("\$$t->data([+=], \@data)");
1155 }
1156 }
1157 0 $self->{data};
1158 }
1159  
1160 15 ▶ sub walk {
Subroutine walk: called CC=2 SCAR=7.0
1161 15 my ($self, $ws, $d) = @_;
1162 15 unshift @$ws, $self->{rx}->object(@{ $self->ender });
1163 15 ▶ unshift @$ws, sub { -1 }, @{ $self->{data} }, sub { +1 } if $d;
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
BranchTrueFalseTotal
if $d 15 0 15
1164 }
1165  
1166 81 ▶ sub insert {
Subroutine insert: called CC=1 SCAR=0.0
1167 81 my ($self, $tree) = @_;
1168 81 my $rx = $self->{rx};
1169 81 push @$tree, $self;
1170 81 push @{ $rx->{stack} }, $tree;
1171 81 $rx->{tree} = $self->{data};
1172 }
1173 }
1174  
1175  
1176 {
1177 # (?=) (?<=)
1178 19 package Regexp::Parser::ifmatch;
1179  
1180 23 ▶ sub new {
Subroutine new: called CC=1 SCAR=0.0
1181 23 my ($class, $rx, $dir, @data) = @_;
1182 my $self = bless {
1183 rx => $rx,
1184 23 flags => $rx->{flags}[-1],
1185 family => 'assertion',
1186 type => 'ifmatch',
1187 dir => $dir,
1188 data => \@data,
1189 down => 1,
1190 zerolen => 1,
1191 }, $class;
1192 23 return $self;
1193 }
1194  
1195 0 ▶ sub dir {
Subroutine dir: not called CC=1 SCAR=6.9
1196 0 my $self = shift;
1197 0 $self->{dir};
1198 }
1199  
1200 25 ▶ sub raw {
Subroutine raw: called CC=2 SCAR=6.9
1201 25 my $self = shift;
1202 25 ▶ join "", "(?", ($self->{dir} < 0 ? '<' : ''), "=";
Branch: 1 branch
BranchTrueFalseTotal
$self->{'dir'} < 0 ? : 9 16 25
1203 }
1204 }
1205  
1206  
1207 {
1208 # (?!) (?<!)
1209 19 package Regexp::Parser::unlessm;
1210  
1211 22 ▶ sub new {
Subroutine new: called CC=1 SCAR=0.0
1212 22 my ($class, $rx, $dir, @data) = @_;
1213 my $self = bless {
1214 rx => $rx,
1215 22 flags => $rx->{flags}[-1],
1216 family => 'assertion',
1217 type => 'unlessm',
1218 dir => $dir,
1219 data => \@data,
1220 down => 1,
1221 zerolen => 1,
1222 }, $class;
1223 22 return $self;
1224 }
1225  
1226 0 ▶ sub dir {
Subroutine dir: not called CC=1 SCAR=6.9
1227 0 my $self = shift;
1228 0 $self->{dir};
1229 }
1230  
1231 24 ▶ sub raw {
Subroutine raw: called CC=2 SCAR=6.9
1232 24 my $self = shift;
1233 24 ▶ join "", "(?", ($self->{dir} < 0 ? '<' : ''), "!";
Branch: 1 branch
BranchTrueFalseTotal
$self->{'dir'} < 0 ? : 11 13 24
1234 }
1235 }
1236  
1237  
1238 {
1239 # (?>)
1240 19 package Regexp::Parser::suspend;
1241  
1242 7 ▶ sub new {
Subroutine new: called CC=1 SCAR=0.0
1243 7 my ($class, $rx, @data) = @_;
1244 my $self = bless {
1245 rx => $rx,
1246 7 flags => $rx->{flags}[-1],
1247 family => 'assertion',
1248 type => 'suspend',
1249 data => \@data,
1250 down => 1,
1251 }, $class;
1252 7 return $self;
1253 }
1254  
1255 7 ▶ sub raw {
Subroutine raw: called CC=1 SCAR=0.0
1256 7 my $self = shift;
1257 7 "(?>";
1258 }
1259 }
1260  
1261 {
1262 # (?(n)t|f)
1263 19 package Regexp::Parser::ifthen;
1264  
1265 31 ▶ sub new {
Subroutine new: called CC=1 SCAR=0.0
1266 31 my ($class, $rx, @data) = @_;
1267 my $self = bless {
1268 rx => $rx,
1269 31 flags => $rx->{flags}[-1],
1270 family => 'assertion',
1271 type => 'ifthen',
1272 data => [],
1273 down => 1,
1274 ifthen => 1,
1275 }, $class;
1276 31 return $self;
1277 }
1278  
1279 31 ▶ sub raw {
Subroutine raw: called CC=1 SCAR=0.0
1280 31 my $self = shift;
1281 31 "(?";
1282 }
1283  
1284 0 ▶ sub qr {
Subroutine qr: not called CC=1 SCAR=6.9
1285 0 my $self = shift;
1286 0 join "", $self->raw, $self->{data}[0]->qr, $self->{data}[1]->qr, ")";
1287 }
1288  
1289 31 ▶ sub visual {
Subroutine visual: called CC=1 SCAR=0.0
1290 31 my $self = shift;
1291 31 join "", $self->raw, $self->{data}[0]->visual, $self->{data}[1]->visual, ")";
1292 }
1293 }
1294  
1295  
1296 {
1297 # the N in (?(N)t|f) when N is a number
1298 19 package Regexp::Parser::groupp;
1299 19 our @ISA = qw( Regexp::Parser::__object__ );
1300  
1301 3 ▶ sub new {
Subroutine new: called CC=1 SCAR=0.0
1302 3 my ($class, $rx, $nparen) = @_;
1303 my $self = bless {
1304 rx => $rx,
1305 3 flags => $rx->{flags}[-1],
1306 family => 'groupp',
1307 nparen => $nparen,
1308 }, $class;
1309 3 return $self;
1310 }
1311  
1312 7 ▶ sub type {
Subroutine type: called CC=1 SCAR=0.0
1313 7 my $self = shift;
1314 7 $self->family . $self->nparen;
1315 }
1316  
1317 7 ▶ sub nparen {
Subroutine nparen: called CC=1 SCAR=0.0
1318 7 my $self = shift;
1319 7 $self->{nparen};
1320 }
1321  
1322 4 ▶ sub visual {
Subroutine visual: called CC=1 SCAR=0.0
1323 4 my $self = shift;
1324 4 "($self->{nparen})";
1325 }
1326 }
1327  
1328  
1329 {
1330 # the DEFINE in (?(DEFINE)...) — always-false condition for defining groups
1331 19 package Regexp::Parser::define;
1332 19 our @ISA = qw( Regexp::Parser::__object__ );
1333  
1334 7 ▶ sub new {
Subroutine new: called CC=1 SCAR=0.0
1335 7 my ($class, $rx) = @_;
1336 my $self = bless {
1337 rx => $rx,
1338 7 flags => $rx->{flags}[-1],
1339 family => 'groupp',
1340 type => 'define',
1341 }, $class;
1342 7 return $self;
1343 }
1344  
1345 10 ▶ sub visual {
Subroutine visual: called CC=1 SCAR=0.0
1346 10 "(DEFINE)";
1347 }
1348 }
1349  
1350  
1351 {
1352 # the <name> or 'name' in (?(<name>)t|f) / (?('name')t|f)
1353 19 package Regexp::Parser::grouppn;
1354 19 our @ISA = qw( Regexp::Parser::__object__ );
1355  
1356 6 ▶ sub new {
Subroutine new: called CC=2 SCAR=7.1
1357 6 my ($class, $rx, $name, $delim) = @_;
1358 my $self = bless {
1359 rx => $rx,
1360 6 ▶ flags => $rx->{flags}[-1],
Condition50%1/2
$delim || '<'
l!l
60
MC/DC0%0/1
$delim || '<'
$delim
Truth table50%1/2
A
A= $delim
Aresult
11
00
1361 family => 'groupp',
1362 type => 'grouppn',
1363 name => $name,
1364 delim => $delim || '<',
1365 }, $class;
1366 6 return $self;
1367 }
1368  
1369 0 ▶ sub name {
Subroutine name: not called CC=1 SCAR=6.9
1370 0 my $self = shift;
1371 0 $self->{name};
1372 }
1373  
1374 8 ▶ sub visual {
Subroutine visual: called CC=2 SCAR=6.9
1375 8 my $self = shift;
1376 8 ▶ my ($open, $close) = $self->{delim} eq '<' ? ('<', '>') : ("'", "'");
Branch: 1 branch
BranchTrueFalseTotal
$self->{'delim'} eq '<' ? : 4 4 8
1377 8 "($open$self->{name}$close)";
1378 }
1379 }
1380  
1381  
1382 {
1383 # (?{ ... })
1384 19 package Regexp::Parser::eval;
1385  
1386 6 ▶ sub new {
Subroutine new: called CC=1 SCAR=0.0
1387 6 my ($class, $rx, $code) = @_;
1388 my $self = bless {
1389 rx => $rx,
1390 6 flags => $rx->{flags}[-1],
1391 family => 'assertion',
1392 type => 'eval',
1393 data => $code,
1394 zerolen => 1,
1395 }, $class;
1396 6 return $self;
1397 }
1398  
1399 7 ▶ sub visual {
Subroutine visual: called CC=1 SCAR=0.0
1400 7 my $self = shift;
1401 7 "(?{$self->{data}})";
1402 }
1403  
1404 0 ▶ sub qr {
Subroutine qr: not called CC=1 SCAR=6.9
1405 0 my $self = shift;
1406 0 $self->visual;
1407 }
1408  
1409 6 ▶ sub insert {
Subroutine insert: called CC=1 SCAR=0.0
1410 6 my ($self, $tree) = @_;
1411 6 push @$tree, $self;
1412 }
1413  
1414 1 ▶ sub walk {
Subroutine walk: called CC=1 SCAR=0.0
1415 1 my $self = shift;
1416 1 return;
1417 }
1418 }
1419  
1420  
1421 {
1422 # (??{ ... })
1423 19 package Regexp::Parser::logical;
1424  
1425 2 ▶ sub new {
Subroutine new: called CC=1 SCAR=0.0
1426 2 my ($class, $rx, $code) = @_;
1427 my $self = bless {
1428 rx => $rx,
1429 2 flags => $rx->{flags}[-1],
1430 family => 'assertion',
1431 type => 'logical',
1432 data => $code,
1433 zerolen => 1,
1434 }, $class;
1435 2 return $self;
1436 }
1437  
1438 2 ▶ sub visual {
Subroutine visual: called CC=1 SCAR=0.0
1439 2 my $self = shift;
1440 2 "(??{$self->{data}})";
1441 }
1442  
1443 0 ▶ sub qr {
Subroutine qr: not called CC=1 SCAR=6.9
1444 0 my $self = shift;
1445 0 $self->visual;
1446 }
1447  
1448 2 ▶ sub insert {
Subroutine insert: called CC=1 SCAR=0.0
1449 2 my ($self, $tree) = @_;
1450 2 push @$tree, $self;
1451 }
1452  
1453 0 ▶ sub walk {
Subroutine walk: not called CC=1 SCAR=6.9
1454 0 my $self = shift;
1455 0 return;
1456 }
1457 }
1458  
1459  
1460 {
1461 19 package Regexp::Parser::flags;
1462 19 our @ISA = qw( Regexp::Parser::__object__ );
1463  
1464 11 ▶ sub new {
Subroutine new: called CC=1 SCAR=0.0
1465 11 my ($class, $rx, $on, $off) = @_;
1466 my $self = bless {
1467 rx => $rx,
1468 11 flags => $rx->{flags}[-1],
1469 family => 'flags',
1470 type => 'flags',
1471 on => $on,
1472 off => $off,
1473 zerolen => 1,
1474 }, $class;
1475 11 return $self;
1476 }
1477  
1478 0 ▶ sub on {
Subroutine on: not called CC=1 SCAR=6.9
1479 0 my $self = shift;
1480 0 $self->{on};
1481 }
1482  
1483 0 ▶ sub off {
Subroutine off: not called CC=1 SCAR=6.9
1484 0 my $self = shift;
1485 0 $self->{off};
1486 }
1487  
1488 11 ▶ sub visual {
Subroutine visual: called CC=3 SCAR=11.0
1489 11 my $self = shift;
1490 11 ▶ if ($self->{on} =~ /^\^/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"on"} =~ /^\^/) 2 9 11
1491 2 return join "", "(?", $self->{on}, ")";
1492 }
1493 join "", "(?", $self->{on},
1494 9 ▶ (length $self->{off} ? "-" : ""), $self->{off}, ")";
Branch: 1 branch
BranchTrueFalseTotal
length $self->{'off'} ? : 3 6 9
1495 }
1496 }
1497  
1498  
1499 {
1500 19 package Regexp::Parser::minmod;
1501 19 our @ISA = qw( Regexp::Parser::__object__ );
1502  
1503 12 ▶ sub new {
Subroutine new: called CC=1 SCAR=0.0
1504 12 my ($class, $rx, $data) = @_;
1505 my $self = bless {
1506 rx => $rx,
1507 12 flags => $rx->{flags}[-1],
1508 family => 'minmod',
1509 type => 'minmod',
1510 raw => '?',
1511 data => $data,
1512 }, $class;
1513 12 return $self;
1514 }
1515  
1516 11 ▶ sub qr {
Subroutine qr: called CC=1 SCAR=0.0
1517 11 my $self = shift;
1518 11 join "", $self->{data}->qr, $self->raw;
1519 }
1520  
1521 15 ▶ sub visual {
Subroutine visual: called CC=1 SCAR=0.0
1522 15 my $self = shift;
1523 15 join "", $self->{data}->visual, $self->raw;
1524 }
1525  
1526 4 ▶ sub walk {
Subroutine walk: called CC=2 SCAR=6.9
1527 4 my ($self, $ws, $d) = @_;
1528 4 ▶ unshift @$ws, sub { -1 }, $self->{data}, sub { +1 } if $d;
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
BranchTrueFalseTotal
if $d 3 1 4
1529 }
1530  
1531 12 ▶ sub insert {
Subroutine insert: called CC=1 SCAR=0.0
1532 12 my ($self, $tree) = @_;
1533 12 $self->{data} = $tree->[-1];
1534 12 $tree->[-1] = $self;
1535 }
1536 }
1537  
1538  
1539 {
1540 # \K (keep, zero-width assertion added in Perl 5.10)
1541 19 package Regexp::Parser::keep;
1542 19 our @ISA = qw( Regexp::Parser::__object__ );
1543  
1544 3 ▶ sub new {
Subroutine new: called CC=1 SCAR=0.0
1545 3 my ($class, $rx) = @_;
1546 my $self = bless {
1547 rx => $rx,
1548 3 flags => $rx->{flags}[-1],
1549 family => 'anchor',
1550 type => 'keep',
1551 vis => '\K',
1552 zerolen => 1,
1553 }, $class;
1554 3 return $self;
1555 }
1556 }
1557  
1558  
1559 {
1560 # \h \H (horizontal whitespace, added in Perl 5.10)
1561 19 package Regexp::Parser::hspace;
1562 19 our @ISA = qw( Regexp::Parser::__object__ );
1563  
1564 10 ▶ sub new {
Subroutine new: called CC=1 SCAR=0.0
1565 10 my ($class, $rx, $neg) = @_;
1566 my $self = bless {
1567 rx => $rx,
1568 10 flags => $rx->{flags}[-1],
1569 neg => $neg,
1570 }, $class;
1571 10 return $self;
1572 }
1573  
1574 2 ▶ sub neg {
Subroutine neg: called CC=2 SCAR=7.1
1575 2 my $self = shift;
1576 2 ▶ $self->{neg} = shift if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 2 2
1577 2 $self->{neg};
1578 }
1579  
1580 2 ▶ sub type {
Subroutine type: called CC=2 SCAR=6.9
1581 2 my $self = shift;
1582 2 ▶ ($self->{neg} ? 'n' : '') . $self->family;
Branch: 1 branch
BranchTrueFalseTotal
$self->{'neg'} ? : 1 1 2
1583 }
1584  
1585 12 ▶ sub family { 'hspace' }
Subroutine family: called CC=1 SCAR=0.0
1586  
1587 6 ▶ sub visual {
Subroutine visual: called CC=2 SCAR=6.9
1588 6 my $self = shift;
1589 6 ▶ $self->{neg} ? '\H' : '\h';
Branch: 1 branch
BranchTrueFalseTotal
$self->{'neg'} ? : 2 4 6
1590 }
1591 }
1592  
1593  
1594 {
1595 # \v \V (vertical whitespace, added in Perl 5.10)
1596 19 package Regexp::Parser::vspace;
1597 19 our @ISA = qw( Regexp::Parser::__object__ );
1598  
1599 6 ▶ sub new {
Subroutine new: called CC=1 SCAR=0.0
1600 6 my ($class, $rx, $neg) = @_;
1601 my $self = bless {
1602 rx => $rx,
1603 6 flags => $rx->{flags}[-1],
1604 neg => $neg,
1605 }, $class;
1606 6 return $self;
1607 }
1608  
1609 2 ▶ sub neg {
Subroutine neg: called CC=2 SCAR=7.1
1610 2 my $self = shift;
1611 2 ▶ $self->{neg} = shift if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 2 2
1612 2 $self->{neg};
1613 }
1614  
1615 2 ▶ sub type {
Subroutine type: called CC=2 SCAR=6.9
1616 2 my $self = shift;
1617 2 ▶ ($self->{neg} ? 'n' : '') . $self->family;
Branch: 1 branch
BranchTrueFalseTotal
$self->{'neg'} ? : 1 1 2
1618 }
1619  
1620 4 ▶ sub family { 'vspace' }
Subroutine family: called CC=1 SCAR=0.0
1621  
1622 3 ▶ sub visual {
Subroutine visual: called CC=2 SCAR=6.9
1623 3 my $self = shift;
1624 3 ▶ $self->{neg} ? '\V' : '\v';
Branch: 1 branch
BranchTrueFalseTotal
$self->{'neg'} ? : 1 2 3
1625 }
1626 }
1627  
1628  
1629 {
1630 # \R (generic linebreak, added in Perl 5.10)
1631 19 package Regexp::Parser::lnbreak;
1632 19 our @ISA = qw( Regexp::Parser::__object__ );
1633  
1634 4 ▶ sub new {
Subroutine new: called CC=1 SCAR=0.0
1635 4 my ($class, $rx) = @_;
1636 my $self = bless {
1637 rx => $rx,
1638 4 flags => $rx->{flags}[-1],
1639 family => 'lnbreak',
1640 type => 'lnbreak',
1641 vis => '\R',
1642 }, $class;
1643 4 return $self;
1644 }
1645 }
1646  
1647  
1648 {
1649 # (?<name>...) named capture group (added in Perl 5.10)
1650 19 package Regexp::Parser::named_open;
1651 19 our @ISA = qw( Regexp::Parser::__object__ );
1652  
1653 29 ▶ sub new {
Subroutine new: called CC=1 SCAR=0.0
1654 29 my ($class, $rx, $nparen, $name, @data) = @_;
1655 my $self = bless {
1656 rx => $rx,
1657 29 flags => $rx->{flags}[-1],
1658 family => 'open',
1659 nparen => $nparen,
1660 name => $name,
1661 data => \@data,
1662 raw => "(?<$name>",
1663 down => 1,
1664 }, $class;
1665 29 $self->{rx}{captures}[$nparen - 1] = $self;
1666 29 return $self;
1667 }
1668  
1669 5 ▶ sub type {
Subroutine type: called CC=1 SCAR=0.0
1670 5 my $self = shift;
1671 5 'open' . $self->nparen;
1672 }
1673  
1674 40 ▶ sub nparen {
Subroutine nparen: called CC=1 SCAR=0.0
1675 40 my $self = shift;
1676 40 $self->{nparen};
1677 }
1678  
1679 2 ▶ sub name {
Subroutine name: called CC=1 SCAR=0.0
1680 2 my $self = shift;
1681 2 $self->{name};
1682 }
1683  
1684 0 ▶ sub qr {
Subroutine qr: not called CC=1 SCAR=6.9
1685 0 my $self = shift;
1686 0 join "", $self->raw, map($_->qr, @{ $self->{data} }), ")";
1687 }
1688  
1689 32 ▶ sub visual {
Subroutine visual: called CC=1 SCAR=0.0
1690 32 my $self = shift;
1691 32 join "", $self->raw, map($_->visual, @{ $self->{data} }), ")";
1692 }
1693  
1694 5 ▶ sub ender {
Subroutine ender: called CC=1 SCAR=0.0
1695 5 my $self = shift;
1696 5 [ close => $self->nparen ];
1697 }
1698  
1699 0 ▶ sub data {
Subroutine data: not called CC=4 SCAR=30.0
1700 0 my $self = shift;
1701 0 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
1702 0 my $how = shift;
1703 0 ▶ if ($how eq '=') { $self->{data} = \@_ }
Branch: 2 branches
BranchTrueFalseTotal
if ($how eq '=') { } 0 0 0
elsif ($how eq '+') { } 0 0 0
1704 0 elsif ($how eq '+') { push @{ $self->{data} }, @_ }
1705 else {
1706 0 my $t = $self->type;
1707 0 Carp::croak("\$$t->data([+=], \@data)");
1708 }
1709 }
1710 0 $self->{data};
1711 }
1712  
1713 5 ▶ sub walk {
Subroutine walk: called CC=2 SCAR=7.0
1714 5 my ($self, $ws, $d) = @_;
1715 5 unshift @$ws, $self->{rx}->object(@{ $self->ender });
1716 5 ▶ unshift @$ws, sub { -1 }, @{ $self->{data} }, sub { +1 } if $d;
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
BranchTrueFalseTotal
if $d 5 0 5
1717 }
1718  
1719 29 ▶ sub insert {
Subroutine insert: called CC=1 SCAR=0.0
1720 29 my ($self, $tree) = @_;
1721 29 my $rx = $self->{rx};
1722 29 push @$tree, $self;
1723 29 push @{ $rx->{stack} }, $tree;
1724 29 $rx->{tree} = $self->{data};
1725 }
1726 }
1727  
1728  
1729 {
1730 # \k<name> named backreference (added in Perl 5.10)
1731 19 package Regexp::Parser::named_ref;
1732 19 our @ISA = qw( Regexp::Parser::__object__ );
1733  
1734 5 ▶ sub new {
Subroutine new: called CC=1 SCAR=0.0
1735 5 my ($class, $rx, $name, $vis) = @_;
1736 my $self = bless {
1737 rx => $rx,
1738 5 flags => $rx->{flags}[-1],
1739 family => 'ref',
1740 name => $name,
1741 vis => $vis,
1742 }, $class;
1743 5 return $self;
1744 }
1745  
1746 0 ▶ sub type {
Subroutine type: not called CC=2 SCAR=17.9
1747 0 my $self = shift;
1748 0 ▶ ($self->{flags} & $self->{rx}->FLAG_i ? 'named_reff' : 'named_ref');
Branch: 1 branch
BranchTrueFalseTotal
$self->{'flags'} & $self->{'rx'}->FLAG_i ? : 0 0 0
1749 }
1750  
1751 2 ▶ sub name {
Subroutine name: called CC=1 SCAR=0.0
1752 2 my $self = shift;
1753 2 $self->{name};
1754 }
1755  
1756 4 ▶ sub visual {
Subroutine visual: called CC=1 SCAR=0.0
1757 4 my $self = shift;
1758 4 $self->{vis};
1759 }
1760 }
1761  
1762  
1763 {
1764 # possessive quantifier modifier (added in Perl 5.10)
1765 19 package Regexp::Parser::possessive;
1766 19 our @ISA = qw( Regexp::Parser::__object__ );
1767  
1768 8 ▶ sub new {
Subroutine new: called CC=1 SCAR=0.0
1769 8 my ($class, $rx, $data) = @_;
1770 my $self = bless {
1771 rx => $rx,
1772 8 flags => $rx->{flags}[-1],
1773 family => 'possessive',
1774 type => 'possessive',
1775 raw => '+',
1776 data => $data,
1777 }, $class;
1778 8 return $self;
1779 }
1780  
1781 0 ▶ sub qr {
Subroutine qr: not called CC=1 SCAR=6.9
1782 0 my $self = shift;
1783 0 join "", $self->{data}->qr, $self->raw;
1784 }
1785  
1786 7 ▶ sub visual {
Subroutine visual: called CC=1 SCAR=0.0
1787 7 my $self = shift;
1788 7 join "", $self->{data}->visual, $self->raw;
1789 }
1790  
1791 0 ▶ sub walk {
Subroutine walk: not called CC=2 SCAR=17.9
1792 0 my ($self, $ws, $d) = @_;
1793 0 ▶ unshift @$ws, sub { -1 }, $self->{data}, sub { +1 } if $d;
Subroutine __ANON__: not called CC=1 SCAR=6.9
Subroutine __ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
if $d 0 0 0
1794 }
1795  
1796 8 ▶ sub insert {
Subroutine insert: called CC=1 SCAR=0.0
1797 8 my ($self, $tree) = @_;
1798 8 $self->{data} = $tree->[-1];
1799 8 $tree->[-1] = $self;
1800 }
1801 }
1802  
1803  
1804 {
1805 # (?R) (?0) (?1) (?+1) (?-1) -- recursive subpatterns (Perl 5.10+)
1806 19 package Regexp::Parser::recurse;
1807 19 our @ISA = qw( Regexp::Parser::__object__ );
1808  
1809 21 ▶ sub new {
Subroutine new: called CC=1 SCAR=0.0
1810 21 my ($class, $rx, $num, $vis) = @_;
1811 my $self = bless {
1812 rx => $rx,
1813 21 flags => $rx->{flags}[-1],
1814 family => 'recurse',
1815 type => 'recurse',
1816 num => $num,
1817 vis => $vis,
1818 }, $class;
1819 21 return $self;
1820 }
1821  
1822 8 ▶ sub num {
Subroutine num: called CC=1 SCAR=0.0
1823 8 my $self = shift;
1824 8 $self->{num};
1825 }
1826  
1827 19 ▶ sub visual {
Subroutine visual: called CC=1 SCAR=0.0
1828 19 my $self = shift;
1829 19 $self->{vis};
1830 }
1831  
1832 1 ▶ sub qr {
Subroutine qr: called CC=1 SCAR=0.0
1833 1 my $self = shift;
1834 1 $self->{vis};
1835 }
1836 }
1837  
1838  
1839 {
1840 # (?&name) -- named recursive subpattern (Perl 5.10+)
1841 19 package Regexp::Parser::named_recurse;
1842 19 our @ISA = qw( Regexp::Parser::__object__ );
1843  
1844 5 ▶ sub new {
Subroutine new: called CC=1 SCAR=0.0
1845 5 my ($class, $rx, $name, $vis) = @_;
1846 my $self = bless {
1847 rx => $rx,
1848 5 flags => $rx->{flags}[-1],
1849 family => 'recurse',
1850 type => 'named_recurse',
1851 name => $name,
1852 vis => $vis,
1853 }, $class;
1854 5 return $self;
1855 }
1856  
1857 2 ▶ sub name {
Subroutine name: called CC=1 SCAR=0.0
1858 2 my $self = shift;
1859 2 $self->{name};
1860 }
1861  
1862 5 ▶ sub visual {
Subroutine visual: called CC=1 SCAR=0.0
1863 5 my $self = shift;
1864 5 $self->{vis};
1865 }
1866  
1867 2 ▶ sub qr {
Subroutine qr: called CC=1 SCAR=0.0
1868 2 my $self = shift;
1869 2 "(?&$self->{name})";
1870 }
1871 }
1872  
1873  
1874 {
1875 # (*VERB) and (*VERB:arg) backtracking control verbs (Perl 5.10+)
1876 19 package Regexp::Parser::verb;
1877 19 our @ISA = qw( Regexp::Parser::__object__ );
1878  
1879 14 ▶ sub new {
Subroutine new: called CC=1 SCAR=0.0
1880 14 my ($class, $rx, $name, $arg) = @_;
1881 my $self = bless {
1882 rx => $rx,
1883 14 flags => $rx->{flags}[-1],
1884 family => 'verb',
1885 type => $name,
1886 name => $name,
1887 arg => $arg,
1888 }, $class;
1889 14 return $self;
1890 }
1891  
1892 1 ▶ sub name {
Subroutine name: called CC=1 SCAR=0.0
1893 1 my $self = shift;
1894 1 $self->{name};
1895 }
1896  
1897 1 ▶ sub arg {
Subroutine arg: called CC=1 SCAR=0.0
1898 1 my $self = shift;
1899 1 $self->{arg};
1900 }
1901  
1902 13 ▶ sub visual {
Subroutine visual: called CC=3 SCAR=11.0
1903 13 my $self = shift;
1904 13 my $v = "(*" . $self->{name};
1905 13 ▶ $v .= ":" . $self->{arg} if defined $self->{arg} && length $self->{arg};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"arg"} and length $self->{"arg"} 4 9 13
Condition66%2/3
defined $self->{"arg"} and length $self->{"arg"}
!ll&&!rl&&r
904
MC/DC50%1/2
defined $self->{"arg"} and length $self->{"arg"}
defined $self->{"arg"} length $self->{"arg"}
Truth table66%2/3
A and B
A= defined $self->{"arg"}B= length $self->{"arg"}
ABresult
0X0
100
111
1906 13 $v . ")";
1907 }
1908 }
1909  
1910  
1911 {
1912 # (?|...) branch reset group (Perl 5.10+)
1913 19 package Regexp::Parser::branch_reset;
1914 19 our @ISA = qw( Regexp::Parser::__object__ );
1915  
1916 7 ▶ sub new {
Subroutine new: called CC=1 SCAR=0.0
1917 7 my ($class, $rx, @data) = @_;
1918 my $self = bless {
1919 rx => $rx,
1920 7 flags => $rx->{flags}[-1],
1921 family => 'group',
1922 type => 'branch_reset',
1923 data => \@data,
1924 down => 1,
1925 }, $class;
1926 7 return $self;
1927 }
1928  
1929 6 ▶ sub raw {
Subroutine raw: called CC=1 SCAR=0.0
1930 6 my $self = shift;
1931 6 "(?|";
1932 }
1933  
1934 0 ▶ sub qr {
Subroutine qr: not called CC=1 SCAR=6.9
1935 0 my $self = shift;
1936 0 join "", $self->raw, map($_->qr, @{ $self->{data} }), ")";
1937 }
1938  
1939 6 ▶ sub visual {
Subroutine visual: called CC=1 SCAR=0.0
1940 6 my $self = shift;
1941 6 join "", $self->raw, map($_->visual, @{ $self->{data} }), ")";
1942 }
1943  
1944 0 ▶ sub data {
Subroutine data: not called CC=4 SCAR=30.0
1945 0 my $self = shift;
1946 0 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
1947 0 my $how = shift;
1948 0 ▶ if ($how eq '=') { $self->{data} = \@_ }
Branch: 2 branches
BranchTrueFalseTotal
if ($how eq '=') { } 0 0 0
elsif ($how eq '+') { } 0 0 0
1949 0 elsif ($how eq '+') { push @{ $self->{data} }, @_ }
1950 else {
1951 0 my $t = $self->type;
1952 0 Carp::croak("\$$t->data([+=], \@data)");
1953 }
1954 }
1955 0 $self->{data};
1956 }
1957  
1958 0 ▶ sub walk {
Subroutine walk: not called CC=2 SCAR=17.9
1959 0 my ($self, $ws, $d) = @_;
1960 0 unshift @$ws, $self->{rx}->object(@{ $self->ender });
1961 0 ▶ unshift @$ws, sub { -1 }, @{ $self->{data} }, sub { +1 } if $d;
Subroutine __ANON__: not called CC=1 SCAR=6.9
Subroutine __ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
if $d 0 0 0
1962 }
1963  
1964 7 ▶ sub insert {
Subroutine insert: called CC=1 SCAR=0.0
1965 7 my ($self, $tree) = @_;
1966 7 my $rx = $self->{rx};
1967 7 push @$tree, $self;
1968 7 push @{ $rx->{stack} }, $tree;
1969 7 $rx->{tree} = $self->{data};
1970 }
1971 }
1972  
1973  
1974 {
1975 # (*script_run:...) Script run (Perl 5.28+)
1976 19 package Regexp::Parser::script_run;
1977 19 our @ISA = qw( Regexp::Parser::assertion );
1978  
1979 2 ▶ sub new {
Subroutine new: called CC=1 SCAR=0.0
1980 2 my ($class, $rx, @data) = @_;
1981 my $self = bless {
1982 rx => $rx,
1983 2 flags => $rx->{flags}[-1],
1984 family => 'assertion',
1985 type => 'script_run',
1986 data => \@data,
1987 down => 1,
1988 }, $class;
1989 2 return $self;
1990 }
1991  
1992 2 ▶ sub raw {
Subroutine raw: called CC=1 SCAR=0.0
1993 2 my $self = shift;
1994 2 "(*script_run:";
1995 }
1996 }
1997  
1998  
1999 {
2000 # (*atomic_script_run:...) / (*asr:...) Atomic script run (Perl 5.28+)
2001 19 package Regexp::Parser::asr;
2002 19 our @ISA = qw( Regexp::Parser::assertion );
2003  
2004 2 ▶ sub new {
Subroutine new: called CC=1 SCAR=0.0
2005 2 my ($class, $rx, @data) = @_;
2006 my $self = bless {
2007 rx => $rx,
2008 2 flags => $rx->{flags}[-1],
2009 family => 'assertion',
2010 type => 'asr',
2011 data => \@data,
2012 down => 1,
2013 }, $class;
2014 2 return $self;
2015 }
2016  
2017 2 ▶ sub raw {
Subroutine raw: called CC=1 SCAR=0.0
2018 2 my $self = shift;
2019 2 "(*asr:";
2020 }
2021 }
2022 19 1;
2023  
2024 __END__
« Perl6/Rule/Parser.pm ↑ Summary Regexp/Parser/Handlers.pm »