blib/lib/Text/DelimMatch.pm

filter: Statementstmt 83.2% 323 / 388 Branchbran 63.6% 140 / 220 Conditioncond 59.7% 43 / 72 MC/DCmcdc 33.3% 15 / 45 Subroutinesub 75.0% 18 / 24 Podpod 100% 19 / 19 totaltotal 72.6% 558 / 768 CC 137 SCAR 32.4
CC
137
Cov
74%
match
58.3
double_escape
13.2
quote
12.7
CRAP 25.5
↑ Summary
1 package Text::DelimMatch;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use vars qw($VERSION @ISA @EXPORT $case_sensitive);
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 1 require 5.000;
7 1 require Exporter;
8 1 require AutoLoader;
9  
10 1 @ISA = qw(Exporter AutoLoader);
11 1 @EXPORT = qw();
12 1 $VERSION = '1.06';
13  
14 4 ▶sub new {
Subroutine new: called CC=9 SCAR=22.8
Pod documented
15 4 my $type = shift;
16 4 my $start = shift;
17 4 ▶ my $end = shift || $start;
Condition66%2/3
shift() || $start
l!l&&r!l&&!r
310
MC/DC0%0/2
shift() || $start
shift() $start
Truth table66%2/3
A || B
A= shift()B= $start
ABresult
1X1
011
000
18 4 my $esc = shift;
19 4 my $dblesc= shift;
20 4 ▶ my $class = ref($type) || $type;
Condition33%1/3
ref $type || $type
l!l&&r!l&&!r
040
MC/DC0%0/2
ref $type || $type
ref $type $type
Truth table33%1/3
A || B
A= ref $typeB= $type
ABresult
1X1
011
000
21 4 my $self = bless {}, $class;
22 4 local $_ = "no -w warning in evals now";
23  
24 4 ▶ eval "/$start/" if defined($start);
Branch: 1 branch
BranchTrueFalseTotal
if defined $start 4 0 4
25 4 ▶ eval "/$end/" if !$@ && defined($end);
Branch: 1 branch
BranchTrueFalseTotal
if not $@ and defined $end 4 0 4
Condition33%1/3
not $@ and defined $end
!ll&&!rl&&r
004
MC/DC0%0/2
not $@ and defined $end
not $@ defined $end
Truth table33%1/3
not(A) and B
A= not $@B= defined $end
ABresult
0X0
100
111
26  
27 4 $self->{'STARTREGEXP'} = $start; # a regexp
28 4 $self->{'ENDREGEXP'} = $end; # a regexp
29 4 $self->{'QUOTE'} = {}; # a hash of regexp, start => end
30 4 $self->{'ESCAPE'} = ""; # a regexp set of chars
31 4 $self->{'DBLESCAPE'} = ""; # a regexp set of chars
32  
33 4 $self->{'ERROR'} = $@; # false if OK
34 4 $self->{'DEBUG'} = 0; # boolean
35 4 $self->{'CASESENSE'} = 0; # boolean
36 4 $self->{'FORCESLOW'} = 0; # boolean
37 4 $self->{'KEEP'} = 1; # boolean
38 4 $self->{'RETURNDELIM'} = 1; # boolean
39  
40 4 $self->{'BUFFER'} = "";
41 4 $self->{'PRE'} = "";
42 4 $self->{'MATCH'} = "";
43 4 $self->{'POST'} = "";
44  
45 4 ▶ $self->escape($esc) if $esc;
Branch: 1 branch
BranchTrueFalseTotal
if $esc 0 4 4
46 4 ▶ $self->double_escape($dblesc) if $dblesc;
Branch: 1 branch
BranchTrueFalseTotal
if $dblesc 0 4 4
47 4 ▶ $self->quote(@_) if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 4 4
48  
49 4 return $self;
50 }
51  
52 3 ▶sub delim {
Subroutine delim: called CC=7 SCAR=23.2
Pod documented
53 3 my $self = shift;
54 3 my $start = shift;
55 3 ▶ my $end = shift || $start;
Condition33%1/3
shift() || $start
l!l&&r!l&&!r
300
MC/DC0%0/2
shift() || $start
shift() $start
Truth table33%1/3
A || B
A= shift()B= $start
ABresult
1X1
011
000
56 3 my $curs = $self->{'STARTREGEXP'};
57 3 my $cure = $self->{'ENDREGEXP'};
58 3 local $_ = "no -w warning in evals now";
59  
60 3 ▶ eval "/$start/" if defined($start);
Branch: 1 branch
BranchTrueFalseTotal
if defined $start 3 0 3
61 3 ▶ eval "/$end/" if !$@ && defined($end);
Branch: 1 branch
BranchTrueFalseTotal
if not $@ and defined $end 3 0 3
Condition33%1/3
not $@ and defined $end
!ll&&!rl&&r
003
MC/DC0%0/2
not $@ and defined $end
not $@ defined $end
Truth table33%1/3
not(A) and B
A= not $@B= defined $end
ABresult
0X0
100
111
62  
63 3 $self->{'ERROR'} = $@; # false if OK
64 3 $self->{'STARTREGEXP'} = $start;
65 3 $self->{'ENDREGEXP'} = $end;
66  
67 3 ▶ if ($self->{'DEBUG'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"DEBUG"}) 0 3 3
68 0 print "DELIM : $start, $end";
69 0 ▶ print ": ", $self->{'ERROR'} if $self->{'ERROR'};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"ERROR"} 0 0 0
70 0 print "\n";
71 }
72  
73 3 return ($curs, $cure);
74 }
75  
76 5 ▶sub quote {
Subroutine quote: called CC=10 SCAR=25.4
Pod documented
77 5 my $self = shift;
78 5 my (%oldq) = %{$self->{'QUOTE'}};
79 5 local $_ = "no -w warning in evals now";
80 5 my ($key, $val);
81  
82 5 $key = shift @_;
83  
84 5 ▶ if (!defined($key)) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $key) { } 2 3 5
85 2 $self->{'QUOTE'} = {};
86 } else {
87 3 ▶ while ($key) {
Branch: 1 branch
BranchTrueFalseTotal
if ($key) 3 3 6
88 3 ▶ $val = shift @_ || $key;
Condition66%2/3
shift @_ || $key
l!l&&r!l&&!r
120
MC/DC0%0/2
shift @_ || $key
shift @_ $key
Truth table66%2/3
A || B
A= shift @_B= $key
ABresult
1X1
011
000
89  
90 3 ▶ eval "/$key/" if defined($key);
Branch: 1 branch
BranchTrueFalseTotal
if defined $key 3 0 3
91 3 ▶ eval "/$val/" if !$@ && defined($val);
Branch: 1 branch
BranchTrueFalseTotal
if not $@ and defined $val 3 0 3
Condition33%1/3
not $@ and defined $val
!ll&&!rl&&r
003
MC/DC0%0/2
not $@ and defined $val
not $@ defined $val
Truth table33%1/3
not(A) and B
A= not $@B= defined $val
ABresult
0X0
100
111
92 3 ▶ $self->{'ERROR'} = $@ if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 3 3
93  
94 3 ▶ if ($self->{'DEBUG'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"DEBUG"}) 0 3 3
95 0 print "QUOTE : $key = $val";
96 0 ▶ print ": ", $self->{'ERROR'} if $self->{'ERROR'};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"ERROR"} 0 0 0
97 0 print "\n";
98 }
99  
100 3 $self->{'QUOTE'}->{$key} = $val;
101 3 $key = shift @_;
102 }
103 }
104  
105 5 return %oldq;
106 }
107  
108 3 ▶sub escape {
Subroutine escape: called CC=8 SCAR=22.8
Pod documented
109 3 my $self = shift;
110 3 my $esc = shift;
111 3 my $curesc = $self->{'ESCAPE'};
112 3 local $_ = "no -w warning in evals now";
113  
114 3 ▶ $esc = '[' . quotemeta($esc) . ']' if defined($esc) && ($esc ne "");
Branch: 1 branch
BranchTrueFalseTotal
if defined $esc and $esc ne "" 2 1 3
Condition66%2/3
defined $esc and $esc ne ""
!ll&&!rl&&r
102
MC/DC50%1/2
defined $esc and $esc ne ""
defined $esc $esc ne ""
Truth table66%2/3
A and B
A= defined $escB= $esc ne ""
ABresult
0X0
100
111
115  
116 3 ▶ if (defined($esc) && ($esc ne "")) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $esc and $esc ne "") 2 1 3
Condition66%2/3
defined $esc and $esc ne ""
!ll&&!rl&&r
102
MC/DC50%1/2
defined $esc and $esc ne ""
defined $esc $esc ne ""
Truth table66%2/3
A and B
A= defined $escB= $esc ne ""
ABresult
0X0
100
111
117 2 eval "/$esc/";
118 2 ▶ $self->{'ERROR'} = $@ if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 2 2
119 }
120  
121 3 $self->{'ESCAPE'} = $esc;
122  
123 3 ▶ if ($self->{'DEBUG'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"DEBUG"}) 0 3 3
124 0 print "ESCAPE: $esc";
125 0 ▶ print ": ", $self->{'ERROR'} if $self->{'ERROR'};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"ERROR"} 0 0 0
126 0 print "\n";
127 }
128  
129 3 return $curesc;
130 }
131  
132 1 ▶sub double_escape {
Subroutine double_escape: called CC=8 SCAR=25.8
Pod documented
133 1 my $self = shift;
134 1 my $esc = shift;
135 1 my $curesc = $self->{'DBLESCAPE'};
136 1 local $_ = "no -w warning in evals now";
137  
138 1 ▶ $esc = '[' . quotemeta($esc) . ']' if defined($esc) && ($esc ne "");
Branch: 1 branch
BranchTrueFalseTotal
if defined $esc and $esc ne "" 1 0 1
Condition33%1/3
defined $esc and $esc ne ""
!ll&&!rl&&r
001
MC/DC0%0/2
defined $esc and $esc ne ""
defined $esc $esc ne ""
Truth table33%1/3
A and B
A= defined $escB= $esc ne ""
ABresult
0X0
100
111
139  
140 1 ▶ if (defined($esc) && ($esc ne "")) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $esc and $esc ne "") 1 0 1
Condition33%1/3
defined $esc and $esc ne ""
!ll&&!rl&&r
001
MC/DC0%0/2
defined $esc and $esc ne ""
defined $esc $esc ne ""
Truth table33%1/3
A and B
A= defined $escB= $esc ne ""
ABresult
0X0
100
111
141 1 eval "/$esc/";
142 1 ▶ $self->{'ERROR'} = $@ if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 1 1
143 }
144  
145 1 $self->{'DBLESCAPE'} = $esc;
146  
147 1 ▶ if ($self->{'DEBUG'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"DEBUG"}) 0 1 1
148 0 print "DBLESC: $esc";
149 0 ▶ print ": ", $self->{'ERROR'} if $self->{'ERROR'};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"ERROR"} 0 0 0
150 0 print "\n";
151 }
152  
153 1 return $curesc;
154 }
155  
156 1 ▶sub case_sensitive {
Subroutine case_sensitive: called CC=3 SCAR=11.6
Pod documented
157 1 my $self = shift;
158 1 my $setsense = shift;
159 1 my $cursense = $self->{'CASESENSE'};
160  
161 1 ▶ $self->{'CASESENSE'} = $setsense || !defined($setsense);
Condition33%1/3
$setsense || !defined($setsense)
l!l&&r!l&&!r
100
MC/DC0%0/2
$setsense || !defined($setsense)
$setsense !defined($setsense)
Truth table33%1/3
A || not(B)
A= $setsenseB= !defined($setsense)
ABresult
1X1
011
000
162  
163 print "CASE : ", $self->{'CASESENSE'}, "\n"
164 1 ▶ if $self->{'DEBUG'};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"DEBUG"} 0 1 1
165  
166 1 return $cursense;
167 }
168  
169 4 ▶sub slow {
Subroutine slow: called CC=3 SCAR=11.2
Pod documented
170 4 my $self = shift;
171 4 my $setslow = shift;
172 4 my $curslow = $self->{'FORCESLOW'};
173  
174 4 ▶ $self->{'FORCESLOW'} = $setslow || !defined($setslow);
Condition66%2/3
$setslow || !defined($setslow)
l!l&&r!l&&!r
202
MC/DC50%1/2
$setslow || !defined($setslow)
$setslow !defined($setslow)
Truth table66%2/3
A || not(B)
A= $setslowB= !defined($setslow)
ABresult
1X1
011
000
175  
176 print "GOSLOW: ", $self->{'FORCESLOW'}, "\n"
177 4 ▶ if $self->{'DEBUG'};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"DEBUG"} 0 4 4
178  
179 4 return $curslow;
180 }
181  
182 1 ▶sub keep {
Subroutine keep: called CC=3 SCAR=11.6
Pod documented
183 1 my $self = shift;
184 1 my $setkeep = shift;
185 1 my $curkeep = $self->{'KEEP'};
186  
187 1 ▶ $self->{'KEEP'} = $setkeep || !defined($setkeep);
Condition33%1/3
$setkeep || !defined($setkeep)
l!l&&r!l&&!r
001
MC/DC0%0/2
$setkeep || !defined($setkeep)
$setkeep !defined($setkeep)
Truth table33%1/3
A || not(B)
A= $setkeepB= !defined($setkeep)
ABresult
1X1
011
000
188  
189 print "KEEP : ", $self->{'KEEP'}, "\n"
190 1 ▶ if $self->{'DEBUG'};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"DEBUG"} 0 1 1
191  
192 1 return $curkeep;
193 }
194  
195 2 ▶sub returndelim {
Subroutine returndelim: called CC=3 SCAR=11.2
Pod documented
196 2 my $self = shift;
197 2 my $setrd = shift;
198 2 my $currd = $self->{'RETURNDELIM'};
199  
200 2 ▶ $self->{'RETURNDELIM'} = $setrd || !defined($setrd);
Condition66%2/3
$setrd || !defined($setrd)
l!l&&r!l&&!r
101
MC/DC50%1/2
$setrd || !defined($setrd)
$setrd !defined($setrd)
Truth table66%2/3
A || not(B)
A= $setrdB= !defined($setrd)
ABresult
1X1
011
000
201  
202 print "RETURNDELIM : ", $self->{'RETURNDELIM'}, "\n"
203 2 ▶ if $self->{'DEBUG'};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"DEBUG"} 0 2 2
204  
205 2 return $currd;
206 }
207  
208 0 ▶sub debug {
Subroutine debug: not called CC=3 SCAR=24.8
Pod documented
209 0 my $self = shift;
210 0 my $setdebug = shift;
211 0 my $curdebug = $self->{'DEBUG'};
212  
213 0 ▶ $self->{'DEBUG'} = $setdebug || !defined($setdebug);
Condition0%0/3
$setdebug || !defined($setdebug)
l!l&&r!l&&!r
000
MC/DC0%0/2
$setdebug || !defined($setdebug)
$setdebug !defined($setdebug)
Truth table0%0/3
A || not(B)
A= $setdebugB= !defined($setdebug)
ABresult
1X1
011
000
214  
215 print "DEBUG : ", $self->{'DEBUG'}, "\n"
216 0 ▶ if $self->{'DEBUG'};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"DEBUG"} 0 0 0
217  
218 0 return $curdebug;
219 }
220  
221 0 ▶sub error {
Subroutine error: not called CC=2 SCAR=17.9
Pod documented
222 0 my $self = shift;
223 0 my $seterr = shift;
224 0 my $curerr = $self->{'ERROR'};
225  
226 0 ▶ $self->{'ERROR'} = $seterr if defined($seterr);
Branch: 1 branch
BranchTrueFalseTotal
if defined $seterr 0 0 0
227 0 return $curerr;
228 }
229  
230 0 ▶sub pre_matched {
Subroutine pre_matched: not called CC=2 SCAR=17.9
Pod documented
231 0 my $self = shift;
232 0 ▶ $self->{'ERROR'} = "pre_matched requires keep" if !$self->{'KEEP'};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"KEEP"} 0 0 0
233 0 return $self->{'PRE'};
234 }
235  
236 0 ▶sub matched {
Subroutine matched: not called CC=2 SCAR=17.9
Pod documented
237 0 my $self = shift;
238 0 ▶ $self->{'ERROR'} = "matched requires keep" if !$self->{'KEEP'};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"KEEP"} 0 0 0
239 0 return $self->{'MATCH'};
240 }
241  
242 0 ▶sub post_matched {
Subroutine post_matched: not called CC=2 SCAR=17.9
Pod documented
243 0 my $self = shift;
244 0 ▶ $self->{'ERROR'} = "post_matched requires keep" if !$self->{'KEEP'};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"KEEP"} 0 0 0
245 0 return $self->{'POST'};
246 }
247  
248 0 ▶sub dump {
Subroutine dump: not called CC=3 SCAR=24.8
Pod documented
249 0 my $self = shift;
250 0 my ($key, $val);
251  
252 0 print "Dump of Text::DelimMatch:\n";
253  
254 print "\n\tERROR : ", $self->{'ERROR'}, "\n"
255 0 ▶ if $self->{'ERROR'};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"ERROR"} 0 0 0
256  
257 0 print "\tStart : ", $self->{'STARTREGEXP'}, "\n";
258 0 print "\tEnd : ", $self->{'ENDREGEXP'}, "\n";
259 0 print "\tEscape: ", $self->{'ESCAPE'}, "\n";
260 0 print "\tDblEsc: ", $self->{'DBLESCAPE'}, "\n";
261 0 print "\tDebug : ", $self->{'DEBUG'}, "\n";
262 0 print "\tCase : ", $self->{'CASESENSE'}, "\n";
263 0 print "\tSlow : ", $self->{'FORCESLOW'}, "\n";
264 0 print "\tKeep : ", $self->{'KEEP'}, "\n";
265 0 print "\tQuote :\n";
266 0 ▶ while (($key, $val) = each %{$self->{'QUOTE'}}) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %{$$self{"QUOTE"};}) 0 0 0
267 0 print "\t\t$key ... $val\n";
268 }
269 0 print "\tBuffer: ", $self->{'BUFFER'}, "\n";
270 0 print "\tPrefix: ", $self->{'PRE'}, "\n";
271 0 print "\tMatch : ", $self->{'MATCH'}, "\n";
272 0 print "\tPost : ", $self->{'POST'}, "\n\n";
273 }
274  
275 46 ▶sub match {
Subroutine match: called CC=55 SCAR=40.6
Pod documented
276 46 my $self = shift;
277 46 my $string = shift;
278 46 my $state = 0;
279 46 my $start = $self->{'STARTREGEXP'};
280 46 my $end = $self->{'ENDREGEXP'};
281 46 my %quote = %{$self->{'QUOTE'}};
282 46 my $escape = $self->{'ESCAPE'};
283 46 my $dblesc = $self->{'DBLESCAPE'};
284 46 my $debug = $self->{'DEBUG'};
285 46 my ($startq, $endq, $specialq) = ("", "", "");
286 46 my ($done) = 0;
287 46 my ($depth) = 0;
288 46 my (@states) = ();
289 46 my ($accum) = "";
290 46 my ($regexp, $match, $pre, $matched, $post);
291 46 my ($scratch);
292 46 local $_ = "no -w warning in evals now";
293  
294 46 ▶ return if $self->{'ERROR'};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"ERROR"} 0 46 46
295  
296 46 ▶ if (defined($string)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $string) { } 44 2 46
297 44 $self->{'BUFFER'} = $string;
298 } else {
299 # use post of previous match, if there was a match previously
300 2 ▶ $self->{'BUFFER'} = $self->{'POST'} if $self->{'MATCH'}
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"MATCH"} 1 1 2
301 }
302  
303 46 $self->{'PRE'} = "";
304 46 $self->{'MATCH'} = "";
305 46 $self->{'POST'} = "";
306  
307 46 ▶ if (!%quote && !$escape && !$dblesc && !$self->{'FORCESLOW'}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (%quote or $escape or $dblesc or $self->{"FORCESLOW"}) 17 29 46
Condition88%8/9
%quote or $escape or $dblesc or $self->{"FORCESLOW"}
l!l&&r!l&&!r
171217
%quote or $escape or $dblesc
l!l&&r!l&&!r
17029
%quote or $escape
l!l&&r!l&&!r
15229
MC/DC75%3/4
%quote or $escape or $dblesc or $self->{"FORCESLOW"}
%quote $escape $dblesc $self->{"FORCESLOW"}
Truth table80%4/5
A or B or C or D
A= %quoteB= $escapeC= $dblescD= $self->{"FORCESLOW"}
ABCDresult
1XXX1
01XX1
001X1
00011
00000
308 17 ▶ print "FAST: $start, $end\n" if $debug;
Branch: 1 branch
BranchTrueFalseTotal
if $debug 0 17 17
309 17 ▶ return $self->_fast0() if $start eq $end;
Branch: 1 branch
BranchTrueFalseTotal
if $start eq $end 5 12 17
310 12 return $self->_fast1();
311 }
312  
313 # build the regexp that matches the next important thing
314  
315 29 ▶ if (%quote) {
Branch: 1 branch
BranchTrueFalseTotal
if (%quote) 15 14 29
316 15 $startq = join (")|(", keys %quote);
317 15 $startq = "($startq)";
318 }
319  
320 29 ▶ if ($escape || $dblesc) {
Branch: 1 branch
BranchTrueFalseTotal
if ($escape or $dblesc) 13 16 29
Condition100%3/3
$escape or $dblesc
l!l&&r!l&&!r
12116
MC/DC100%2/2
$escape or $dblesc
$escape $dblesc
Truth table100%3/3
A or B
A= $escapeB= $dblesc
ABresult
1X1
011
000
321 13 ▶ if ($escape && $dblesc) {
Branch: 2 branches
BranchTrueFalseTotal
if ($escape and $dblesc) { } 10 3 13
elsif ($escape) { } 2 1 3
Condition100%3/3
$escape and $dblesc
!ll&&!rl&&r
1210
MC/DC100%2/2
$escape and $dblesc
$escape $dblesc
Truth table100%3/3
A and B
A= $escapeB= $dblesc
ABresult
0X0
100
111
322 10 $specialq = "($escape)|($dblesc)";
323 } elsif ($escape) {
324 2 $specialq = "($escape)";
325 } else {
326 1 $specialq = "($dblesc)";
327 }
328 }
329  
330 29 $_ = $self->{'BUFFER'};
331 29 $self->{'BUFFER'} = "";
332 29 ▶ while ($state != 3) {
Branch: 1 branch
BranchTrueFalseTotal
if ($state != 3) 103 22 125
333 103 ▶ if ($state == 0) { # before start tag
Branch: 3 branches
BranchTrueFalseTotal
if ($state == 0) { } 44 59 103
elsif ($state == 1) { } 47 12 59
elsif ($state == 2) { } 12 0 12
334 44 $regexp = "($start)";
335 44 ▶ $regexp .= "|$startq" if $startq;
Branch: 1 branch
BranchTrueFalseTotal
if $startq 29 15 44
336 44 ▶ $regexp .= "|($escape)" if $escape;
Branch: 1 branch
BranchTrueFalseTotal
if $escape 20 24 44
337 } elsif ($state == 1) { # in start tag
338 47 $regexp = "($start)|($end)";
339 47 ▶ $regexp .= "|$startq" if $startq;
Branch: 1 branch
BranchTrueFalseTotal
if $startq 22 25 47
340 47 ▶ $regexp .= "|($escape)" if $escape;
Branch: 1 branch
BranchTrueFalseTotal
if $escape 20 27 47
341 } elsif ($state == 2) { # in quote
342 12 $regexp = $endq;
343 12 ▶ $regexp .= "|$specialq" if $specialq;
Branch: 1 branch
BranchTrueFalseTotal
if $specialq 6 6 12
344 } else {
345 0 $self->{'ERROR'} = "BAD STATE! THIS CAN'T HAPPEN!";
346 0 return;
347 }
348  
349 103 ▶ print "STATE: $state: $regexp\n" if $debug;
Branch: 1 branch
BranchTrueFalseTotal
if $debug 0 103 103
350  
351 103 ($pre, $matched, $post) = $self->_match($regexp, $_);
352  
353 103 ▶ print "\tSTR : $_\n" if $debug;
Branch: 1 branch
BranchTrueFalseTotal
if $debug 0 103 103
354 103 ▶ print "\tPRE : $pre\n" if $debug;
Branch: 1 branch
BranchTrueFalseTotal
if $debug 0 103 103
355 103 ▶ print "\tMTCH: $matched\n" if $debug;
Branch: 1 branch
BranchTrueFalseTotal
if $debug 0 103 103
356 103 ▶ print "\tPOST: $post\n" if $debug;
Branch: 1 branch
BranchTrueFalseTotal
if $debug 0 103 103
357  
358 103 ▶ last if !$matched;
Branch: 1 branch
BranchTrueFalseTotal
unless $matched 7 96 103
359  
360 # First things first, if we've encountered an escaped
361 # character, move along
362 96 ▶ if ($escape && $self->_match ($escape, $matched)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($escape and $self->_match($escape, $matched)) 10 86 96
Condition100%3/3
$escape and $self->_match($escape, $matched)
!ll&&!rl&&r
533310
MC/DC100%2/2
$escape and $self->_match($escape, $matched)
$escape $self->_match($escape, $matched)
Truth table100%3/3
A and B
A= $escapeB= $self->_match($escape, $matched)
ABresult
0X0
100
111
363 10 $accum .= $pre . $matched;
364 10 $accum .= substr($post, 0, 1);
365 10 $_ = substr ($post, 1);
366 10 next;
367 }
368  
369 86 ▶ if ($state == 0) { # looking for start or startq
Branch: 3 branches
BranchTrueFalseTotal
if ($state == 0) { } 34 52 86
elsif ($state == 1) { } 41 11 52
elsif ($state == 2) { } 11 0 11
370 34 ▶ if ($self->_match($start, $matched)) { # matched start
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_match($start, $matched)) { } 26 8 34
371 26 $state = 1;
372 26 $depth++;
373 26 ▶ print "START: $depth\n" if $debug;
Branch: 1 branch
BranchTrueFalseTotal
if $debug 0 26 26
374  
375 26 $self->{'PRE'} = $accum . $pre;
376 26 $accum = $matched;
377 26 $_ = $post;
378 } else { # (must have) matched startq
379 8 push (@states, $state);
380 8 $state = 2;
381 8 $accum .= $pre . $matched;
382 8 foreach $scratch (keys %quote) {
383 8 ▶ if ($self->_match ($scratch, $matched)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_match($scratch, $matched)) 8 0 8
384 8 $endq = $quote{$scratch};
385 8 last;
386 }
387 }
388 8 $_ = $post;
389 }
390 } elsif ($state == 1) {
391 41 ▶ if ($self->_match($end, $matched)) { # matched end
Branch: 2 branches
BranchTrueFalseTotal
if ($self->_match($end, $matched)) { } 31 10 41
elsif ($self->_match($start, $matched)) { } 9 1 10
392 31 $state = 1;
393 31 $depth--;
394  
395 31 ▶ print "END : $depth\n" if $debug;
Branch: 1 branch
BranchTrueFalseTotal
if $debug 0 31 31
396 31 $accum .= $pre . $matched;
397 31 ▶ if ($depth == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($depth == 0) { } 22 9 31
398 22 $state = 3;
399 22 $self->{'MATCH'} = $accum;
400 22 $self->{'POST'} = $post;
401 22 $_ = "";
402 } else {
403 9 $_ = $post;
404 }
405 } elsif ($self->_match($start, $matched)) { # matched start
406 9 $state = 1;
407 9 $depth++;
408 9 ▶ print "START: $depth\n" if $debug;
Branch: 1 branch
BranchTrueFalseTotal
if $debug 0 9 9
409  
410 9 $accum .= $pre . $matched;
411 9 $_ = $post;
412 } else { # (must have) matched startq
413 1 push (@states, $state);
414 1 $state = 2;
415 1 $accum .= $pre . $matched;
416 1 foreach $scratch (keys %quote) {
417 1 ▶ if ($self->_match ($scratch, $matched)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_match($scratch, $matched)) 1 0 1
418 1 $endq = $quote{$scratch};
419 1 last;
420 }
421 }
422 1 $_ = $post;
423 }
424 } elsif ($state == 2) {
425 # case 1, matched dblesc and is a doubled char
426 11 ▶ if ($dblesc
Branch: 1 branch
BranchTrueFalseTotal
if ($dblesc and $self->_match($dblesc, $matched) and $matched eq substr($post, 0, 1)) 2 9 11
Condition83%5/6
$dblesc and $self->_match($dblesc, $matched) and $matched eq substr($post, 0, 1)
!ll&&!rl&&r
632
$dblesc and $self->_match($dblesc, $matched)
!ll&&!rl&&r
605
MC/DC66%2/3
$dblesc and $self->_match($dblesc, $matched) and $matched eq substr($post, 0, 1)
$dblesc $self->_match($dblesc, $matched) $matched eq substr($post, 0, 1)
Truth table75%3/4
A and B and C
A= $dblescB= $self->_match($dblesc, $matched)C= $matched eq substr($post, 0, 1)
ABCresult
0XX0
10X0
1100
1111
427 && $self->_match ($dblesc, $matched)
428 && ($matched eq substr($post, 0, 1))) { # skip forward
429 2 $accum .= $pre . $matched;
430 2 $accum .= substr($post, 0, 1);
431 2 $_ = substr($post, 1);
432 2 next;
433 } # otherwise check for other things then revisit
434
435 9 ▶ if ($self->_match ($endq, $matched)) { # matched endq
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_match($endq, $matched)) { } 9 0 9
436 9 $state = pop (@states);
437 9 $accum .= $pre . $matched;
438 9 $_ = $post;
439 } else { # (must have) matched a undoubled dblesc
440 # usually this ends a quoted string
441 # (and we'd never get here)
442 # but since it didn't, just skip along
443 0 $accum .= $pre . $matched;
444 0 $_ = $post;
445 }
446 } else {
447 0 $self->{'ERROR'} = "BAD STATE! THIS CAN'T HAPPEN!";
448 0 return;
449 }
450 }
451  
452 29 ▶ if ($state == 3) {
Branch: 1 branch
BranchTrueFalseTotal
if ($state == 3) { } 22 7 29
453 22 $pre = $self->{'PRE'};
454 22 $match = $self->{'MATCH'};
455 22 $post = $self->{'POST'};
456  
457 22 ▶ $match = $self->strip_delim($match) if !$self->{'RETURNDELIM'};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"RETURNDELIM"} 0 22 22
458 } else {
459 7 $self->{'PRE'} = "";
460 7 $self->{'MATCH'} = "";
461 7 $self->{'POST'} = "";
462 7 undef $pre;
463 7 undef $match;
464 7 undef $post;
465 }
466
467 29 ▶ if (!$self->{'KEEP'}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"KEEP"}) 2 27 29
468 2 $self->{'PRE'} = "";
469 2 $self->{'MATCH'} = "";
470 2 $self->{'POST'} = "";
471 }
472  
473 29 ▶ return wantarray ? ($pre, $match, $post) : $match;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 29 0 29
474 }
475  
476 5 ▶sub _fast0 {
Subroutine _fast0: called CC=7 SCAR=20.4
477 5 my $self = shift;
478 5 my $delim = $self->{'STARTREGEXP'};
479 5 local $_ = $self->{'BUFFER'};
480 5 my ($pre, $match, $post);
481  
482 5 ▶ if ($self->{'CASESENSE'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'CASESENSE'}) { } 0 5 5
483 0 $match = /^(.*?)($delim.*?$delim)(.*)$/s;
484 0 ($pre, $match, $post) = ($1, $2, $3);
485 } else {
486 5 $match = /^(.*?)($delim.*?$delim)(.*)$/si;
487 5 ($pre, $match, $post) = ($1, $2, $3);
488 }
489  
490 5 ▶ if ($match) {
Branch: 1 branch
BranchTrueFalseTotal
if ($match) { } 3 2 5
491 3 ▶ $match = $self->strip_delim($match) if !$self->{'RETURNDELIM'};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"RETURNDELIM"} 0 3 3
492  
493 3 ▶ if ($self->{'KEEP'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"KEEP"}) 3 0 3
494 3 $self->{'PRE'} = $pre;
495 3 $self->{'MATCH'} = $match;
496 3 $self->{'POST'} = $post;
497 }
498  
499 3 ▶ return wantarray ? ($pre, $match, $post) : $match;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 3 0 3
500 } else {
501 2 ▶ return wantarray ? (undef, undef, undef) : undef;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 2 0 2
502 }
503 }
504  
505 12 ▶sub _fast1 {
Subroutine _fast1: called CC=10 SCAR=23.0
506 12 my $self = shift;
507 12 my $string = $self->{'BUFFER'};
508 12 my $start = $self->{'STARTREGEXP'};
509 12 my $end = $self->{'ENDREGEXP'};
510 12 my $regexp = "($start)|($end)";
511 12 my $count = 0;
512 12 my ($match, $realpre, $pre, $post, $matched);
513  
514 12 ($realpre, $match, $post) = $self->_match($start, $string);
515  
516 12 ▶ if (defined($match)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $match) 10 2 12
517 10 $matched = $match;
518 10 $string = $post;
519 10 $count++;
520  
521 10 ($pre, $match, $post) = $self->_match($regexp, $string);
522  
523 10 ▶ while (defined($match)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $match) 26 2 28
524 26 $matched .= $pre . $match;
525  
526 26 ▶ if ($self->_match($end, $match)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_match($end, $match)) { } 17 9 26
527 17 $count--;
528 } else {
529 9 $count++;
530 }
531  
532 26 $string = $post;
533 26 ▶ last if $count == 0;
Branch: 1 branch
BranchTrueFalseTotal
if $count == 0 8 18 26
534  
535 18 ($pre, $match, $post) = $self->_match($regexp, $string);
536 }
537  
538 10 ▶ if ($count == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($count == 0) 8 2 10
539 8 ▶ $matched = $self->strip_delim($matched) if !$self->{'RETURNDELIM'};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"RETURNDELIM"} 2 6 8
540  
541 8 ▶ if ($self->{'KEEP'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"KEEP"}) 8 0 8
542 8 $self->{'PRE'} = $realpre;
543 8 $self->{'MATCH'} = $matched;
544 8 $self->{'POST'} = $post;
545 }
546
547 8 ▶ return wantarray ? ($realpre, $matched, $post) : $matched;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 5 3 8
548 }
549 }
550  
551 4 ▶ return wantarray ? (undef, undef, undef) : undef;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 4 0 4
552 }
553  
554 2 ▶sub strip_delim {
Subroutine strip_delim: called CC=5 SCAR=17.4
Pod documented
555 2 my $self = shift;
556 2 my $string = shift;
557 2 my $start = $self->{'STARTREGEXP'};
558 2 my $end = $self->{'ENDREGEXP'};
559 2 my $ok = 1;
560 2 local $_ = "no -w warning in evals now";
561  
562 2 ▶ return if $self->{'ERROR'};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"ERROR"} 0 2 2
563  
564 2 ▶ $string = $self->{'MATCH'} if !defined($string);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $string 0 2 2
565  
566 2 ▶ if ($string =~ /^$start/s) {
Branch: 1 branch
BranchTrueFalseTotal
if ($string =~ /^$start/s) { } 2 0 2
567 2 my($rest) = $';
568 2 ▶ if ($rest =~ /^(.*)$end$/s) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rest =~ /^(.*)$end$/s) { } 2 0 2
569 2 return $1;
570 } else {
571 0 $self->{'ERROR'} = "FAILED TO MATCH END DELIMITER";
572 }
573 } else {
574 0 $self->{'ERROR'} = "FAILED TO MATCH START DELIMITER";
575 }
576  
577 0 return;
578 }
579  
580 320 ▶sub _match {
Subroutine _match: called CC=5 SCAR=16.1
581 320 my $self = shift;
582 320 my $regexp = shift;
583 320 local $_ = shift;
584 320 my $match = 0;
585 320 my ($pre, $matched, $post);
586  
587 320 ▶ if ($self->{'CASESENSE'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'CASESENSE'}) { } 19 301 320
588 19 $match = /$regexp/s;
589 19 ($pre, $matched, $post) = ($`, $&, $');
590 } else {
591 301 $match = /$regexp/si;
592 301 ($pre, $matched, $post) = ($`, $&, $');
593 }
594  
595 320 ▶ if ($match) {
Branch: 1 branch
BranchTrueFalseTotal
if ($match) { } 248 72 320
596 248 ▶ wantarray ? ($pre, $matched, $post) : $matched;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 132 116 248
597 } else {
598 72 ▶ wantarray ? (undef, undef, undef) : undef;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 11 61 72
599 }
600 }
601  
602 1 ▶sub nested_match {
Subroutine nested_match: called CC=4 SCAR=16.4
Pod documented
603 1 my ($search, $start, $end, $three) = @_;
604 1 my $mc = new Text::DelimMatch $start, $end;
605 1 my ($p, $m, $s) = $mc->match($search);
606  
607 1 ▶ if (defined($three)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $three) { } 0 1 1
608 0 ▶ return wantarray ? ($p, $m, $s) : $m;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
609 } else {
610 1 ▶ return wantarray ? ("$p$m", $s) : $m;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 1 1
611 }
612 }
613  
614 1 ▶sub skip_nested_match {
Subroutine skip_nested_match: called CC=4 SCAR=16.4
Pod documented
615 1 my ($search, $start, $end, $three) = @_;
616 1 my $mc = new Text::DelimMatch $start, $end;
617 1 my ($p, $m, $s) = $mc->match($search);
618  
619 1 ▶ if (defined($three)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $three) { } 0 1 1
620 0 ▶ return wantarray ? ($p, $m, $s) : $s;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
621 } else {
622 1 ▶ return wantarray ? ("$p$m", $s) : $s;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 1 1
623 }
624 }
625  
626 1 1;
627 __END__
↑ Summary