Regexp/Structure/Quantifier.pm

filter: Statementstmt 94.3% 67 / 71 Branchbran 75.0% 36 / 48 Conditioncond 73.3% 11 / 15 MC/DCmcdc 60.0% 6 / 10 Subroutinesub 80.0% 12 / 15 Podpod 100% 4 / 4 totaltotal 83.4% 136 / 163 CC 33 SCAR 21.7
CC
33
Cov
85%
__PPIX_LEXER__finalize
16.3
_min_max
9.0
__quantified_width
7.3
CRAP 8.7
« Regexp/Token/Modifier.pm ↑ Summary Regexp/Tokenizer.pm »
1 =head1 NAME
2  
3 PPIx::Regexp::Structure::Quantifier - Represent curly bracket quantifiers
4  
5 =head1 SYNOPSIS
6  
7 use PPIx::Regexp::Dumper;
8 PPIx::Regexp::Dumper->new( 'qr{fo{2,}}smx' )
9 ->print();
10  
11 =head1 INHERITANCE
12  
13 C<PPIx::Regexp::Structure::Quantifier> is a
14 L<PPIx::Regexp::Structure|PPIx::Regexp::Structure>.
15  
16 C<PPIx::Regexp::Structure::Quantifier> has no descendants.
17  
18 =head1 DESCRIPTION
19  
20 This class represents curly bracket quantifiers such as C<{3}>, C<{3,}>
21 and C<{3,5}>. The contents are left as literals or interpolations.
22  
23 B<Note> that if they occur inside a variable-length look-behind,
24 quantifiers with different low and high limits (such as C<'{1,3}'> imply
25 a minimum Perl version of C<5.29.9>. Quantifiers specifying more than
26 255 characters are regarded as parse errors and reblessed into the
27 unknown structure.
28  
29 =head1 METHODS
30  
31 This class provides no public methods beyond those provided by its
32 superclass.
33  
34 =cut
35  
36 package PPIx::Regexp::Structure::Quantifier;
37  
38 9 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
39 9 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
40  
41 9 ▶use base qw{ PPIx::Regexp::Structure };
Subroutine BEGIN: called CC=1 SCAR=0.0
42  
43 9 ▶use Scalar::Util qw{ looks_like_number };
Subroutine BEGIN: called CC=1 SCAR=0.0
44  
45 9 ▶use PPIx::Regexp::Constant qw{
Subroutine BEGIN: called CC=1 SCAR=0.0
46 INFINITY
47 LITERAL_LEFT_CURLY_ALLOWED
48 MINIMUM_PERL
49 MSG_LOOK_BEHIND_TOO_LONG
50 STRUCTURE_UNKNOWN
51 VARIABLE_LENGTH_LOOK_BEHIND_INTRODUCED
52 @CARP_NOT
53 9 };
54  
55 9 our $VERSION = '0.092';
56  
57 0 ▶sub can_be_quantified {
Subroutine can_be_quantified: not called CC=1 SCAR=6.9
Pod documented
58 0 return;
59 }
60  
61 4 ▶sub explain {
Subroutine explain: called CC=6 SCAR=18.0
Pod documented
62 4 my ( $self ) = @_;
63  
64 =begin comment
65  
66 my $content = $self->content();
67 if ( $content =~ m/ \A [{] ( .*? ) [}] \z /smx ) {
68 my $quant = $1;
69 my ( $lo, $hi ) = split qr{ , }smx, $quant;
70 foreach ( $lo, $hi ) {
71 defined
72 or next;
73 s/ \A \s+ //smx;
74 s/ \s+ \z //smx;
75 }
76 defined $lo
77 and '' ne $lo
78 or $lo = '0';
79 defined $hi
80 and '' ne $hi
81 and return "match $lo to $hi times";
82 $quant =~ m/ , \z /smx
83 and return "match $lo or more times";
84 $lo =~ m/ [^0-9] /smx
85 and return "match $lo times";
86 return "match exactly $lo times";
87 }
88 return $self->SUPER::explain();
89  
90 =end comment
91  
92 =cut
93  
94 4 my ( $lo, $hi ) = $self->_min_max();
95  
96 4 ▶ if ( looks_like_number( $hi ) ) {
Branch: 2 branches
BranchTrueFalseTotal
if (&looks_like_number($hi)) { } 3 1 4
elsif ($lo eq $hi) { } 1 0 1
97 3 ▶ $hi == INFINITY
Branch: 1 branch
BranchTrueFalseTotal
$hi == "Inf" and return "match $lo or more times" 1 2 3
98 and return "match $lo or more times";
99 2 ▶ looks_like_number( $lo )
Branch: 1 branch
BranchTrueFalseTotal
&looks_like_number($lo) and $lo == $hi and return "match exactly $lo times" 1 1 2
Condition66%2/3
&looks_like_number($lo) and $lo == $hi
!ll&&!rl&&r
011
MC/DC50%1/2
&looks_like_number($lo) and $lo == $hi
&looks_like_number($lo) $lo == $hi
Truth table66%2/3
A and B
A= &looks_like_number($lo)B= $lo == $hi
ABresult
0X0
100
111
100 and $lo == $hi
101 and return "match exactly $lo times";
102 } elsif ( $lo eq $hi ) {
103 1 return "match $lo times";
104 }
105 1 return "match $lo to $hi times";
106 }
107  
108 39 ▶sub _min_max {
Subroutine _min_max: called CC=9 SCAR=22.0
109 39 my ( $self ) = @_;
110 39 my $content = $self->content();
111 39 ▶ if ( $content =~ m/ \A [{] ( .*? ) [}] \z /smx ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($content =~ / \A [{] ( .*? ) [}] \z /msx) 39 0 39
112 39 my $quant = $1;
113 39 my ( $lo, $hi ) = split qr{ , }smx, $quant;
114 39 foreach ( $lo, $hi ) {
115 defined
116 78 ▶ or next;
Branch: 1 branch
BranchTrueFalseTotal
defined $_ or next 71 7 78
117 71 s/ \A \s+ //smx;
118 71 s/ \s+ \z //smx;
119 }
120 39 ▶ defined $lo
Branch: 1 branch
BranchTrueFalseTotal
defined $lo and "" ne $lo or $lo = 0 24 15 39
Condition66%2/3
defined $lo and "" ne $lo
!ll&&!rl&&r
01524
MC/DC50%1/2
defined $lo and "" ne $lo
defined $lo "" ne $lo
Truth table66%2/3
A and B
A= defined $loB= "" ne $lo
ABresult
0X0
100
111
121 and '' ne $lo
122 or $lo = 0;
123 39 ▶ defined $hi
Branch: 1 branch
BranchTrueFalseTotal
defined $hi and "" ne $hi and return $lo, $hi 26 13 39
Condition100%3/3
defined $hi and "" ne $hi
!ll&&!rl&&r
7626
MC/DC100%2/2
defined $hi and "" ne $hi
defined $hi "" ne $hi
Truth table100%3/3
A and B
A= defined $hiB= "" ne $hi
ABresult
0X0
100
111
124 and '' ne $hi
125 and return ( $lo, $hi );
126 13 ▶ $quant =~ m/ , \z /smx
Branch: 1 branch
BranchTrueFalseTotal
$quant =~ / , \z /msx and return $lo, "Inf" 6 7 13
127 and return ( $lo, INFINITY );
128 7 return ( $lo, $lo );
129 }
130 }
131  
132 0 ▶sub is_quantifier {
Subroutine is_quantifier: not called CC=1 SCAR=6.9
Pod documented
133 0 return 1;
134 }
135  
136 35 ▶sub width {
Subroutine width: called CC=1 SCAR=0.0
Pod documented
137 35 return ( 0, 0 );
138 }
139  
140 35 ▶sub __quantified_width {
Subroutine __quantified_width: called CC=7 SCAR=19.8
141 35 my ( $self, $raw_min, $raw_max ) = @_;
142 35 my ( $my_min, $my_max ) = $self->_min_max();
143 35 foreach ( $my_min, $my_max ) {
144 70 ▶ looks_like_number( $_ )
Branch: 1 branch
BranchTrueFalseTotal
&looks_like_number($_) or $_ = undef 60 10 70
145 or $_ = undef;
146 }
147 35 ▶ defined $raw_min
Branch: 2 branches
BranchTrueFalseTotal
defined $raw_min and $raw_min = defined $my_min ? $raw_min * $my_min : undef 35 0 35
defined $my_min ? : 35 0 35
148 and $raw_min = defined $my_min ? $raw_min * $my_min : undef;
149 35 ▶ defined $raw_max
Branch: 2 branches
BranchTrueFalseTotal
defined $raw_max and $raw_max = defined $my_max ? $raw_max * $my_max : undef 35 0 35
defined $my_max ? : 25 10 35
150 and $raw_max = defined $my_max ? $raw_max * $my_max : undef;
151 35 return ( $raw_min, $raw_max );
152 }
153  
154 0 ▶sub __following_literal_left_curly_disallowed_in {
Subroutine __following_literal_left_curly_disallowed_in: not called CC=1 SCAR=6.9
155 0 return LITERAL_LEFT_CURLY_ALLOWED;
156 }
157  
158 1 ▶sub _too_big {
Subroutine _too_big: called CC=1 SCAR=0.0
159 1 my ( $self ) = @_;
160 1 STRUCTURE_UNKNOWN->__PPIX_ELEM__rebless( $self,
161 error => MSG_LOOK_BEHIND_TOO_LONG,
162 );
163 1 return 1;
164 }
165  
166 29 ▶sub __PPIX_LEXER__finalize {
Subroutine __PPIX_LEXER__finalize: called CC=14 SCAR=27.9
167 29 my ( $self ) = @_;
168  
169 29 my $content = $self->content();
170  
171 29 ▶ if ( $self->__in_look_behind() ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->__in_look_behind) 2 27 29
172 2 ▶ if ( $content =~ m/ \A [{] ( .*? ) [}] \z /smx ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($content =~ / \A [{] ( .*? ) [}] \z /msx) 2 0 2
173 2 my $quant = $1;
174  
175 2 ▶ $quant =~ m/ , \z /smx
Branch: 1 branch
BranchTrueFalseTotal
$quant =~ / , \z /msx and return $self->_too_big 1 1 2
176 and return $self->_too_big();
177  
178 1 my ( $lo, $hi ) = split qr{ , }smx, $quant;
179  
180 1 ▶ defined $hi
Branch: 1 branch
BranchTrueFalseTotal
defined $hi or $hi = $lo 1 0 1
181 or $hi = $lo;
182  
183 1 my $numeric = 1;
184 1 foreach ( $lo, $hi ) {
185 2 ▶ if ( m/ \A [0-9]+ \z /smx ) {
Branch: 1 branch
BranchTrueFalseTotal
if (/ \A [0-9]+ \z /msx) { } 2 0 2
186 2 ▶ $_ >= 256
Branch: 1 branch
BranchTrueFalseTotal
$_ >= 256 and return $self->_too_big 0 2 2
187 and return $self->_too_big();
188 } else {
189 0 $numeric = 0;
190 }
191 }
192  
193 1 ▶ if ( $numeric && $lo != $hi ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($numeric and $lo != $hi) 1 0 1
Condition33%1/3
$numeric and $lo != $hi
!ll&&!rl&&r
001
MC/DC0%0/2
$numeric and $lo != $hi
$numeric $lo != $hi
Truth table33%1/3
A and B
A= $numericB= $lo != $hi
ABresult
0X0
100
111
194  
195 1 ▶ if ( my $finish = $self->finish() ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $finish = $self->finish) 1 0 1
196 $finish->perl_version_introduced() lt
197 VARIABLE_LENGTH_LOOK_BEHIND_INTRODUCED
198 and $finish->{perl_version_introduced} =
199 1 ▶ VARIABLE_LENGTH_LOOK_BEHIND_INTRODUCED;
Branch: 1 branch
BranchTrueFalseTotal
$finish->perl_version_introduced lt "5.029009" and $finish->{"perl_version_introduced"} = "5.029009" 1 0 1
200 }
201  
202 }
203 }
204 }
205  
206 ( $content =~ m/ \s /smx or $content =~ m/ \A \{ , /smx )
207 28 ▶ and $self->finish()->{perl_version_introduced} = '5.033006';
Branch: 1 branch
BranchTrueFalseTotal
$content =~ / \s /msx || $content =~ / \A \{ , /msx and $self->finish->{"perl_version_introduced"} = "5.033006" 6 22 28
Condition100%3/3
$content =~ / \s /msx or $content =~ / \A \{ , /msx
l!l&&r!l&&!r
1522
MC/DC100%2/2
$content =~ / \s /msx or $content =~ / \A \{ , /msx
$content =~ / \s /msx $content =~ / \A \{ , /msx
Truth table100%3/3
A or B
A= $content =~ / \s /msxB= $content =~ / \A \{ , /msx
ABresult
1X1
011
000
208  
209 28 return 0;
210 }
211  
212 # Called by the lexer to record the capture number.
213 28 ▶sub __PPIX_LEXER__record_capture_number {
Subroutine __PPIX_LEXER__record_capture_number: called CC=1 SCAR=0.0
214 28 my ( undef, $number ) = @_; # Invocant unused
215 28 return $number;
216 }
217  
218 9 1;
219  
220 __END__
« Regexp/Token/Modifier.pm ↑ Summary Regexp/Tokenizer.pm »