lib/TUI/Validate/PXPictureValidator.pm

filter: Statementstmt 13.7% 63 / 457 Branchbran 0.0% 0 / 252 Conditioncond 0.0% 0 / 57 MC/DCmcdc 0.0% 0 / 37 Subroutinesub 28.5% 12 / 42 Podpod 66.6% 8 / 12 totaltotal 9.6% 83 / 857 CC 156 SCAR 57.1
CC
156
Cov
8%
__ANON__
1056.0
__ANON__
420.0
picture
272.0
CRAP 301.7
« lib/TUI/Views/ScrollBar.pm ↑ Summary lib/TUI/Views/Frame.pm »
1 package TUI::Validate::PXPictureValidator;
2 # ABSTRACT: Validator for picture-based input validation with auto-fill support
3
4 5 ▶use 5.010;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 5 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7
8 5 our $VERSION = '2.000003';
9 5 $VERSION =~ tr/_//d;
10 5 our $AUTHORITY = 'cpan:BRICKPOOL';
11
12 5 ▶use Exporter 'import';
Subroutine BEGIN: called CC=1 SCAR=0.0
13 5 our @EXPORT = qw(
14 TPXPictureValidator
15 new_TPXPictureValidator
16 );
17
18 5 ▶use Scalar::Util qw( readonly );
Subroutine BEGIN: called CC=1 SCAR=0.0
19 5 ▶use Storable;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 5 ▶use TUI::toolkit;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 5 ▶use TUI::toolkit::Types qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
22 Maybe
23 :is
24 :types
25 5 );
26
27 5 ▶use TUI::MsgBox::Const qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
28 mfError
29 mfOKButton
30 5 );
31 5 ▶use TUI::MsgBox::MsgBoxText qw( messageBox );
Subroutine BEGIN: called CC=1 SCAR=0.0
32 5 ▶use TUI::Validate::Const qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
33 :TPicResult
34 vsSyntax
35 voFill
36 5 );
37 5 ▶use TUI::Validate::Validator;
Subroutine BEGIN: called CC=1 SCAR=0.0
38
39 sub TPXPictureValidator() { __PACKAGE__ }
40 sub name() { 'TPXPictureValidator' };
41 0 ▶sub new_TPXPictureValidator { __PACKAGE__->from(@_) }
Subroutine new_TPXPictureValidator: not called CC=1 SCAR=6.9
Pod documented
42
43 5 extends TValidator;
44
45 # declare global variables
46 5 our $errorMsg = "Error in picture format.\n %s";
47
48 # private attributes
49 5 has index => ( is => 'bare' );
50 5 has jndex => ( is => 'bare' );
51
52 # protected attributes
53 0 ▶has pic => ( is => 'ro', default => sub { die 'required '} );
Subroutine __ANON__: not called CC=1 SCAR=1.2
54
55 # private methods
56 my (
57 5 $consume,
58 $toGroupEnd,
59 $skipToComma,
60 $calcTerm,
61 $iteration,
62 $group,
63 $checkComplete,
64 $scan,
65 $process,
66 $syntaxCheck,
67 );
68
69 0 ▶sub BUILDARGS { # \%args (%args)
Subroutine BUILDARGS: not called CC=1 SCAR=6.9
Pod documented
70 0 state $sig = signature(
71 method => 1,
72 named => [
73 pic => Str, { alias => 'aPic' },
74 autoFill => Bool,
75 ],
76 caller_level => +1,
77 );
78 0 my ( $class, $args ) = $sig->( @_ );
79 0 return { %$args };
80 }
81
82 0 ▶sub BUILD { # void (\%args)
Subroutine BUILD: not called CC=6 SCAR=37.4
Pod documented
83 0 my ( $self, $args ) = @_;
84 0 ▶ assert ( @_ == 2 );
Branch: 1 branch
BranchTrueFalseTotal
unless @_ == 2 0 0 0
85 0 ▶ assert ( is_Object $self );
Branch: 1 branch
BranchTrueFalseTotal
unless &is_Object($self) 0 0 0
86 0 ▶ assert ( is_HashRef $args );
Branch: 1 branch
BranchTrueFalseTotal
unless &is_HashRef($args) 0 0 0
87 $self->{options} |= voFill
88 0 ▶ if ( $args->{autoFill} );
Branch: 1 branch
BranchTrueFalseTotal
if $args->{"autoFill"} 0 0 0
89 0 my $s = '';
90 0 ▶ $self->{status} = vsSyntax
Branch: 1 branch
BranchTrueFalseTotal
if 0 0 0
91 if $self->picture( $s, false ) != prEmpty;
92 0 return;
93 }
94
95 0 ▶sub from { # $obj ($aPic, $autoFill)
Subroutine from: not called CC=1 SCAR=6.9
Pod undocumented
96 0 state $sig = signature(
97 method => 1,
98 pos => [Str, Bool],
99 );
100 0 my ( $class, @args ) = $sig->( @_ );
101 0 return $class->new( pic => $args[0], autoFill => $args[1] );
102 }
103
104 0 ▶sub DEMOLISH { # void ($in_global_destruction)
Subroutine DEMOLISH: not called CC=3 SCAR=24.8
Pod documented
105 0 my ( $self, $in_global_destruction ) = @_;
106 0 ▶ assert ( @_ == 2 );
Branch: 1 branch
BranchTrueFalseTotal
unless @_ == 2 0 0 0
107 0 ▶ assert ( is_Object $self );
Branch: 1 branch
BranchTrueFalseTotal
unless &is_Object($self) 0 0 0
108 0 $self->{pic} = undef;
109 0 return;
110 }
111
112 0 ▶sub error { # void ()
Subroutine error: not called CC=1 SCAR=6.9
Pod documented
113 0 state $sig = signature(
114 method => Object,
115 pos => [],
116 );
117 0 my ( $self ) = $sig->( @_ );
118 0 messageBox( mfError | mfOKButton, $errorMsg, $self->{pic} );
119 0 return;
120 }
121
122 0 ▶sub isValidInput { # $bool ($s, $suppressFill)
Subroutine isValidInput: not called CC=4 SCAR=30.0
Pod documented
123 0 state $sig = signature(
124 method => Object,
125 pos => [Str, Bool],
126 );
127 0 my ( $self, $s, $suppressFill ) = $sig->( @_ );
128 0 alias: for $s ( $_[1] ) {
129 0 ▶ my $doFill = ( $self->{options} & voFill ) && !$suppressFill;
Condition0%0/3
$self->{'options'} & 1 && !$suppressFill
!ll&&!rl&&r
000
MC/DC0%0/2
$self->{'options'} & 1 && !$suppressFill
$self->{'options'} & 1 !$suppressFill
Truth table0%0/3
A && not(B)
A= $self->{'options'} & 1B= !$suppressFill
ABresult
0X0
100
111
130 0 ▶ return $self->{pic} eq '' || $self->picture( $s, $doFill ) != prError;
Condition0%0/3
$self->{'pic'} eq '' || $self->picture($s, $doFill) != 3
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{'pic'} eq '' || $self->picture($s, $doFill) != 3
$self->{'pic'} eq '' $self->picture($s, $doFill) != 3
Truth table0%0/3
A || B
A= $self->{'pic'} eq ''B= $self->picture($s, $doFill) != 3
ABresult
1X1
011
000
131 } #/ alias:
132 }
133
134 0 ▶sub isValid { # $bool ($s)
Subroutine isValid: not called CC=2 SCAR=17.9
Pod documented
135 0 state $sig = signature(
136 method => Object,
137 pos => [Str],
138 );
139 0 my ( $self, $s ) = $sig->( @_ );
140 0 ▶ return $self->{pic} eq '' || $self->picture( $s, false ) == prComplete;
Condition0%0/3
$self->{'pic'} eq '' || $self->picture($s, !1) == 0
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{'pic'} eq '' || $self->picture($s, !1) == 0
$self->{'pic'} eq '' $self->picture($s, !1) == 0
Truth table0%0/3
A || B
A= $self->{'pic'} eq ''B= $self->picture($s, !1) == 0
ABresult
1X1
011
000
141 }
142
143 0 ▶my $toUpper = sub { length( uc( $_[0] ) ) == 1 ? uc( $_[0] ) : $_[0] };
Subroutine __ANON__: not called CC=2 SCAR=13.0
Branch: 1 branch
BranchTrueFalseTotal
length uc $_[0] == 1 ? : 0 0 0
144 0 ▶my $isNumber = sub { $_[0] =~ /^\d$/ };
Subroutine __ANON__: not called CC=1 SCAR=1.2
145 0 ▶my $isLetter = sub { $_[0] =~ /^[[:alpha:]]$/ };
Subroutine __ANON__: not called CC=1 SCAR=1.2
146 0 ▶my $isSpecial = sub { length $_[0] == 1 && index( $_[1], $_[0] ) != -1 };
Subroutine __ANON__: not called CC=2 SCAR=13.0
Branch: 1 branch
BranchTrueFalseTotal
length $_[0] == 1 and index($_[1], $_[0]) != -1 0 0 0
147 0 ▶my $numChar = sub { return () = ( $_[1] =~ /\Q$_[0]\E/g ) };
Subroutine __ANON__: not called CC=1 SCAR=1.2
148 0 ▶my $isComplete = sub { $_[0] == prComplete || $_[0] == prAmbiguous };
Subroutine __ANON__: not called CC=2 SCAR=13.0
Branch: 1 branch
BranchTrueFalseTotal
$_[0] == 0 or $_[0] == 5 0 0 0
149 0 ▶my $isIncomplete = sub { $_[0] == prIncomplete || $_[0] == prIncompNoFill };
Subroutine __ANON__: not called CC=2 SCAR=13.0
Branch: 1 branch
BranchTrueFalseTotal
$_[0] == 1 or $_[0] == 6 0 0 0
150
151 0 ▶sub picture { # $picResult ($input, $autoFill)
Subroutine picture: not called CC=16 SCAR=56.1
Pod documented
152 0 state $sig = signature(
153 method => Object,
154 pos => [Maybe[Str], Bool],
155 );
156 0 my ( $self, $input, $autoFill ) = $sig->( @_ );
157 0 alias: for $input ( $_[1] ) {
158
159 0 my $reprocess;
160 my $rslt;
161
162 0 ▶ if ( !$self->$syntaxCheck() ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->$syntaxCheck) 0 0 0
163 0 return prSyntax;
164 }
165
166 0 ▶ if ( !defined( $input ) || !length( $input ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $input and length $input) 0 0 0
Condition0%0/3
defined $input and length $input
!ll&&!rl&&r
000
MC/DC0%0/2
defined $input and length $input
defined $input length $input
Truth table0%0/3
A and B
A= defined $inputB= length $input
ABresult
0X0
100
111
167 0 return prEmpty;
168 }
169
170 0 $self->{jndex} = 0;
171 0 $self->{index} = 0;
172
173 0 $rslt = $self->$process( $input, length( $self->{pic} ) );
174
175 0 ▶ if ( $rslt != prError && $self->{jndex} < length( $input ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rslt != 3 and $self->{"jndex"} < length $input) 0 0 0
Condition0%0/3
$rslt != 3 and $self->{"jndex"} < length $input
!ll&&!rl&&r
000
MC/DC0%0/2
$rslt != 3 and $self->{"jndex"} < length $input
$rslt != 3 $self->{"jndex"} < length $input
Truth table0%0/3
A and B
A= $rslt != 3B= $self->{"jndex"} < length $input
ABresult
0X0
100
111
176 0 $rslt = prError;
177 }
178
179 0 ▶ if ( ( $rslt == prIncomplete ) && $autoFill ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rslt == 1 and $autoFill) 0 0 0
Condition0%0/3
$rslt == 1 and $autoFill
!ll&&!rl&&r
000
MC/DC0%0/2
$rslt == 1 and $autoFill
$rslt == 1 $autoFill
Truth table0%0/3
A and B
A= $rslt == 1B= $autoFill
ABresult
0X0
100
111
180 0 $reprocess = false;
181
182 0 ▶ while ( ( $self->{index} < length( $self->{pic} ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"index"} < length $self->{"pic"} and not &$isSpecial(substr($self->{"pic"}, $self->{"index"}, 1), "#?&!\@*{}[],")) 0 0 0
Condition0%0/3
$self->{"index"} < length $self->{"pic"} and not &$isSpecial(substr($self->{"pic"}, $self->{"index"}, 1), "#?&!\@*{}[],")
!ll&&!rl&&r
000
MC/DC0%0/2
$self->{"index"} < length $self->{"pic"} and not &$isSpecial(substr($self->{"pic"}, $self->{"index"}, 1), "#?&!\@*{}[],")
$self->{"index"} < length $self->{"pic"} not &$isSpecial(substr($self->{"pic"}, $self->{"index"}, 1), "#?&!\@*{}[],")
Truth table0%0/3
A and not(B)
A= $self->{"index"} < length $self->{"pic"}B= not &$isSpecial(substr($self->{"pic"}, $self->{"index"}, 1), "#?&!\@*{}[],")
ABresult
0X0
100
111
183 && !&$isSpecial( substr($self->{pic}, $self->{index}, 1), "#?&!@*{}[]," )
184 ) {
185 0 my $pchar = substr( $self->{pic}, $self->{index}, 1 );
186 0 ▶ if ( $pchar eq ';' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pchar eq ";") 0 0 0
187 0 $self->{index}++;
188 0 ▶ last if $self->{index} >= length( $self->{pic} );
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"index"} >= length $self->{"pic"} 0 0 0
189 0 $pchar = substr( $self->{pic}, $self->{index}, 1 );
190 }
191
192 0 $input .= $pchar;
193 0 $self->{index}++;
194 0 $reprocess = true;
195 }
196
197 0 $self->{jndex} = 0;
198 0 $self->{index} = 0;
199 0 ▶ if ( $reprocess ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($reprocess) 0 0 0
200 0 $rslt = $self->$process( $input, length( $self->{pic} ) );
201 }
202 } #/ if ( ( $rslt == prIncomplete...))
203
204 0 ▶ if ( $rslt == prAmbiguous ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($rslt == 5) { } 0 0 0
elsif ($rslt == 6) { } 0 0 0
205 0 return prComplete;
206 }
207 elsif ( $rslt == prIncompNoFill ) {
208 0 return prIncomplete;
209 }
210 else {
211 0 return $rslt;
212 }
213 } #/ alias:
214 }; #/ $picture = sub
215
216 # Consume input
217 0 ▶$consume = sub { # void ($ch, $input)
Subroutine __ANON__: not called CC=7 SCAR=40.3
218 0 my ( $self, $ch, $input ) = @_;
219 0 ▶ assert ( @_ == 3 );
Branch: 1 branch
BranchTrueFalseTotal
unless @_ == 3 0 0 0
220 0 ▶ assert ( is_Object $self );
Branch: 1 branch
BranchTrueFalseTotal
unless &is_Object($self) 0 0 0
221 0 ▶ assert ( is_Str $ch );
Branch: 1 branch
BranchTrueFalseTotal
unless &is_Str($ch) 0 0 0
222 0 ▶ assert ( is_Str $input );
Branch: 1 branch
BranchTrueFalseTotal
unless &is_Str($input) 0 0 0
223 0 alias: for $input ( $_[2] ) {
224 0 ▶ assert ( !readonly $input );
Branch: 1 branch
BranchTrueFalseTotal
if &readonly($input) 0 0 0
225
226 0 substr( $input, $self->{jndex}, 1 ) = $ch;
227 0 $self->{index}++;
228 0 $self->{jndex}++;
229 0 return;
230
231 } #/ alias:
232 5 };
233
234 # Skip a character or a picture group
235 0 ▶$toGroupEnd = sub { # void (\$i, $termCh)
Subroutine __ANON__: not called CC=14 SCAR=53.5
236 0 my ( $self, $i, $termCh ) = @_;
237 0 ▶ assert ( @_ == 3 );
Branch: 1 branch
BranchTrueFalseTotal
unless @_ == 3 0 0 0
238 0 ▶ assert ( is_Object $self );
Branch: 1 branch
BranchTrueFalseTotal
unless &is_Object($self) 0 0 0
239 0 ▶ assert ( is_ScalarRef $i );
Branch: 1 branch
BranchTrueFalseTotal
unless &is_ScalarRef($i) 0 0 0
240 0 ▶ assert ( is_Int $termCh );
Branch: 1 branch
BranchTrueFalseTotal
unless &is_Int($termCh) 0 0 0
241
242 0 my $brkLevel = 0;
243 0 my $brcLevel = 0;
244 0 ▶ do {
Branch: 1 branch
BranchTrueFalseTotal
$brkLevel == 0 and $brcLevel == 0 or do { do { return if $$i == $termCh; SWITCH: foreach $_ (substr $self->{"pic"}, $$i, 1) { $_ eq "[" and do { ++$brkLevel; last }; $_ eq "]" and do { --$brkLevel; last }; $_ eq "{" and do { ++$brcLevel; last }; $_ eq "}" and do { --$brcLevel; last }; $_ eq ";" and do { ++$$i; last }; } ; ++$$i } } 0 0 0
Condition0%0/3
$brkLevel == 0 and $brcLevel == 0
!ll&&!rl&&r
000
MC/DC0%0/2
$brkLevel == 0 and $brcLevel == 0
$brkLevel == 0 $brcLevel == 0
Truth table0%0/3
A and B
A= $brkLevel == 0B= $brcLevel == 0
ABresult
0X0
100
111
245 0 ▶ return if $$i == $termCh;
Branch: 1 branch
BranchTrueFalseTotal
if $$i == $termCh 0 0 0
246 0 SWITCH: for ( substr( $self->{pic}, $$i, 1 ) ) {
247 0 ▶ $_ eq '[' and do { $brkLevel++; last };
Branch: 1 branch
BranchTrueFalseTotal
$_ eq "[" and do { ++$brkLevel; last } 0 0 0
248 0 ▶ $_ eq ']' and do { $brkLevel--; last };
Branch: 1 branch
BranchTrueFalseTotal
$_ eq "]" and do { --$brkLevel; last } 0 0 0
249 0 ▶ $_ eq '{' and do { $brcLevel++; last };
Branch: 1 branch
BranchTrueFalseTotal
$_ eq "{" and do { ++$brcLevel; last } 0 0 0
250 0 ▶ $_ eq '}' and do { $brcLevel--; last };
Branch: 1 branch
BranchTrueFalseTotal
$_ eq "}" and do { --$brcLevel; last } 0 0 0
251 0 ▶ $_ eq ';' and do { $$i++; last };
Branch: 1 branch
BranchTrueFalseTotal
$_ eq ";" and do { ++$$i; last } 0 0 0
252 }
253 0 $$i++;
254 } while ( !( $brkLevel == 0 && $brcLevel == 0 ) );
255 0 return;
256 5 }; #/ $toGroupEnd = sub
257
258 # Find a comma separator
259 0 ▶$skipToComma = sub { # $bool ($termCh)
Subroutine __ANON__: not called CC=7 SCAR=40.3
260 0 my ( $self, $termCh ) = @_;
261 0 ▶ assert ( @_ == 2 );
Branch: 1 branch
BranchTrueFalseTotal
unless @_ == 2 0 0 0
262 0 ▶ assert ( is_Object $self );
Branch: 1 branch
BranchTrueFalseTotal
unless &is_Object($self) 0 0 0
263 0 ▶ assert ( is_Int $termCh );
Branch: 1 branch
BranchTrueFalseTotal
unless &is_Int($termCh) 0 0 0
264 do {
265 0 $self->$toGroupEnd( \$self->{index}, $termCh );
266 } while ( !( $self->{index} == $termCh
267 0 ▶ || substr( $self->{pic}, $self->{index}, 1 ) eq ',' ) );
Branch: 1 branch
BranchTrueFalseTotal
($self->{"index"} == $termCh or substr($self->{"pic"}, $self->{"index"}, 1) eq ",") or do { do { $self->$toGroupEnd(\$self->{"index"}, $termCh) } } 0 0 0
Condition0%0/3
$self->{"index"} == $termCh or substr($self->{"pic"}, $self->{"index"}, 1) eq ","
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"index"} == $termCh or substr($self->{"pic"}, $self->{"index"}, 1) eq ","
$self->{"index"} == $termCh substr($self->{"pic"}, $self->{"index"}, 1) eq ","
Truth table0%0/3
A or B
A= $self->{"index"} == $termChB= substr($self->{"pic"}, $self->{"index"}, 1) eq ","
ABresult
1X1
011
000
268
269 $self->{index}++
270 0 ▶ if substr( $self->{pic}, $self->{index}, 1 ) eq ',';
Branch: 1 branch
BranchTrueFalseTotal
if substr($self->{"pic"}, $self->{"index"}, 1) eq "," 0 0 0
271 0 return $self->{index} < $termCh;
272 5 };
273
274 # Calculate the end of a group
275 0 ▶$calcTerm = sub { # $int ($termCh)
Subroutine __ANON__: not called CC=4 SCAR=30.0
276 0 my ( $self, $termCh ) = @_;
277 0 ▶ assert ( @_ == 2 );
Branch: 1 branch
BranchTrueFalseTotal
unless @_ == 2 0 0 0
278 0 ▶ assert ( is_Object $self );
Branch: 1 branch
BranchTrueFalseTotal
unless &is_Object($self) 0 0 0
279 0 ▶ assert ( is_Int $termCh );
Branch: 1 branch
BranchTrueFalseTotal
unless &is_Int($termCh) 0 0 0
280 0 my $k = $self->{index};
281 0 $self->$toGroupEnd( \$k, $termCh );
282 0 return $k;
283 5 };
284
285 # The next group is repeated X times
286 0 ▶$iteration = sub { # $picResult ($input, $inTerm)
Subroutine __ANON__: not called CC=15 SCAR=54.8
287 0 my ( $self, $input, $inTerm ) = @_;
288 0 ▶ assert ( @_ == 3 );
Branch: 1 branch
BranchTrueFalseTotal
unless @_ == 3 0 0 0
289 0 ▶ assert ( is_Object $self );
Branch: 1 branch
BranchTrueFalseTotal
unless &is_Object($self) 0 0 0
290 0 ▶ assert ( is_Str $input );
Branch: 1 branch
BranchTrueFalseTotal
unless &is_Str($input) 0 0 0
291 0 ▶ assert ( is_Int $inTerm );
Branch: 1 branch
BranchTrueFalseTotal
unless &is_Int($inTerm) 0 0 0
292 0 for $input ( $_[1] ) {
293 0 ▶ assert ( !readonly $input );
Branch: 1 branch
BranchTrueFalseTotal
if &readonly($input) 0 0 0
294
295 0 my $itr = 0;
296 0 my $rslt = prError;
297 0 my $termCh;
298
299 0 $self->{index}++; # Skip '*'
300
301 # Retrieve number
302 0 ▶ while ( &$isNumber( substr( $self->{pic}, $self->{index}, 1 ) ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (&$isNumber(substr($self->{"pic"}, $self->{"index"}, 1))) 0 0 0
303 0 my $digit = substr( $self->{pic}, $self->{index}, 1 );
304 0 $itr = $itr * 10 + ( ord( $digit ) - ord( '0' ) );
305 0 $self->{index}++;
306 }
307
308 0 my $k = $self->{index};
309 0 $termCh = $self->$calcTerm( $inTerm );
310
311 # If $itr is 0 allow any number, otherwise enforce the number
312 0 ▶ if ( $itr != 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($itr != 0) { } 0 0 0
313 0 ▶ for ( my $l = 1 ; $l <= $itr ; $l++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($l <= $itr) 0 0 0
314 0 $self->{index} = $k;
315 0 $rslt = $self->$process( $input, $termCh );
316
317 0 ▶ if ( !&$isComplete( $rslt ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (&$isComplete($rslt)) 0 0 0
318
319 # Empty means incomplete since all are required
320 0 ▶ if ( $rslt == prEmpty ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rslt == 2) 0 0 0
321 0 $rslt = prIncomplete;
322 }
323 0 return $rslt;
324 }
325 }
326 }
327 else {
328 0 ▶ do {
Branch: 1 branch
BranchTrueFalseTotal
$rslt == 0 and do { do { $self->{"index"} = $k; $rslt = $self->$process($input, $termCh) } } 0 0 0
329 0 $self->{index} = $k;
330 0 $rslt = $self->$process( $input, $termCh );
331 } while ( $rslt == prComplete );
332
333 0 ▶ if ( $rslt == prEmpty || $rslt == prError ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rslt == 2 or $rslt == 3) 0 0 0
Condition0%0/3
$rslt == 2 or $rslt == 3
l!l&&r!l&&!r
000
MC/DC0%0/2
$rslt == 2 or $rslt == 3
$rslt == 2 $rslt == 3
Truth table0%0/3
A or B
A= $rslt == 2B= $rslt == 3
ABresult
1X1
011
000
334 0 $self->{index}++;
335 0 $rslt = prAmbiguous;
336 }
337 }
338
339 0 $self->{index} = $termCh;
340 0 return $rslt;
341 } #/ alias:
342 5 }; #/ $iteration = sub
343
344 # Process a picture group
345 0 ▶$group = sub { # $picResult ($input, $inTerm)
Subroutine __ANON__: not called CC=8 SCAR=42.8
346 0 my ( $self, $input, $inTerm ) = @_;
347 0 ▶ assert ( @_ == 3 );
Branch: 1 branch
BranchTrueFalseTotal
unless @_ == 3 0 0 0
348 0 ▶ assert ( is_Object $self );
Branch: 1 branch
BranchTrueFalseTotal
unless &is_Object($self) 0 0 0
349 0 ▶ assert ( is_Str $input );
Branch: 1 branch
BranchTrueFalseTotal
unless &is_Str($input) 0 0 0
350 0 ▶ assert ( is_Int $inTerm );
Branch: 1 branch
BranchTrueFalseTotal
unless &is_Int($inTerm) 0 0 0
351 0 alias: for $input ( $_[1] ) {
352 0 ▶ assert ( !readonly $input );
Branch: 1 branch
BranchTrueFalseTotal
if &readonly($input) 0 0 0
353
354 0 my $rslt;
355 my $termCh;
356
357 0 $termCh = $self->$calcTerm( $inTerm );
358 0 $self->{index}++;
359 0 $rslt = $self->$process( $input, $termCh - 1 );
360
361 0 ▶ if ( !&$isIncomplete( $rslt ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (&$isIncomplete($rslt)) 0 0 0
362 0 $self->{index} = $termCh;
363 }
364
365 0 return $rslt;
366 } #/ alias:
367 5 };
368
369 0 ▶$checkComplete = sub { # $picResult ($rslt, $termCh)
Subroutine __ANON__: not called CC=11 SCAR=48.8
370 0 my ( $self, $rslt, $termCh ) = @_;
371 0 ▶ assert ( @_ == 3 );
Branch: 1 branch
BranchTrueFalseTotal
unless @_ == 3 0 0 0
372 0 ▶ assert ( is_Object $self );
Branch: 1 branch
BranchTrueFalseTotal
unless &is_Object($self) 0 0 0
373 0 ▶ assert ( is_PositiveOrZeroInt $rslt );
Branch: 1 branch
BranchTrueFalseTotal
unless &is_PositiveOrZeroInt($rslt) 0 0 0
374 0 ▶ assert ( is_Int $termCh );
Branch: 1 branch
BranchTrueFalseTotal
unless &is_Int($termCh) 0 0 0
375
376 0 my $j = $self->{index};
377 0 my $status = true;
378
379 0 ▶ if ( &$isIncomplete( $rslt ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (&$isIncomplete($rslt)) 0 0 0
380
381 # Skip optional pieces
382 0 ▶ while ( $status ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($status) 0 0 0
383 0 my $ch = substr( $self->{pic}, $j, 1 );
384
385 0 ▶ if ( $ch eq '[' ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($ch eq '[') { } 0 0 0
elsif ($ch eq '*') { } 0 0 0
386 0 $self->$toGroupEnd( \$j, $termCh );
387 }
388 elsif ( $ch eq '*' ) {
389 0 ▶ if ( !&$isNumber( substr( $self->{pic}, $j + 1, 1 ) ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (&$isNumber(substr($self->{"pic"}, $j + 1, 1))) 0 0 0
390 0 $j++;
391 }
392 0 $self->$toGroupEnd( \$j, $termCh );
393 }
394 else {
395 0 $status = false;
396 }
397 }
398
399 0 ▶ if ( $j == $termCh ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($j == $termCh) 0 0 0
400 0 $rslt = prAmbiguous;
401 }
402 } #/ if ( $self->isIncomplete...)
403
404 0 return $rslt;
405 5 }; #/ $checkComplete = sub
406
407 0 ▶$scan = sub { # $picResult ($input, $termCh)
Subroutine __ANON__: not called CC=32 SCAR=69.6
408 0 my ( $self, $input, $termCh ) = @_;
409 0 ▶ assert ( @_ == 3 );
Branch: 1 branch
BranchTrueFalseTotal
unless @_ == 3 0 0 0
410 0 ▶ assert ( is_Object $self );
Branch: 1 branch
BranchTrueFalseTotal
unless &is_Object($self) 0 0 0
411 0 ▶ assert ( is_Str $input );
Branch: 1 branch
BranchTrueFalseTotal
unless &is_Str($input) 0 0 0
412 0 ▶ assert ( is_Int $termCh );
Branch: 1 branch
BranchTrueFalseTotal
unless &is_Int($termCh) 0 0 0
413 0 alias: for $input ( $_[1] ) {
414 0 ▶ assert ( !readonly $input );
Branch: 1 branch
BranchTrueFalseTotal
if &readonly($input) 0 0 0
415
416 0 my $ch;
417 0 my ( $rslt, $rScan );
418
419 0 $rScan = prError;
420 0 $rslt = prEmpty;
421
422 0 ▶ while ( ( $self->{index} != $termCh )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"index"} != $termCh and substr($self->{"pic"}, $self->{"index"}, 1) ne ",") 0 0 0
Condition0%0/3
$self->{"index"} != $termCh and substr($self->{"pic"}, $self->{"index"}, 1) ne ","
!ll&&!rl&&r
000
MC/DC0%0/2
$self->{"index"} != $termCh and substr($self->{"pic"}, $self->{"index"}, 1) ne ","
$self->{"index"} != $termCh substr($self->{"pic"}, $self->{"index"}, 1) ne ","
Truth table0%0/3
A and B
A= $self->{"index"} != $termChB= substr($self->{"pic"}, $self->{"index"}, 1) ne ","
ABresult
0X0
100
111
423 && ( substr( $self->{pic}, $self->{index}, 1 ) ne ',' ) )
424 {
425 0 ▶ if ( $self->{jndex} >= length( $input ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"jndex"} >= length $input) 0 0 0
426 0 return $self->$checkComplete( $rslt, $termCh );
427 }
428
429 0 $ch = substr( $input, $self->{jndex}, 1 );
430
431 0 SWITCH: for ( substr( $self->{pic}, $self->{index}, 1 ) ) {
432
433 0 ▶ $_ eq '#' and do {
Branch: 1 branch
BranchTrueFalseTotal
$_ eq "#" and do { if (not &$isNumber($ch)) { return 3; } else { $self->$consume($ch, $input); } ; last } 0 0 0
434 0 ▶ if ( !&$isNumber( $ch ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not &$isNumber($ch)) { } 0 0 0
435 0 return prError();
436 }
437 else {
438 0 $self->$consume( $ch, $input );
439 }
440 0 last;
441 };
442
443 0 ▶ $_ eq '?' and do {
Branch: 1 branch
BranchTrueFalseTotal
$_ eq "?" and do { if (not &$isLetter($ch)) { return 3; } else { $self->$consume($ch, $input); } ; last } 0 0 0
444 0 ▶ if ( !&$isLetter( $ch ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not &$isLetter($ch)) { } 0 0 0
445 0 return prError;
446 }
447 else {
448 0 $self->$consume( $ch, $input );
449 }
450 0 last;
451 };
452
453 0 ▶ $_ eq '&' and do {
Branch: 1 branch
BranchTrueFalseTotal
$_ eq "&" and do { if (not &$isLetter($ch)) { return 3; } else { $self->$consume(&$toUpper($ch), $input); } ; last } 0 0 0
454 0 ▶ if ( !&$isLetter( $ch ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not &$isLetter($ch)) { } 0 0 0
455 0 return prError();
456 }
457 else {
458 0 $self->$consume( &$toUpper( $ch ), $input );
459 }
460 0 last;
461 };
462
463 0 ▶ $_ eq '!' and do {
Branch: 1 branch
BranchTrueFalseTotal
$_ eq "!" and do { $self->$consume(&$toUpper($ch), $input); last } 0 0 0
464 0 $self->$consume( &$toUpper( $ch ), $input );
465 0 last;
466 };
467
468 0 ▶ $_ eq '@' and do {
Branch: 1 branch
BranchTrueFalseTotal
$_ eq "\@" and do { $self->$consume($ch, $input); last } 0 0 0
469 0 $self->$consume( $ch, $input );
470 0 last;
471 };
472
473 0 ▶ $_ eq '*' and do {
Branch: 1 branch
BranchTrueFalseTotal
$_ eq "*" and do { $rslt = $self->$iteration($input, $termCh); unless (&$isComplete($rslt)) { return $rslt; } ; if ($rslt == 3) { $rslt = 5; } ; last } 0 0 0
474 0 $rslt = $self->$iteration( $input, $termCh );
475 0 ▶ if ( !&$isComplete( $rslt ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (&$isComplete($rslt)) 0 0 0
476 0 return $rslt;
477 }
478
479 0 ▶ if ( $rslt == prError ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rslt == 3) 0 0 0
480 0 $rslt = prAmbiguous;
481 }
482 0 last;
483 };
484
485 0 ▶ $_ eq '{' and do {
Branch: 1 branch
BranchTrueFalseTotal
$_ eq "{" and do { $rslt = $self->$group($input, $termCh); unless (&$isComplete($rslt)) { return $rslt; } ; last } 0 0 0
486 0 $rslt = $self->$group( $input, $termCh );
487 0 ▶ if ( !&$isComplete( $rslt ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (&$isComplete($rslt)) 0 0 0
488 0 return $rslt;
489 }
490 0 last;
491 };
492
493 0 ▶ $_ eq '[' and do {
Branch: 1 branch
BranchTrueFalseTotal
$_ eq "[" and do { $rslt = $self->$group($input, $termCh); if (&$isIncomplete($rslt)) { return $rslt; } ; if ($rslt == 3) { $rslt = 5; } ; last } 0 0 0
494 0 $rslt = $self->$group( $input, $termCh );
495 0 ▶ if ( &$isIncomplete( $rslt ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (&$isIncomplete($rslt)) 0 0 0
496 0 return $rslt;
497 }
498 0 ▶ if ( $rslt == prError ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rslt == 3) 0 0 0
499 0 $rslt = prAmbiguous;
500 }
501 0 last;
502 };
503
504 DEFAULT: {
505 0 my $p = substr( $self->{pic}, $self->{index}, 1 );
506
507 0 ▶ if ( $p eq ';' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($p eq ";") 0 0 0
508 0 $self->{index}++;
509 0 $p = substr( $self->{pic}, $self->{index}, 1 );
510 }
511
512 0 ▶ if ( &$toUpper( $p ) ne &$toUpper( $ch ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (&$toUpper($p) ne &$toUpper($ch)) 0 0 0
513 0 ▶ if ( $ch ne ' ' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ch ne " ") 0 0 0
514 0 return $rScan;
515 }
516 }
517
518 0 $self->$consume( $p, $input );
519 }
520 } #/ SWITCH: for ( substr( $self->{pic...}))
521
522 0 ▶ if ( $rslt == prAmbiguous ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rslt == 5) { } 0 0 0
523 0 $rslt = prIncompNoFill;
524 }
525 else {
526 0 $rslt = prIncomplete;
527 }
528 } #/ while ( ( $self->{index} ...))
529
530 0 ▶ if ( $rslt == prIncompNoFill ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rslt == 6) { } 0 0 0
531 0 return prAmbiguous;
532 }
533 else {
534 0 return prComplete;
535 }
536 } #/ alias:
537 5 }; #/ $scan = sub
538
539 0 ▶$process = sub { # $picResult ($input, $termCh)
Subroutine __ANON__: not called CC=20 SCAR=60.4
540 0 my ( $self, $input, $termCh ) = @_;
541 0 ▶ assert ( @_ == 3 );
Branch: 1 branch
BranchTrueFalseTotal
unless @_ == 3 0 0 0
542 0 ▶ assert ( is_Object $self );
Branch: 1 branch
BranchTrueFalseTotal
unless &is_Object($self) 0 0 0
543 0 ▶ assert ( is_Str $input );
Branch: 1 branch
BranchTrueFalseTotal
unless &is_Str($input) 0 0 0
544 0 ▶ assert ( is_Int $termCh );
Branch: 1 branch
BranchTrueFalseTotal
unless &is_Int($termCh) 0 0 0
545 0 alias: for $input ( $_[1] ) {
546 0 ▶ assert ( !readonly $input );
Branch: 1 branch
BranchTrueFalseTotal
if &readonly($input) 0 0 0
547
548 0 my ( $rslt, $rProcess );
549 0 my $incomp;
550 0 my ( $oldI, $oldJ, $incompJ, $incompI );
551
552 0 $incomp = false;
553 0 $oldI = $self->{index};
554 0 $oldJ = $self->{jndex};
555 0 $incompJ = 0;
556
557 0 ▶ do {
Branch: 1 branch
BranchTrueFalseTotal
$rslt == 3 || $rslt == 1 and 0 0 0
Condition0%0/3
$rslt == 3 or $rslt == 1
l!l&&r!l&&!r
000
MC/DC0%0/2
$rslt == 3 or $rslt == 1
$rslt == 3 $rslt == 1
Truth table0%0/3
A or B
A= $rslt == 3B= $rslt == 1
ABresult
1X1
011
000
558 0 $rslt = $self->$scan( $input, $termCh );
559
560 # Only accept completes if they make it farther in the input stream
561 # from the last incomplete
562 0 ▶ if ( $rslt == prComplete && $incomp && $self->{jndex} < $incompJ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rslt == 0 and $incomp and $self->{"jndex"} < $incompJ) 0 0 0
Condition0%0/6
$rslt == 0 and $incomp and $self->{"jndex"} < $incompJ
!ll&&!rl&&r
000
$rslt == 0 and $incomp
!ll&&!rl&&r
000
MC/DC0%0/3
$rslt == 0 and $incomp and $self->{"jndex"} < $incompJ
$rslt == 0 $incomp $self->{"jndex"} < $incompJ
Truth table0%0/4
A and B and C
A= $rslt == 0B= $incompC= $self->{"jndex"} < $incompJ
ABCresult
0XX0
10X0
1100
1111
563 0 $rslt = prIncomplete;
564 0 $self->{jndex} = $incompJ;
565 }
566
567 0 ▶ if ( $rslt == prError || $rslt == prIncomplete ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rslt == 3 or $rslt == 1) 0 0 0
Condition0%0/3
$rslt == 3 or $rslt == 1
l!l&&r!l&&!r
000
MC/DC0%0/2
$rslt == 3 or $rslt == 1
$rslt == 3 $rslt == 1
Truth table0%0/3
A or B
A= $rslt == 3B= $rslt == 1
ABresult
1X1
011
000
568 0 $rProcess = $rslt;
569
570 0 ▶ if ( !$incomp && $rslt == prIncomplete ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $incomp and $rslt == 1) 0 0 0
Condition0%0/3
not $incomp and $rslt == 1
!ll&&!rl&&r
000
MC/DC0%0/2
not $incomp and $rslt == 1
not $incomp $rslt == 1
Truth table0%0/3
not(A) and B
A= not $incompB= $rslt == 1
ABresult
0X0
100
111
571 0 $incomp = true;
572 0 $incompI = $self->{index};
573 0 $incompJ = $self->{jndex};
574 }
575
576 0 $self->{index} = $oldI;
577 0 $self->{jndex} = $oldJ;
578
579 0 ▶ if ( !$self->$skipToComma( $termCh ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->$skipToComma($termCh)) 0 0 0
580 0 ▶ if ( $incomp ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($incomp) 0 0 0
581 0 $rProcess = prIncomplete;
582 0 $self->{index} = $incompI;
583 0 $self->{jndex} = $incompJ;
584 }
585 0 return $rProcess;
586 }
587
588 0 $oldI = $self->{index};
589 } #/ if ( ( $rslt == prError...))
590
591 } while ( $rslt == prError || $rslt == prIncomplete );
592
593 0 ▶ if ( $rslt == prComplete && $incomp ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rslt == 0 and $incomp) { } 0 0 0
Condition0%0/3
$rslt == 0 and $incomp
!ll&&!rl&&r
000
MC/DC0%0/2
$rslt == 0 and $incomp
$rslt == 0 $incomp
Truth table0%0/3
A and B
A= $rslt == 0B= $incomp
ABresult
0X0
100
111
594 0 return prAmbiguous;
595 }
596 else {
597 0 return $rslt;
598 }
599 } #/ alias:
600 5 }; #/ $process = sub
601
602 0 ▶$syntaxCheck = sub { # $bool ()
Subroutine __ANON__: not called CC=14 SCAR=53.5
603 0 my ( $self ) = @_;
604 0 ▶ assert ( @_ == 1 );
Branch: 1 branch
BranchTrueFalseTotal
unless @_ == 1 0 0 0
605 0 ▶ assert ( is_Object $self );
Branch: 1 branch
BranchTrueFalseTotal
unless &is_Object($self) 0 0 0
606
607 0 ▶ if ( !defined $self->{pic} || length( $self->{pic} ) == 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $self->{"pic"} or length $self->{"pic"} == 0) 0 0 0
Condition0%0/3
not defined $self->{"pic"} or length $self->{"pic"} == 0
l!l&&r!l&&!r
000
MC/DC0%0/2
not defined $self->{"pic"} or length $self->{"pic"} == 0
not defined $self->{"pic"} length $self->{"pic"} == 0
Truth table0%0/3
not(A) or B
A= not defined $self->{"pic"}B= length $self->{"pic"} == 0
ABresult
1X1
011
000
608 0 return false;
609 }
610
611 0 ▶ if ( substr( $self->{pic}, -1, 1 ) eq ';' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (substr($self->{"pic"}, -1, 1) eq ";") 0 0 0
612 0 return false;
613 }
614
615 0 my $i = 0;
616 0 my $brkLevel = 0;
617 0 my $brcLevel = 0;
618
619 0 my $len = length( $self->{pic} );
620 0 ▶ while ( $i < $len ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $len) 0 0 0
621 0 SWITCH: for ( substr( $self->{pic}, $i, 1 ) ) {
622 0 ▶ $_ eq '[' and do { $brkLevel++; last };
Branch: 1 branch
BranchTrueFalseTotal
$_ eq "[" and do { ++$brkLevel; last } 0 0 0
623 0 ▶ $_ eq ']' and do { $brkLevel--; last };
Branch: 1 branch
BranchTrueFalseTotal
$_ eq "]" and do { --$brkLevel; last } 0 0 0
624 0 ▶ $_ eq '{' and do { $brcLevel++; last };
Branch: 1 branch
BranchTrueFalseTotal
$_ eq "{" and do { ++$brcLevel; last } 0 0 0
625 0 ▶ $_ eq '}' and do { $brcLevel--; last };
Branch: 1 branch
BranchTrueFalseTotal
$_ eq "}" and do { --$brcLevel; last } 0 0 0
626 0 ▶ $_ eq ';' and do { $i++; last };
Branch: 1 branch
BranchTrueFalseTotal
$_ eq ";" and do { ++$i; last } 0 0 0
627 }
628 0 $i++;
629 }
630
631 0 ▶ return $brkLevel == 0 && $brcLevel == 0;
Condition0%0/3
$brkLevel == 0 && $brcLevel == 0
!ll&&!rl&&r
000
MC/DC0%0/2
$brkLevel == 0 && $brcLevel == 0
$brkLevel == 0 $brcLevel == 0
Truth table0%0/3
A && B
A= $brkLevel == 0B= $brcLevel == 0
ABresult
0X0
100
111
632 5 }; #/ $syntaxCheck = sub
633
634 0 ▶sub write :method { # void ($os)
Subroutine write: not called CC=1 SCAR=6.9
Pod undocumented
635 0 state $sig = signature(
636 method => Object,
637 pos => [Object],
638 );
639 0 my ( $self, $os ) = $sig->( @_ );
640 0 $self->SUPER::write( $os );
641 0 $os->put( $self->{pic} );
642 0 return;
643 }
644
645 0 ▶sub read :method { # $self ($is)
Subroutine read: not called CC=1 SCAR=6.9
Pod undocumented
646 0 state $sig = signature(
647 method => Object,
648 pos => [Object],
649 );
650 0 my ( $self, $is ) = $sig->( @_ );
651
652 0 $self->SUPER::read( $is );
653 0 $self->{pic} = $is->get();
654 0 $self->{index} = $self->{jndex} = 0;
655
656 0 return $self;
657 }
658
659 0 ▶sub build { # $obj ()
Subroutine build: not called CC=4 SCAR=30.0
Pod undocumented
660 0 my ( $class ) = @_;
661 0 ▶ assert ( @_ == 1 );
Branch: 1 branch
BranchTrueFalseTotal
unless @_ == 1 0 0 0
662 0 ▶ assert ( is_Str $class );
Branch: 1 branch
BranchTrueFalseTotal
unless &is_Str($class) 0 0 0
663 0 ▶ assert ( Storable::is_retrieving );
Branch: 1 branch
BranchTrueFalseTotal
unless &Storable::is_retrieving() 0 0 0
664 0 return $class->new(
665 pic => '',
666 autoFill => false,
667 );
668 }
669
670 5 1
671
672 __END__
« lib/TUI/Views/ScrollBar.pm ↑ Summary lib/TUI/Views/Frame.pm »