| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Mojolicious::Plugin::Vparam::Bool; |
|
2
|
72
|
|
|
72
|
|
3963491
|
use Mojo::Base -strict; |
|
|
72
|
|
|
|
|
10620
|
|
|
|
72
|
|
|
|
|
541
|
|
|
3
|
72
|
|
|
72
|
|
7667
|
use Mojolicious::Plugin::Vparam::Common; |
|
|
72
|
|
|
|
|
163
|
|
|
|
72
|
|
|
|
|
46093
|
|
|
4
|
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
sub check_bool($) { |
|
6
|
18
|
100
|
|
18
|
0
|
42
|
return 'Wrong format' unless defined $_[0]; |
|
7
|
17
|
|
|
|
|
46
|
return 0; |
|
8
|
|
|
|
|
|
|
} |
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub parse_bool($) { |
|
11
|
18
|
|
|
18
|
0
|
29
|
my ($str) = @_; |
|
12
|
|
|
|
|
|
|
# HTML forms do not transmit if checkbox off |
|
13
|
18
|
100
|
|
|
|
41
|
return 0 unless defined $str; |
|
14
|
12
|
100
|
|
|
|
31
|
return 0 unless length $str; |
|
15
|
10
|
100
|
|
|
|
45
|
return 0 if $str =~ m{^(?:0|no|false|fail)$}i; |
|
16
|
6
|
100
|
|
|
|
29
|
return 1 if $str =~ m{^(?:1|yes|true|ok)$}i; |
|
17
|
1
|
|
|
|
|
3
|
return undef; |
|
18
|
|
|
|
|
|
|
} |
|
19
|
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub check_logic($) { |
|
21
|
20
|
100
|
|
20
|
0
|
60
|
return 'Value is not defined' unless defined $_[0]; |
|
22
|
14
|
100
|
|
|
|
84
|
return 'Wrong format' unless $_[0] =~ m{^(?:0|1|)$}; |
|
23
|
13
|
|
|
|
|
37
|
return 0; |
|
24
|
|
|
|
|
|
|
} |
|
25
|
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub parse_logic($) { |
|
27
|
20
|
|
|
20
|
0
|
60
|
my ($str) = @_; |
|
28
|
20
|
100
|
|
|
|
49
|
return undef unless defined $str; |
|
29
|
14
|
100
|
|
|
|
54
|
return '' if $str =~ m{^\s*$}; |
|
30
|
12
|
100
|
|
|
|
53
|
return '' if $str =~ m{^(?:nil|null|undef|undefined|nan)$}i; |
|
31
|
10
|
100
|
|
|
|
44
|
return 0 if $str =~ m{^(?:0|no|false|fail)$}i; |
|
32
|
6
|
100
|
|
|
|
41
|
return 1 if $str =~ m{^(?:1|yes|true|ok)$}i; |
|
33
|
1
|
|
|
|
|
8
|
return $str; |
|
34
|
|
|
|
|
|
|
} |
|
35
|
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub register { |
|
37
|
74
|
|
|
74
|
0
|
262
|
my ($class, $self, $app, $conf) = @_; |
|
38
|
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
$app->vtype( |
|
40
|
|
|
|
|
|
|
bool => |
|
41
|
18
|
|
|
18
|
|
51
|
pre => sub { parse_bool trim $_[1] }, |
|
42
|
18
|
|
|
18
|
|
34
|
valid => sub { check_bool $_[1] }, |
|
43
|
74
|
|
|
|
|
886
|
); |
|
44
|
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
$app->vtype( |
|
46
|
|
|
|
|
|
|
logic => |
|
47
|
20
|
|
|
20
|
|
77
|
pre => sub { parse_logic trim $_[1] }, |
|
48
|
20
|
|
|
20
|
|
46
|
valid => sub { check_logic $_[1] }, |
|
49
|
|
|
|
|
|
|
post => sub { |
|
50
|
20
|
100
|
100
|
20
|
|
103
|
defined($_[1]) && $_[1] eq '' |
|
51
|
|
|
|
|
|
|
? undef |
|
52
|
|
|
|
|
|
|
: $_[1] |
|
53
|
|
|
|
|
|
|
; |
|
54
|
|
|
|
|
|
|
}, |
|
55
|
74
|
|
|
|
|
1034
|
); |
|
56
|
|
|
|
|
|
|
|
|
57
|
74
|
|
|
|
|
352
|
return; |
|
58
|
|
|
|
|
|
|
} |
|
59
|
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
1; |