| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package HTML::CheckArgs::integer; |
|
2
|
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
6
|
use strict; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
37
|
|
|
4
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
30
|
|
|
5
|
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
6
|
use base 'HTML::CheckArgs::Object'; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
723
|
|
|
7
|
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
sub is_valid { |
|
9
|
10
|
|
|
10
|
0
|
13
|
my $self = shift; |
|
10
|
|
|
|
|
|
|
|
|
11
|
10
|
|
|
|
|
29
|
my $value = $self->value; |
|
12
|
10
|
|
|
|
|
35
|
my $config = $self->config; |
|
13
|
|
|
|
|
|
|
|
|
14
|
10
|
|
|
|
|
54
|
$self->check_params( required => [], optional => [ qw( min max ) ], cleanable => 0 ); |
|
15
|
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
# no value passed in |
|
17
|
|
|
|
|
|
|
# zero is a valid integer, so we can't just check !$value |
|
18
|
10
|
100
|
100
|
|
|
100
|
if ( $config->{required} && ( !defined( $value ) || $value eq '' ) ) { |
|
|
|
100
|
66
|
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
19
|
2
|
|
|
|
|
15
|
$self->error_code( 'integer_00' ); # required |
|
20
|
2
|
|
|
|
|
9
|
$self->error_message( 'Not given.' ); |
|
21
|
2
|
|
|
|
|
8
|
return; |
|
22
|
|
|
|
|
|
|
} elsif ( !$config->{required} && ( !defined( $value ) || $value eq '' ) ) { |
|
23
|
1
|
|
|
|
|
5
|
return 1; |
|
24
|
|
|
|
|
|
|
} |
|
25
|
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
# is it valid? |
|
27
|
7
|
50
|
|
|
|
35
|
unless ( $value =~ m/^[-+]?\d+$/ ) { |
|
28
|
0
|
|
|
|
|
0
|
$self->error_code( 'integer_01' ); # not valid |
|
29
|
0
|
|
|
|
|
0
|
$self->error_message( 'Not a valid integer.' ); |
|
30
|
0
|
|
|
|
|
0
|
return; |
|
31
|
|
|
|
|
|
|
} |
|
32
|
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
# check parameters |
|
34
|
|
|
|
|
|
|
# legal ones are min and max |
|
35
|
7
|
|
|
|
|
9
|
my ( $min, $max ); |
|
36
|
7
|
|
|
|
|
14
|
$min = $config->{params}{min}; |
|
37
|
7
|
|
|
|
|
13
|
$max = $config->{params}{max}; |
|
38
|
|
|
|
|
|
|
|
|
39
|
7
|
100
|
100
|
|
|
31
|
if ( defined( $min ) && ( $value < $min ) ) { |
|
40
|
1
|
|
|
|
|
6
|
$self->error_code( 'integer_02' ); # under min |
|
41
|
1
|
|
|
|
|
7
|
$self->error_message( "Less than the minimum required ($min)." ); |
|
42
|
1
|
|
|
|
|
4
|
return; |
|
43
|
|
|
|
|
|
|
} |
|
44
|
|
|
|
|
|
|
|
|
45
|
6
|
100
|
100
|
|
|
20
|
if ( defined( $max ) && ( $value > $max ) ) { |
|
46
|
1
|
|
|
|
|
5
|
$self->error_code( 'integer_03' ); # over max |
|
47
|
1
|
|
|
|
|
6
|
$self->error_message( "More than the maximum allowed ($max)." ); |
|
48
|
1
|
|
|
|
|
4
|
return; |
|
49
|
|
|
|
|
|
|
} |
|
50
|
|
|
|
|
|
|
|
|
51
|
5
|
|
|
|
|
28
|
return 1; |
|
52
|
|
|
|
|
|
|
} |
|
53
|
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
1; |