Object/DOM/Element/Input.pm

filter: Statementstmt 85.5% 136 / 159 Branchbran 59.6% 62 / 104 Conditioncond 64.4% 58 / 90 MC/DCmcdc 36.3% 16 / 44 Subroutinesub 70.0% 14 / 20 Podpod 55.5% 5 / 9 totaltotal 68.3% 291 / 426 CC 86 SCAR 50.5
CC
86
Cov
73%
_set_up_down
214.0
__ANON__
9.1
init
3.1
CRAP 156.0
« Object/DOM/List.pm ↑ Summary Object/XPath/Expr.pm »
1 ##----------------------------------------------------------------------------
2 ## HTML Object - ~/lib/HTML/Object/DOM/Element/Input.pm
3 ## Version v0.2.2
4 ## Copyright(c) 2023 DEGUEST Pte. Ltd.
5 ## Author: Jacques Deguest <jack@deguest.jp>
6 ## Created 2021/12/23
7 ## Modified 2023/11/06
8 ## All rights reserved.
9 ##
10 ##
11 ## This program is free software; you can redistribute it and/or modify it
12 ## under the same terms as Perl itself.
13 ##----------------------------------------------------------------------------
14 package HTML::Object::DOM::Element::Input;
15 BEGIN
16 5 ▶{
Subroutine BEGIN: called CC=1 SCAR=0.0
17 5 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 5 ▶ use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 5 warnings::register_categories( 'HTML::Object' );
20 5 ▶ use parent qw( HTML::Object::DOM::Element );
Subroutine BEGIN: called CC=1 SCAR=0.0
21 5 ▶ use vars qw( $VERSION );
Subroutine BEGIN: called CC=1 SCAR=0.0
22 5 ▶ use HTML::Object::DOM::Element::Shared qw( :input );
Subroutine BEGIN: called CC=1 SCAR=0.0
23 5 ▶ use POSIX ();
Subroutine BEGIN: called CC=1 SCAR=0.0
24 5 our $VERSION = 'v0.2.2';
25 };
26  
27 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
28 5 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
29  
30 sub init
31 12 ▶{
Subroutine init: called CC=3 SCAR=11.3
Pod documented
32 12 my $self = shift( @_ );
33 12 $self->{_init_strict_use_sub} = 1;
34 12 ▶ $self->SUPER::init( @_ ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->SUPER::init(@_) or return $self->pass_error 12 0 12
35 12 ▶ $self->{tag} = 'input' if( !CORE::length( "$self->{tag}" ) );
Branch: 1 branch
BranchTrueFalseTotal
unless length qq[$self->{"tag"}] 0 12 12
36 12 return( $self );
37 }
38  
39 # Note: property accept is inherited
40  
41 # Note: property accessKey is inherited
42  
43 # Note: deprecated property align is inherited
44  
45 # Note: property allowdirs is inherited
46  
47 # Note: property alt is inherited
48  
49 # Note: property autocapitalize is inherited
50  
51 # Note: property autocomplete is inherited
52  
53 # Note: property autofocus is inherited
54  
55 # Note: property checked is inherited
56  
57 # Note: property defaultChecked is inherited
58  
59 # Note: property defaultValue is inherited
60  
61 # Note: property dirName is inherited
62  
63 # Note: property disabled is inherited
64  
65 # Note: property files is inherited
66  
67 # Note: property form read-only is inherited
68  
69 # Note: property formAction is inherited
70  
71 # Note: property formEnctype is inherited
72  
73 # Note: property formMethod is inherited
74  
75 # Note: property formNoValidate is inherited
76  
77 # Note: property formTarget is inherited
78  
79 # Note: property height is inherited
80  
81 # Note: property indeterminate is inherited
82  
83 # Note: property inputmode is inherited
84  
85 # Note: property labels read-only is inherited
86  
87 # Note: property list read-only is inherited
88  
89 # Note: property max is inherited
90  
91 # Note: property maxLength is inherited
92  
93 # Note: property min is inherited
94  
95 # Note: property minLength is inherited
96  
97 0 ▶sub mozGetFileNameArray { return; }
Subroutine mozGetFileNameArray: not called CC=1 SCAR=6.9
Pod documented
98  
99 0 ▶sub mozSetFileArray { return; }
Subroutine mozSetFileArray: not called CC=1 SCAR=6.9
Pod documented
100  
101 # Note: property multiple is inherited
102  
103 # Note: property name is inherited
104  
105 0 ▶sub oninput : lvalue { return( shift->on( 'input', @_ ) ); }
Subroutine oninput: not called CC=1 SCAR=6.9
Pod undocumented
106  
107 0 ▶sub oninvalid : lvalue { return( shift->on( 'invalid', @_ ) ); }
Subroutine oninvalid: not called CC=1 SCAR=6.9
Pod undocumented
108  
109 0 ▶sub onsearch : lvalue { return( shift->on( 'search', @_ ) ); }
Subroutine onsearch: not called CC=1 SCAR=6.9
Pod undocumented
110  
111 0 ▶sub onselectionchange : lvalue { return( shift->on( 'selectionchange', @_ ) ); }
Subroutine onselectionchange: not called CC=1 SCAR=6.9
Pod undocumented
112  
113 # Note: property pattern is inherited
114  
115 # Note: property placeholder is inherited
116  
117 # Note: property readOnly is inherited
118  
119 # Note: property required is inherited
120  
121 # Note: property selectionDirection is inherited
122  
123 # Note: property selectionEnd is inherited
124  
125 # Note: property selectionStart is inherited
126  
127 # Note: property size is inherited
128  
129 # Note: property src is inherited
130  
131 # Note: property step is inherited
132  
133 21 ▶sub stepDown { return( shift->_set_up_down( { direction => 'down' }, @_ ) ); }
Subroutine stepDown: called CC=1 SCAR=0.0
Pod documented
134  
135 14 ▶sub stepUp { return( shift->_set_up_down( { direction => 'up' }, @_ ) ); }
Subroutine stepUp: called CC=1 SCAR=0.0
Pod documented
136  
137 # Note: property type is inherited
138  
139 # Note: deprecated property useMap is inherited
140  
141 # Note: property validationMessage read-only is inherited
142  
143 # Note: property validity read-only is inherited
144  
145 # Note: property value is inherited
146  
147 # Note: property valueAsDate is inherited
148  
149 # Note: property valueAsNumber is inherited
150  
151 # Note: property webkitEntries is inherited
152  
153 # Note: property webkitdirectory is inherited
154  
155 # Note: property width is inherited
156  
157 # Note: property willValidate read-only is inherited
158  
159 # date 1 (day) <input type="date" min="2019-12-25" step="1" />
160 # month 1 (month) <input type="month" min="2019-12" step="12" />
161 # week 1 (week) <input type="week" min="2019-W23" step="2" />
162 # time 60 (seconds) <input type="time" min="09:00" step="900" />
163 # datetime-local 1 (day) <input type="datetime-local" min="2019-12-25T19:30" step="7" />
164 # number 1 <input type="number" min="0" step="0.1" max="10" />
165 # range 1 <input type="range" min="0" step="2" max="10" />
166 #
167 # HTML::Object::InvalidStateError
168 sub _set_up_down
169 35 ▶{
Subroutine _set_up_down: called CC=76 SCAR=53.7
170 35 my $self = shift( @_ );
171 35 my $opts = shift( @_ );
172 35 my $incr = shift( @_ );
173 35 ▶ $incr = 1 if( !defined( $incr ) || !CORE::length( "$incr" ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $incr and length "$incr" 24 11 35
Condition66%2/3
defined $incr and length "$incr"
!ll&&!rl&&r
24011
MC/DC50%1/2
defined $incr and length "$incr"
defined $incr length "$incr"
Truth table66%2/3
A and B
A= defined $incrB= length "$incr"
ABresult
0X0
100
111
174 35 ▶ return( $self->error( "First argument must be an hash reference of parameters." ) ) if( ref( $opts ) ne 'HASH' );
Branch: 1 branch
BranchTrueFalseTotal
if ref $opts ne "HASH" 0 35 35
175 35 ▶ return( $self->error({
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_is_number($incr) 0 35 35
176 message => "Incremental value provided ($incr) is not a valid number.",
177 class => 'HTML::Object::SyntaxError',
178 }) ) if( !$self->_is_number( $incr ) );
179 # "If the value is a float, the value will increment as if Math.floor(stepDecrement) was passed. If the value is negative, the value will be incremented instead of decremented. "
180 # <https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement/stepDown>
181 35 $incr = POSIX::floor( "$incr" );
182 35 ▶ my $dir = $opts->{direction} // 'down';
Condition50%1/2
$opts->{"direction"} // "down"
l!l
350
MC/DC0%0/1
$opts->{"direction"} // "down"
$opts->{"direction"}
Truth table50%1/2
A
A= $opts->{"direction"}
Aresult
11
00
183 35 my $val = $self->value;
184 35 ▶ $self->_load_class( 'DateTime::Lite' ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->_load_class("DateTime::Lite") or return $self->pass_error 35 0 35
185 35 ▶ $self->_load_class( 'DateTime::Format::Lite' ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->_load_class("DateTime::Format::Lite") or return $self->pass_error 35 0 35
186 35 ▶ $self->_load_class( 'DateTime::Lite::Duration' ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->_load_class("DateTime::Lite::Duration") or return $self->pass_error 35 0 35
187 35 my $type2unit =
188 {
189 date => { unit => 'day', pattern => '%Y-%m-%d', default => '1970-01-01', step_re => qr/^\d+$/ },
190 month => { unit => 'month', pattern => '%Y-%m', default => '1970-01', step_re => qr/^\d+$/ },
191 week => { unit => 'week', pattern => '%Y-W%W', default => '1970-W1', step_re => qr/^\d+$/ },
192 'time' => { unit => 'second', pattern => ['%H:%M:%S','%H:%M'], default => '00:00:00', step_re => qr/^\d+$/, dt_format => '%02d:%02d', format => '%H:%M:%S' },
193 'datetime-local' => { unit => 'second', pattern => ['%Y-%m-%dT%H:%M:%S','%Y-%m-%dT%H:%M','%Y-%m-%dT%H'], default => '1970-01-01T00:00', step_re => qr/^\d+$/, format => '%Y-%m-%dT%H:%M:%S' },
194 number => { unit => 1, default => 0, step_re => qr/^\d+(?:\.\d+)?$/ },
195 range => { unit => 1, default => 0, step_re => qr/^\d+(?:\.\d+)?$/ },
196 };
197 35 ▶ my $type = $self->attr( 'type' ) || return( $self->error({
Condition50%1/2
$self->attr('type') || (return $self->error({'message', 'This input type has no type attribute.', 'class', 'HTML::Object::SyntaxError'}))
l!l
350
MC/DC0%0/1
$self->attr('type') || (return $self->error({'message', 'This input type has no type attribute.', 'class', 'HTML::Object::SyntaxError'}))
$self->attr('type')
Truth table50%1/2
A
A= $self->attr('type')
Aresult
11
00
198 message => "This input type has no type attribute.",
199 class => 'HTML::Object::SyntaxError',
200 }) );
201 35 ▶ my $def = $type2unit->{ $type } || return( $self->error({
Branch: 1 branch
BranchTrueFalseTotal
$dir eq 'up' ? : 0 0 0
Condition50%1/2
$type2unit->{$type} || (return $self->error({'message', qq[This input type "$type" is unsupported for ] . ($dir eq 'up' ? 'stepUp' : 'stepDown'), 'class', 'HTML::Object::InvalidStateError'}))
l!l
350
MC/DC0%0/1
$type2unit->{$type} || (return $self->error({'message', qq[This input type "$type" is unsupported for ] . ($dir eq 'up' ? 'stepUp' : 'stepDown'), 'class', 'HTML::Object::InvalidStateError'}))
$type2unit->{$type}
Truth table50%1/2
A
A= $type2unit->{$type}
Aresult
11
00
202 message => "This input type \"$type\" is unsupported for " . ( $dir eq 'up' ? 'stepUp' : 'stepDown' ),
203 class => 'HTML::Object::InvalidStateError',
204 }) );
205 35 my $min = $self->attr( 'min' );
206 35 my $max = $self->attr( 'max' );
207 35 my $step = $self->attr( 'step' );
208 35 ▶ $step = 1 if( !defined( $step ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $step 0 35 35
209 35 $step = $step + 0;
210 35 ▶ $step = 1 if( !CORE::length( $step ) || lc( $step ) eq 'any' || $step !~ /$def->{step_re}/ );
Branch: 1 branch
BranchTrueFalseTotal
if not length $step or lc $step eq "any" or not $step =~ /$def->{"step_re"}/ 0 35 35
Condition33%2/6
not length $step or lc $step eq "any" or not $step =~ /$def->{"step_re"}/
l!l&&r!l&&!r
0035
not length $step or lc $step eq "any"
l!l&&r!l&&!r
0035
MC/DC0%0/3
not length $step or lc $step eq "any" or not $step =~ /$def->{"step_re"}/
not length $step lc $step eq "any" not $step =~ /$def->{"step_re"}/
Truth table25%1/4
not(A) or B or not(C)
A= not length $stepB= lc $step eq "any"C= not $step =~ /$def->{"step_re"}/
ABCresult
1XX1
01X1
0011
0000
211 35 ▶ return( $self->error({
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_is_number($step) 0 35 35
Condition0%0/4
$step // "undef"
l!l
00
$step // "undef"
l!l
00
MC/DC0%0/1
$step // "undef"
$step
MC/DC0%0/1
$step // "undef"
$step
Truth table0%0/2
A
A= $step
Aresult
11
00
Truth table0%0/2
A
A= $step
Aresult
11
00
212 message => "This input step value provided '" . ( $step // 'undef' ) . "' (" . $self->_str_val( $step // 'undef' ) . ") is not a proper number.",
213 class => 'HTML::Object::SyntaxError',
214 }) ) if( !$self->_is_number( $step ) );
215  
216 35 my $parse;
217 $parse = sub
218 31 ▶ {
Subroutine __ANON__: called CC=9 SCAR=22.0
219 31 my $this = shift( @_ );
220 31 ▶ return( $this ) if( $type eq 'week' || $type eq 'number' || $type eq 'range' );
Branch: 1 branch
BranchTrueFalseTotal
if $type eq "week" or $type eq "number" or $type eq "range" 3 28 31
Condition83%5/6
$type eq "week" or $type eq "number" or $type eq "range"
l!l&&r!l&&!r
3028
$type eq "week" or $type eq "number"
l!l&&r!l&&!r
2128
MC/DC66%2/3
$type eq "week" or $type eq "number" or $type eq "range"
$type eq "week" $type eq "number" $type eq "range"
Truth table75%3/4
A or B or C
A= $type eq "week"B= $type eq "number"C= $type eq "range"
ABCresult
1XX1
01X1
0011
0000
221 28 my( $fmt, $dt );
222 28 ▶ if( ref( $def->{pattern} ) eq 'ARRAY' )
Branch: 1 branch
BranchTrueFalseTotal
if (ref $def->{'pattern'} eq 'ARRAY') { } 12 16 28
223 {
224 12 foreach my $pat ( @{$def->{pattern}} )
225 {
226 19 $fmt = DateTime::Format::Lite->new( pattern => $pat );
227 19 $dt = $fmt->parse_datetime( "$this" );
228 19 ▶ last if( $dt );
Branch: 1 branch
BranchTrueFalseTotal
if $dt 12 7 19
229 }
230 }
231 else
232 {
233 16 $fmt = DateTime::Format::Lite->new( pattern => $def->{pattern} );
234 16 $dt = $fmt->parse_datetime( "$this" );
235 }
236 28 ▶ if( !defined( $dt ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $dt) 0 28 28
237 {
238 0 return( $self->error({
239 message => "Unable to parse $type value \"$this\"': " . $fmt->errmsg,
240 class => 'HTML::Object::InvalidStateError',
241 }) );
242 }
243  
244 28 ▶ if( $def->{format} )
Branch: 1 branch
BranchTrueFalseTotal
if ($def->{'format'}) { } 12 16 28
245 {
246 12 $dt->set_formatter( DateTime::Format::Lite->new( pattern => $def->{format} ) );
247 }
248 else
249 {
250 16 $dt->set_formatter( $fmt );
251 }
252 28 return( $dt );
253 35 };
254  
255 35 ▶ $max //= '';
Condition100%2/2
$max //= ""
l!l
2312
MC/DC100%1/1
$max //= ""
$max
Truth table100%2/2
A
A= $max
Aresult
11
00
256 35 ▶ if( !defined( $val ) || !CORE::length( "$val" ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $val and length "$val") 10 25 35
Condition66%2/3
defined $val and length "$val"
!ll&&!rl&&r
10025
MC/DC50%1/2
defined $val and length "$val"
defined $val length "$val"
Truth table66%2/3
A and B
A= defined $valB= length "$val"
ABresult
0X0
100
111
257 {
258 # If min is provided and we are told to go up, min is our starting value and we return immediately.
259 # However, the reverse is not true, i.e. if we go down and max is defined, we do not start at max value. We would start at 00:00
260 10 ▶ if( $dir eq 'up' && defined( $min ) && CORE::length( "$min" ) )
Branch: 2 branches
BranchTrueFalseTotal
if ($dir eq 'up' and defined $min and length "$min") { } 4 6 10
elsif ($dir eq 'down' and defined $max and length "$max") { } 6 0 6
Condition66%4/6
$dir eq "up" and defined $min and length "$min"
!ll&&!rl&&r
604
$dir eq "up" and defined $min
!ll&&!rl&&r
604
MC/DC33%1/3
$dir eq "up" and defined $min and length "$min"
$dir eq "up" defined $min length "$min"
Truth table50%2/4
A and B and C
A= $dir eq "up"B= defined $minC= length "$min"
ABCresult
0XX0
10X0
1100
1111
261 {
262 4 ▶ if( exists( $type2unit->{ $type } ) )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $type2unit->{$type}) 4 0 4
263 {
264 4 my $this = $parse->( $min );
265 # return( $self->error({
266 # message => "Unable to parse $type minimum value \"$min\"': " . $fmt->errmsg,
267 # class => 'HTML::Object::InvalidStateError',
268 # }) ) if( !defined( $this ) );
269 4 ▶ return( $self->pass_error ) if( !defined( $this ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $this 0 4 4
270 4 $min = $this;
271 }
272 # $self->value = $min;
273 4 $self->value( $min );
274 4 return( $self );
275 }
276 ▶ elsif( $dir eq 'down' && defined( $max ) && CORE::length( "$max" ) )
Condition33%2/6
$dir eq "down" and defined $max and length "$max"
!ll&&!rl&&r
006
$dir eq "down" and defined $max
!ll&&!rl&&r
006
MC/DC0%0/3
$dir eq "down" and defined $max and length "$max"
$dir eq "down" defined $max length "$max"
Truth table25%1/4
A and B and C
A= $dir eq "down"B= defined $maxC= length "$max"
ABCresult
0XX0
10X0
1100
1111
277 {
278 6 ▶ if( exists( $type2unit->{ $type } ) )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $type2unit->{$type}) 6 0 6
279 {
280 6 my $this = $parse->( $max );
281 # return( $self->error({
282 # message => "Unable to parse $type maximum value \"$max\"': " . $fmt->errmsg,
283 # class => 'HTML::Object::InvalidStateError',
284 # }) ) if( !defined( $this ) );
285 6 ▶ return( $self->pass_error ) if( !defined( $this ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $this 0 6 6
286 6 $max = $this;
287 }
288 # $self->value = $max;
289 6 $self->value( $max );
290 6 return( $self );
291 }
292 else
293 {
294 0 $val = $def->{default};
295 }
296 }
297  
298 # try-catch
299 my $rv = eval
300 25 {
301 25 my $new;
302 25 ▶ if( $type eq 'number' || $type eq 'range' )
Branch: 2 branches
BranchTrueFalseTotal
if ($type eq 'number' or $type eq 'range') { } 5 20 25
elsif ($type eq 'week') { } 5 15 20
Condition66%2/3
$type eq "number" or $type eq "range"
l!l&&r!l&&!r
5020
MC/DC50%1/2
$type eq "number" or $type eq "range"
$type eq "number" $type eq "range"
Truth table66%2/3
A or B
A= $type eq "number"B= $type eq "range"
ABresult
1X1
011
000
303 {
304 5 ▶ $new = ( $dir eq 'up' )
Branch: 1 branch
BranchTrueFalseTotal
$dir eq 'up' ? : 2 3 5
305 ? ( $val + ( $step * $incr ) )
306 : ( $val - ( $step * $incr ) );
307 5 ▶ if( ( defined( $max ) && CORE::length( "$max" ) && $dir eq 'up' && $new > $max ) ||
Branch: 1 branch
BranchTrueFalseTotal
if (defined $max and length "$max" and $dir eq "up" and $new > $max or defined $min and length "$min" and $dir eq "down" and $new < $min) 2 3 5
Condition71%15/21
defined $max and length "$max" and $dir eq "up" and $new > $max or defined $min and length "$min" and $dir eq "down" and $new < $min
l!l&&r!l&&!r
113
defined $max and length "$max" and $dir eq "up" and $new > $max
!ll&&!rl&&r
311
defined $max and length "$max" and $dir eq "up"
!ll&&!rl&&r
032
defined $max and length "$max"
!ll&&!rl&&r
005
defined $min and length "$min" and $dir eq "down" and $new < $min
!ll&&!rl&&r
121
defined $min and length "$min" and $dir eq "down"
!ll&&!rl&&r
013
defined $min and length "$min"
!ll&&!rl&&r
004
MC/DC37%3/8
defined $max and length "$max" and $dir eq "up" and $new > $max or defined $min and length "$min" and $dir eq "down" and $new < $min
defined $max length "$max" $dir eq "up" $new > $max defined $min length "$min" $dir eq "down" $new < $min
Truth table19%4/21
A and B and C and D or E and F and G and H
A= defined $maxB= length "$max"C= $dir eq "up"D= $new > $maxE= defined $minF= length "$min"G= $dir eq "down"H= $new < $min
ABCDEFGHresult
1111XXXX1
0XXX11111
10XX11111
110X11111
111011111
0XXX0XXX0
0XXX10XX0
0XXX110X0
0XXX11100
10XX0XXX0
10XX10XX0
10XX110X0
10XX11100
110X0XXX0
110X10XX0
110X110X0
110X11100
11100XXX0
111010XX0
1110110X0
111011100
308 ( defined( $min ) && CORE::length( "$min" ) && $dir eq 'down' && $new < $min ) )
309 {
310 2 return( $self );
311 }
312 }
313 # We manage it ourself, i.e. without using DateTime::Format::Lite, beecause
314 # the parser does not seem capable of recognising format like 2021-W23 even with
315 # the proper pattern
316 elsif( $type eq 'week' )
317 {
318 5 ▶ if( $val =~ /^(\d{1,})-W(\d{1,2})$/ )
Branch: 1 branch
BranchTrueFalseTotal
if ($val =~ /^(\d{1,})-W(\d{1,2})$/) { } 5 0 5
319 {
320 5 my( $y, $w ) = ( $1, $2 );
321 5 ▶ return( $self->error({
Branch: 1 branch
BranchTrueFalseTotal
if int $w > 52 0 5 5
322 message => "Week number found \"$w\" is higher than the maximum possible 52",
323 class => 'HTML::Object::InvalidStateError',
324 }) ) if( int( $w ) > 52 );
325 5 ▶ return( $self->error({
Branch: 1 branch
BranchTrueFalseTotal
if int $w < 1 0 5 5
326 message => "Week number found \"$w\" is lower than the minimum possible 1",
327 class => 'HTML::Object::InvalidStateError',
328 }) ) if( int( $w ) < 1 );
329 5 my $dt = DateTime::Lite->from_day_of_year( year => $y, day_of_year => ( $w * 7 ) );
330 5 my $fmt = DateTime::Format::Lite->new( pattern => $def->{pattern} );
331 5 $dt->set_formatter( $fmt );
332  
333 5 ▶ if( $dir eq 'up' )
Branch: 1 branch
BranchTrueFalseTotal
if ($dir eq 'up') { } 2 3 5
334 {
335 2 $dt->add( weeks => ( $step * $incr ) );
336 }
337 else
338 {
339 3 $dt->subtract( weeks => ( $step * $incr ) );
340 }
341  
342 5 ▶ if( $dir eq 'down' && defined( $min ) && CORE::length( "$min" ) )
Branch: 2 branches
BranchTrueFalseTotal
if ($dir eq 'down' and defined $min and length "$min") { } 1 4 5
elsif ($dir eq 'up' and defined $max and length "$max") { } 0 6 6
Condition83%5/6
$dir eq "down" and defined $min and length "$min"
!ll&&!rl&&r
401
$dir eq "down" and defined $min
!ll&&!rl&&r
221
MC/DC66%2/3
$dir eq "down" and defined $min and length "$min"
$dir eq "down" defined $min length "$min"
Truth table75%3/4
A and B and C
A= $dir eq "down"B= defined $minC= length "$min"
ABCresult
0XX0
10X0
1100
1111
343 {
344 1 my( $min_year, $min_week );
345 1 ▶ if( $min =~ /^(\d{1,})-W(\d{1,2})$/ )
Branch: 1 branch
BranchTrueFalseTotal
if ($min =~ /^(\d{1,})-W(\d{1,2})$/) { } 1 0 1
346 {
347 1 ( $min_year, $min_week ) = ( $1, $2 );
348 1 ▶ return( $self->error({
Branch: 1 branch
BranchTrueFalseTotal
if int $min_week > 52 0 1 1
349 message => "Minimum week number found \"$min_week\" is higher than the maximum possible 52",
350 class => 'HTML::Object::InvalidStateError',
351 }) ) if( int( $min_week ) > 52 );
352 1 ▶ return( $self->error({
Branch: 1 branch
BranchTrueFalseTotal
if int $min_week < 1 0 1 1
353 message => "Minimum week number found \"$min_week\" is lower than the minimum possible 1",
354 class => 'HTML::Object::InvalidStateError',
355 }) ) if( int( $min_week ) < 1 );
356 1 my $dt_min = DateTime::Lite->from_day_of_year( year => $min_year, day_of_year => ( $min_week * 7 ) );
357 1 $dt_min->set_formatter( $fmt );
358 1 ▶ if( $dt < $dt_min )
Branch: 1 branch
BranchTrueFalseTotal
if ($dt < $dt_min) 1 0 1
359 {
360 # Silently refuse to comply, as browsers do
361 1 return( $self );
362 }
363 }
364 else
365 {
366 0 return( $self->error({
367 message => "Unable to parse $type minimum value \"$min\"': unsupported format. It should be 2021-W20 for example.",
368 class => 'HTML::Object::InvalidStateError',
369 }) );
370 }
371 }
372 ▶ elsif( $dir eq 'up' && defined( $max ) && CORE::length( "$max" ) )
Condition66%4/6
$dir eq "up" and defined $max and length "$max"
!ll&&!rl&&r
220
$dir eq "up" and defined $max
!ll&&!rl&&r
202
MC/DC0%0/3
$dir eq "up" and defined $max and length "$max"
$dir eq "up" defined $max length "$max"
Truth table50%2/4
A and B and C
A= $dir eq "up"B= defined $maxC= length "$max"
ABCresult
0XX0
10X0
1100
1111
373 {
374 0 my( $max_year, $max_week );
375 0 ▶ if( $max =~ /^(\d{1,})-W(\d{1,2})$/ )
Branch: 1 branch
BranchTrueFalseTotal
if ($max =~ /^(\d{1,})-W(\d{1,2})$/) { } 0 0 0
376 {
377 0 ( $max_year, $max_week ) = ( $1, $2 );
378 0 ▶ return( $self->error({
Branch: 1 branch
BranchTrueFalseTotal
if int $max_week > 52 0 0 0
379 message => "Maximum week number found \"$max_week\" is higher than the maximum possible 52",
380 class => 'HTML::Object::InvalidStateError',
381 }) ) if( int( $max_week ) > 52 );
382 0 ▶ return( $self->error({
Branch: 1 branch
BranchTrueFalseTotal
if int $max_week < 1 0 0 0
383 message => "Maximum week number found \"$max_week\" is lower than the minimum possible 1",
384 class => 'HTML::Object::InvalidStateError',
385 }) ) if( int( $max_week ) < 1 );
386 0 my $dt_max = DateTime::Lite->from_day_of_year( year => $max_year, day_of_year => ( $max_week * 7 ) );
387 0 $dt_max->set_formatter( $fmt );
388 0 ▶ if( $dt > $dt_max )
Branch: 1 branch
BranchTrueFalseTotal
if ($dt > $dt_max) 0 0 0
389 {
390 # Silently refuse to comply, as browsers do
391 0 return( $self );
392 }
393 }
394 else
395 {
396 0 return( $self->error({
397 message => "Unable to parse $type maximum value \"$max\"': unsupported format. It should be 2021-W20 for example.",
398 class => 'HTML::Object::InvalidStateError',
399 }) );
400 }
401 }
402 4 $new = "$dt";
403 }
404 else
405 {
406 0 return( $self->error({
407 message => "Unable to parse $type value \"$val\"': unsupported format. It should be 2021-W20 for example.",
408 class => 'HTML::Object::InvalidStateError',
409 }) );
410 }
411 }
412 else
413 {
414 15 my $dt = $parse->( $val );
415 15 ▶ return( $self->pass_error ) if( !defined( $dt ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $dt 0 15 15
416 # We can pass negative number to duration
417 15 my $interval = DateTime::Lite::Duration->new( "$def->{unit}s" => ( $step * $incr ) );
418 15 ▶ if( $dir eq 'up' )
Branch: 1 branch
BranchTrueFalseTotal
if ($dir eq 'up') { } 6 9 15
419 {
420 6 $dt->add_duration( $interval );
421 }
422 else
423 {
424 9 $dt->subtract_duration( $interval );
425 }
426  
427  
428 15 ▶ if( $dir eq 'down' && defined( $min ) && CORE::length( "$min" ) )
Branch: 2 branches
BranchTrueFalseTotal
if ($dir eq 'down' and defined $min and length "$min") { } 3 12 15
elsif ($dir eq 'up' and defined $max and length "$max") { } 3 15 18
Condition83%5/6
$dir eq "down" and defined $min and length "$min"
!ll&&!rl&&r
1203
$dir eq "down" and defined $min
!ll&&!rl&&r
663
MC/DC66%2/3
$dir eq "down" and defined $min and length "$min"
$dir eq "down" defined $min length "$min"
Truth table75%3/4
A and B and C
A= $dir eq "down"B= defined $minC= length "$min"
ABCresult
0XX0
10X0
1100
1111
429 {
430 3 my $dt_min = $parse->( "$min" );
431 3 ▶ if( !defined( $dt_min ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $dt_min) 0 3 3
432 {
433 # return( $self->error({
434 # message => "Unable to parse $type minimum value \"$min\"': " . $fmt->errmsg,
435 # class => 'HTML::Object::InvalidStateError',
436 # }) );
437 0 return( $self->pass_error );
438 }
439 # $dt_min->set_formatter( $fmt );
440 3 ▶ if( $dt < $dt_min )
Branch: 1 branch
BranchTrueFalseTotal
if ($dt < $dt_min) 3 0 3
441 {
442 # Silently refuse to comply, as browsers do
443 3 return( $self );
444 }
445 }
446 ▶ elsif( $dir eq 'up' && defined( $max ) && CORE::length( "$max" ) )
Condition83%5/6
$dir eq "up" and defined $max and length "$max"
!ll&&!rl&&r
633
$dir eq "up" and defined $max
!ll&&!rl&&r
606
MC/DC66%2/3
$dir eq "up" and defined $max and length "$max"
$dir eq "up" defined $max length "$max"
Truth table75%3/4
A and B and C
A= $dir eq "up"B= defined $maxC= length "$max"
ABCresult
0XX0
10X0
1100
1111
447 {
448 3 my $dt_max = $parse->( "$max" );
449 3 ▶ if( !defined( $dt_max ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $dt_max) 0 3 3
450 {
451 # return( $self->error({
452 # message => "Unable to parse $type maximum value \"$max\"': " . $fmt->errmsg,
453 # class => 'HTML::Object::InvalidStateError',
454 # }) );
455 0 return( $self->pass_error );
456 }
457 # $dt_max->set_formatter( $fmt );
458 3 ▶ if( $dt > $dt_max )
Branch: 1 branch
BranchTrueFalseTotal
if ($dt > $dt_max) 3 0 3
459 {
460 # Silently refuse to comply, as browsers do
461 3 return( $self );
462 }
463 }
464 9 $new = "$dt";
465 }
466 # $self->value = $new;
467 16 $self->value( $new );
468 16 return( $self );
469 };
470 25 ▶ if( $@ )
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 25 25
471 {
472 return( $self->error({
473 0 ▶ message => "Error " . ( $opts->{direction} ? 'increasing' : 'decreasing' ) . " the input value: $@",
Branch: 1 branch
BranchTrueFalseTotal
$opts->{'direction'} ? : 0 0 0
474 class => 'HTML::Object::InvalidStateError',
475 }) );
476 }
477 25 return( $rv );
478 }
479  
480 5 1;
481 # NOTE: POD
482 __END__
« Object/DOM/List.pm ↑ Summary Object/XPath/Expr.pm »