line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Checkster; |
2
|
|
|
|
|
|
|
# ABSTRACT: Checkster is a check perl module |
3
|
|
|
|
|
|
|
|
4
|
5
|
|
|
5
|
|
98612
|
use 5.010; |
|
5
|
|
|
|
|
17
|
|
|
5
|
|
|
|
|
188
|
|
5
|
5
|
|
|
5
|
|
23
|
use strict; |
|
5
|
|
|
|
|
8
|
|
|
5
|
|
|
|
|
149
|
|
6
|
5
|
|
|
5
|
|
25
|
use warnings; |
|
5
|
|
|
|
|
13
|
|
|
5
|
|
|
|
|
246
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our $VERSION = '0.001'; |
9
|
|
|
|
|
|
|
|
10
|
5
|
|
|
5
|
|
30
|
use Exporter 'import'; |
|
5
|
|
|
|
|
34
|
|
|
5
|
|
|
|
|
4429
|
|
11
|
|
|
|
|
|
|
our @EXPORT_OK = qw(check); |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
# constructor |
15
|
|
|
|
|
|
|
sub new { |
16
|
32
|
|
|
32
|
0
|
560
|
my $class = shift; |
17
|
|
|
|
|
|
|
|
18
|
32
|
|
33
|
|
|
177
|
return bless { |
19
|
|
|
|
|
|
|
_operator => undef, |
20
|
|
|
|
|
|
|
}, $class || ref $class; |
21
|
|
|
|
|
|
|
} |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
# accessors |
25
|
|
|
|
|
|
|
sub check { |
26
|
31
|
|
|
31
|
0
|
18388
|
return Checkster->new(@_); |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub Checkster::not { |
30
|
4
|
|
|
4
|
0
|
7
|
my $self = shift; |
31
|
4
|
|
|
|
|
10
|
$self->_operator('not'); |
32
|
|
|
|
|
|
|
|
33
|
4
|
|
|
|
|
10
|
$self |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub any { |
37
|
4
|
|
|
4
|
0
|
5
|
my $self = shift; |
38
|
4
|
|
|
|
|
7
|
$self->_operator('any'); |
39
|
|
|
|
|
|
|
|
40
|
4
|
|
|
|
|
20
|
$self |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
sub all { |
44
|
4
|
|
|
4
|
0
|
5
|
my $self = shift; |
45
|
4
|
|
|
|
|
8
|
$self->_operator('all'); |
46
|
|
|
|
|
|
|
|
47
|
4
|
|
|
|
|
11
|
$self |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
sub op { |
51
|
70
|
|
|
70
|
0
|
279
|
return shift->{_operator}; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
# type check |
55
|
|
|
|
|
|
|
sub Checkster::array { |
56
|
6
|
|
|
6
|
0
|
5
|
my $self = shift; |
57
|
6
|
100
|
|
|
|
13
|
my $value = @_ > 1 ? \@_ : [ shift ]; |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
# one param test |
60
|
6
|
100
|
|
|
|
15
|
if(int(@$value) == 1){ |
61
|
4
|
100
|
|
|
|
9
|
return ref $value->[0] eq 'ARRAY' ? 1 : 0 unless $self->op; |
|
|
100
|
|
|
|
|
|
62
|
1
|
50
|
33
|
|
|
2
|
return ref $value->[0] eq 'ARRAY' ? 0 : 1 if $self->op && $self->op eq 'not'; |
|
|
50
|
|
|
|
|
|
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
# multi param test |
66
|
2
|
50
|
|
|
|
6
|
if(int(@$value) > 1){ |
67
|
2
|
|
|
|
|
3
|
my $res = 0; |
68
|
|
|
|
|
|
|
|
69
|
2
|
100
|
66
|
|
|
3
|
do { $res = 1; map { $res = 0 unless ref $_ eq 'ARRAY' } @$value } |
|
1
|
100
|
|
|
|
2
|
|
|
1
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
8
|
|
70
|
|
|
|
|
|
|
if !$self->op || $self->op eq 'all'; |
71
|
|
|
|
|
|
|
|
72
|
2
|
100
|
66
|
|
|
6
|
map { $res = 1 if ref $_ eq 'ARRAY' } @$value |
|
2
|
100
|
|
|
|
14
|
|
73
|
|
|
|
|
|
|
if $self->op && $self->op eq 'any'; |
74
|
|
|
|
|
|
|
|
75
|
2
|
|
|
|
|
5
|
return $res; |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
sub number { |
80
|
6
|
|
|
6
|
0
|
7
|
my $self = shift; |
81
|
6
|
100
|
|
|
|
14
|
my $value = @_ > 1 ? \@_ : [ shift ]; |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
# one param test |
84
|
6
|
100
|
|
|
|
14
|
if(int(@$value) == 1){ |
85
|
3
|
100
|
|
|
|
5
|
return $value->[0] =~ /^[\d\.\,]+$/ ? 1 : 0 unless $self->op; |
|
|
100
|
|
|
|
|
|
86
|
1
|
50
|
33
|
|
|
2
|
return $value->[0] =~ /^[\d\.\,]+$/ ? 0 : 1 if $self->op && $self->op eq 'not'; |
|
|
50
|
|
|
|
|
|
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
# multi param test |
90
|
3
|
50
|
|
|
|
9
|
if(int(@$value) > 1){ |
91
|
3
|
|
|
|
|
5
|
my $res = 0; |
92
|
|
|
|
|
|
|
|
93
|
3
|
100
|
100
|
|
|
5
|
do { $res = 1; map { $res = 0 unless $_ =~ /^[\d\.\,]+$/ } @$value } |
|
2
|
100
|
|
|
|
3
|
|
|
2
|
|
|
|
|
4
|
|
|
5
|
|
|
|
|
29
|
|
94
|
|
|
|
|
|
|
if !$self->op || $self->op eq 'all'; |
95
|
|
|
|
|
|
|
|
96
|
3
|
100
|
100
|
|
|
6
|
map { $res = 1 if ref $_ eq 'ARRAY' } @$value |
|
2
|
100
|
|
|
|
9
|
|
97
|
|
|
|
|
|
|
if $self->op && $self->op eq 'any'; |
98
|
|
|
|
|
|
|
|
99
|
3
|
|
|
|
|
423
|
return $res; |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
# bool checkers |
104
|
|
|
|
|
|
|
sub true { |
105
|
18
|
|
|
18
|
0
|
17
|
my $self = shift; |
106
|
18
|
100
|
|
|
|
64
|
my $value = @_ > 1 ? \@_ : [ shift ]; |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
# one param test |
109
|
18
|
100
|
|
|
|
41
|
if(int(@$value) == 1){ |
110
|
7
|
100
|
|
|
|
14
|
return $value->[0] ? 1 : 0 unless $self->op; |
|
|
100
|
|
|
|
|
|
111
|
2
|
100
|
33
|
|
|
4
|
return $value->[0]? 0 : 1 if $self->op && $self->op eq 'not'; |
|
|
50
|
|
|
|
|
|
112
|
|
|
|
|
|
|
} |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
# multi param test |
115
|
11
|
50
|
|
|
|
30
|
if(int(@$value) > 1){ |
116
|
11
|
|
|
|
|
11
|
my $res = 0; |
117
|
|
|
|
|
|
|
|
118
|
11
|
100
|
100
|
|
|
14
|
do { $res = 1; map { $res = 0 unless $_ } @$value } |
|
9
|
100
|
|
|
|
9
|
|
|
9
|
|
|
|
|
14
|
|
|
22
|
|
|
|
|
51
|
|
119
|
|
|
|
|
|
|
if !$self->op || $self->op eq 'all'; |
120
|
|
|
|
|
|
|
|
121
|
11
|
100
|
100
|
|
|
17
|
map { $res = 1 if $_ } @$value |
|
7
|
100
|
|
|
|
16
|
|
122
|
|
|
|
|
|
|
if $self->op && $self->op eq 'any'; |
123
|
|
|
|
|
|
|
|
124
|
11
|
|
|
|
|
30
|
return $res; |
125
|
|
|
|
|
|
|
} |
126
|
|
|
|
|
|
|
} |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
sub false { |
129
|
4
|
|
|
4
|
0
|
7
|
return !shift->true(@_); |
130
|
|
|
|
|
|
|
} |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
# private methods |
134
|
|
|
|
|
|
|
sub _operator { |
135
|
12
|
|
|
12
|
|
11
|
my $self = shift; |
136
|
12
|
50
|
|
|
|
36
|
$self->{_operator} = $_[0] if $_[0]; |
137
|
|
|
|
|
|
|
} |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
1; |
140
|
|
|
|
|
|
|
__END__ |