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