| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Mojolicious::Plugin::Vparam::Filters; |
|
2
|
72
|
|
|
72
|
|
5300675
|
use Mojo::Base -strict; |
|
|
72
|
|
|
|
|
9534
|
|
|
|
72
|
|
|
|
|
554
|
|
|
3
|
72
|
|
|
72
|
|
8588
|
use Mojolicious::Plugin::Vparam::Common qw(load_class); |
|
|
72
|
|
|
|
|
326
|
|
|
|
72
|
|
|
|
|
4078
|
|
|
4
|
72
|
|
|
72
|
|
941
|
use List::MoreUtils qw(any); |
|
|
72
|
|
|
|
|
6348
|
|
|
|
72
|
|
|
|
|
1376
|
|
|
5
|
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
sub like($$) { |
|
7
|
24
|
50
|
|
24
|
0
|
68
|
return 'Value not defined' unless defined $_[0]; |
|
8
|
24
|
100
|
|
|
|
202
|
return 'Wrong format' unless $_[0] =~ $_[1]; |
|
9
|
15
|
|
|
|
|
110
|
return 0; |
|
10
|
|
|
|
|
|
|
} |
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub in($$) { |
|
13
|
11
|
|
|
11
|
0
|
27
|
my ($str, $list) = @_; |
|
14
|
|
|
|
|
|
|
|
|
15
|
11
|
50
|
|
|
|
40
|
die 'Not ArrayRef' unless 'ARRAY' eq ref $list; |
|
16
|
|
|
|
|
|
|
|
|
17
|
11
|
100
|
|
|
|
30
|
return 'Value not defined' unless defined $str; |
|
18
|
|
|
|
|
|
|
return 'Wrong value' |
|
19
|
10
|
50
|
|
28
|
|
71
|
unless any {defined($_) && $str eq $_} @$list; |
|
|
28
|
100
|
|
|
|
234
|
|
|
20
|
|
|
|
|
|
|
|
|
21
|
5
|
|
|
|
|
37
|
return 0; |
|
22
|
|
|
|
|
|
|
} |
|
23
|
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub size($$$) { |
|
25
|
12
|
|
|
12
|
0
|
28
|
my ($value, $min, $max) = @_; |
|
26
|
12
|
100
|
|
|
|
29
|
return 'Value is not defined' unless defined $value; |
|
27
|
10
|
100
|
|
|
|
31
|
return 'Value is not set' unless length $value; |
|
28
|
9
|
100
|
|
|
|
27
|
return sprintf "Value should not be less than %s", $min |
|
29
|
|
|
|
|
|
|
unless $min <= length $value; |
|
30
|
8
|
100
|
|
|
|
30
|
return sprintf "Value should not be longer than %s", $max |
|
31
|
|
|
|
|
|
|
unless $max >= length $value; |
|
32
|
6
|
|
|
|
|
15
|
return 0; |
|
33
|
|
|
|
|
|
|
} |
|
34
|
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
sub num_ge($$) { |
|
36
|
11
|
|
|
11
|
0
|
36
|
my $e = load_class('Mojolicious::Plugin::Vparam::Numbers'); |
|
37
|
11
|
50
|
|
|
|
1084
|
die $e if $e; |
|
38
|
|
|
|
|
|
|
|
|
39
|
11
|
|
|
|
|
43
|
my $numeric = Mojolicious::Plugin::Vparam::Numbers::check_numeric( $_[0] ); |
|
40
|
11
|
100
|
|
|
|
39
|
return $numeric if $numeric; |
|
41
|
|
|
|
|
|
|
|
|
42
|
7
|
100
|
|
|
|
34
|
return sprintf "Value should not be greater than %s", $_[1] |
|
43
|
|
|
|
|
|
|
unless $_[0] >= $_[1]; |
|
44
|
4
|
|
|
|
|
14
|
return 0; |
|
45
|
|
|
|
|
|
|
} |
|
46
|
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
sub num_le($$) { |
|
48
|
7
|
|
|
7
|
0
|
24
|
my $e = load_class('Mojolicious::Plugin::Vparam::Numbers'); |
|
49
|
7
|
50
|
|
|
|
602
|
die $e if $e; |
|
50
|
|
|
|
|
|
|
|
|
51
|
7
|
|
|
|
|
27
|
my $numeric = Mojolicious::Plugin::Vparam::Numbers::check_numeric( $_[0] ); |
|
52
|
7
|
100
|
|
|
|
64
|
return $numeric if $numeric; |
|
53
|
|
|
|
|
|
|
|
|
54
|
6
|
100
|
|
|
|
44
|
return sprintf "Value should not be less than %s", $_[1] |
|
55
|
|
|
|
|
|
|
unless $_[0] <= $_[1]; |
|
56
|
2
|
|
|
|
|
5
|
return 0; |
|
57
|
|
|
|
|
|
|
} |
|
58
|
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
sub num_eq($$) { |
|
60
|
3
|
|
|
3
|
0
|
12
|
my $e = load_class('Mojolicious::Plugin::Vparam::Numbers'); |
|
61
|
3
|
50
|
|
|
|
304
|
die $e if $e; |
|
62
|
|
|
|
|
|
|
|
|
63
|
3
|
|
|
|
|
12
|
my $numeric = Mojolicious::Plugin::Vparam::Numbers::check_numeric( $_[0] ); |
|
64
|
3
|
100
|
|
|
|
14
|
return $numeric if $numeric; |
|
65
|
|
|
|
|
|
|
|
|
66
|
2
|
100
|
|
|
|
12
|
return sprintf "Value not equal" unless $_[0] == $_[1]; |
|
67
|
1
|
|
|
|
|
4
|
return 0; |
|
68
|
|
|
|
|
|
|
} |
|
69
|
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
sub num_ne($$) { |
|
71
|
3
|
|
|
3
|
0
|
17
|
my $e = load_class('Mojolicious::Plugin::Vparam::Numbers'); |
|
72
|
3
|
50
|
|
|
|
440
|
die $e if $e; |
|
73
|
|
|
|
|
|
|
|
|
74
|
3
|
|
|
|
|
18
|
my $numeric = Mojolicious::Plugin::Vparam::Numbers::check_numeric( $_[0] ); |
|
75
|
3
|
100
|
|
|
|
18
|
return $numeric if $numeric; |
|
76
|
|
|
|
|
|
|
|
|
77
|
2
|
100
|
|
|
|
13
|
return sprintf "Value equal" unless $_[0] != $_[1]; |
|
78
|
1
|
|
|
|
|
5
|
return 0; |
|
79
|
|
|
|
|
|
|
} |
|
80
|
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
sub num_range($$$) { |
|
82
|
5
|
|
|
5
|
0
|
21
|
my $min = num_ge $_[0] => $_[1]; |
|
83
|
5
|
100
|
|
|
|
17
|
return $min if $min; |
|
84
|
|
|
|
|
|
|
|
|
85
|
3
|
|
|
|
|
12
|
my $max = num_le $_[0] => $_[2]; |
|
86
|
3
|
100
|
|
|
|
13
|
return $max if $max; |
|
87
|
|
|
|
|
|
|
|
|
88
|
1
|
|
|
|
|
4
|
return 0; |
|
89
|
|
|
|
|
|
|
} |
|
90
|
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
sub str_lt($$) { |
|
92
|
1
|
50
|
|
1
|
0
|
3
|
return 'Value is not defined' unless defined $_[0]; |
|
93
|
1
|
50
|
|
|
|
6
|
return sprintf "Value should not be less than %s", $_[1] |
|
94
|
|
|
|
|
|
|
unless $_[0] lt $_[1]; |
|
95
|
1
|
|
|
|
|
3
|
return 0; |
|
96
|
|
|
|
|
|
|
} |
|
97
|
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
sub str_gt($$) { |
|
99
|
1
|
50
|
|
1
|
0
|
4
|
return 'Value is not defined' unless defined $_[0]; |
|
100
|
1
|
50
|
|
|
|
3
|
return sprintf "Value should not be greater than %s", $_[1] |
|
101
|
|
|
|
|
|
|
unless $_[0] gt $_[1]; |
|
102
|
1
|
|
|
|
|
3
|
return 0; |
|
103
|
|
|
|
|
|
|
} |
|
104
|
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
sub str_le($$) { |
|
106
|
1
|
50
|
|
1
|
0
|
3
|
return 'Value is not defined' unless defined $_[0]; |
|
107
|
1
|
50
|
|
|
|
4
|
return sprintf "Value should not be less or equal than %s", $_[1] |
|
108
|
|
|
|
|
|
|
unless $_[0] le $_[1]; |
|
109
|
1
|
|
|
|
|
3
|
return 0; |
|
110
|
|
|
|
|
|
|
} |
|
111
|
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
sub str_ge($$) { |
|
113
|
1
|
50
|
|
1
|
0
|
3
|
return 'Value is not defined' unless defined $_[0]; |
|
114
|
1
|
50
|
|
|
|
4
|
return sprintf "Value should not be greater or equal than %s", $_[1] |
|
115
|
|
|
|
|
|
|
unless $_[0] ge $_[1]; |
|
116
|
1
|
|
|
|
|
2
|
return 0; |
|
117
|
|
|
|
|
|
|
} |
|
118
|
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
sub str_cmp($$) { |
|
120
|
1
|
50
|
|
1
|
0
|
4
|
return 'Value is not defined' unless defined $_[0]; |
|
121
|
1
|
50
|
|
|
|
3
|
return sprintf "Value not equal" if $_[0] cmp $_[1]; |
|
122
|
1
|
|
|
|
|
2
|
return 0; |
|
123
|
|
|
|
|
|
|
} |
|
124
|
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
sub str_eq($$) { |
|
126
|
1
|
50
|
|
1
|
0
|
5
|
return 'Value is not defined' unless defined $_[0]; |
|
127
|
1
|
50
|
|
|
|
3
|
return sprintf "Value not equal" unless $_[0] eq $_[1]; |
|
128
|
1
|
|
|
|
|
2
|
return 0; |
|
129
|
|
|
|
|
|
|
} |
|
130
|
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
sub str_ne($$) { |
|
132
|
1
|
50
|
|
1
|
0
|
5
|
return 'Value is not defined' unless defined $_[0]; |
|
133
|
1
|
50
|
|
|
|
4
|
return sprintf "Value equal" unless $_[0] ne $_[1]; |
|
134
|
1
|
|
|
|
|
2
|
return 0; |
|
135
|
|
|
|
|
|
|
} |
|
136
|
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
sub register { |
|
138
|
74
|
|
|
74
|
0
|
260
|
my ($class, $self, $app, $conf) = @_; |
|
139
|
|
|
|
|
|
|
|
|
140
|
74
|
|
|
24
|
|
1171
|
$app->vfilter(regexp => sub { like $_[1], $_[2] } ); |
|
|
24
|
|
|
|
|
75
|
|
|
141
|
74
|
|
|
11
|
|
741
|
$app->vfilter(in => sub { in $_[1], $_[2] } ); |
|
|
11
|
|
|
|
|
38
|
|
|
142
|
74
|
|
|
12
|
|
693
|
$app->vfilter(size => sub { size $_[1], $_[2][0], $_[2][1] } ); |
|
|
12
|
|
|
|
|
37
|
|
|
143
|
|
|
|
|
|
|
|
|
144
|
74
|
|
|
6
|
|
591
|
$app->vfilter(min => sub { num_ge $_[1], $_[2] } ); |
|
|
6
|
|
|
|
|
19
|
|
|
145
|
74
|
|
|
4
|
|
637
|
$app->vfilter(max => sub { num_le $_[1], $_[2] } ); |
|
|
4
|
|
|
|
|
17
|
|
|
146
|
74
|
|
|
3
|
|
594
|
$app->vfilter(equal => sub { num_eq $_[1], $_[2] } ); |
|
|
3
|
|
|
|
|
14
|
|
|
147
|
74
|
|
|
3
|
|
592
|
$app->vfilter('not' => sub { num_ne $_[1], $_[2] } ); |
|
|
3
|
|
|
|
|
18
|
|
|
148
|
74
|
|
|
5
|
|
568
|
$app->vfilter(range => sub { num_range $_[1], $_[2][0], $_[2][1] } ); |
|
|
5
|
|
|
|
|
22
|
|
|
149
|
|
|
|
|
|
|
|
|
150
|
74
|
|
|
1
|
|
656
|
$app->vfilter('lt' => sub { str_lt $_[1], $_[2] } ); |
|
|
1
|
|
|
|
|
4
|
|
|
151
|
74
|
|
|
1
|
|
580
|
$app->vfilter('gt' => sub { str_gt $_[1], $_[2] } ); |
|
|
1
|
|
|
|
|
4
|
|
|
152
|
74
|
|
|
1
|
|
612
|
$app->vfilter('le' => sub { str_le $_[1], $_[2] } ); |
|
|
1
|
|
|
|
|
4
|
|
|
153
|
74
|
|
|
1
|
|
641
|
$app->vfilter('ge' => sub { str_ge $_[1], $_[2] } ); |
|
|
1
|
|
|
|
|
5
|
|
|
154
|
74
|
|
|
1
|
|
589
|
$app->vfilter('cmp' => sub { str_cmp $_[1], $_[2] } ); |
|
|
1
|
|
|
|
|
4
|
|
|
155
|
74
|
|
|
1
|
|
598
|
$app->vfilter('eq' => sub { str_eq $_[1], $_[2] } ); |
|
|
1
|
|
|
|
|
4
|
|
|
156
|
74
|
|
|
1
|
|
694
|
$app->vfilter('ne' => sub { str_ne $_[1], $_[2] } ); |
|
|
1
|
|
|
|
|
35
|
|
|
157
|
|
|
|
|
|
|
|
|
158
|
74
|
|
|
|
|
307
|
return; |
|
159
|
|
|
|
|
|
|
} |
|
160
|
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
1; |