line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mojolicious::Plugin::Vparam::Bool; |
2
|
72
|
|
|
72
|
|
3475776
|
use Mojo::Base -strict; |
|
72
|
|
|
|
|
7776
|
|
|
72
|
|
|
|
|
460
|
|
3
|
72
|
|
|
72
|
|
6786
|
use Mojolicious::Plugin::Vparam::Common; |
|
72
|
|
|
|
|
145
|
|
|
72
|
|
|
|
|
39047
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
sub check_bool($) { |
6
|
18
|
100
|
|
18
|
0
|
43
|
return 'Wrong format' unless defined $_[0]; |
7
|
17
|
|
|
|
|
47
|
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
|
|
|
|
43
|
return 0 unless defined $str; |
14
|
12
|
100
|
|
|
|
32
|
return 0 unless length $str; |
15
|
10
|
100
|
|
|
|
46
|
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
|
|
|
|
|
4
|
return undef; |
18
|
|
|
|
|
|
|
} |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub check_logic($) { |
21
|
20
|
100
|
|
20
|
0
|
59
|
return 'Value is not defined' unless defined $_[0]; |
22
|
14
|
100
|
|
|
|
63
|
return 'Wrong format' unless $_[0] =~ m{^(?:0|1|)$}; |
23
|
13
|
|
|
|
|
40
|
return 0; |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub parse_logic($) { |
27
|
20
|
|
|
20
|
0
|
43
|
my ($str) = @_; |
28
|
20
|
100
|
|
|
|
47
|
return undef unless defined $str; |
29
|
14
|
100
|
|
|
|
53
|
return '' if $str =~ m{^\s*$}; |
30
|
12
|
100
|
|
|
|
55
|
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
|
|
|
|
32
|
return 1 if $str =~ m{^(?:1|yes|true|ok)$}i; |
33
|
1
|
|
|
|
|
6
|
return $str; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub register { |
37
|
74
|
|
|
74
|
0
|
213
|
my ($class, $self, $app, $conf) = @_; |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
$app->vtype( |
40
|
|
|
|
|
|
|
bool => |
41
|
18
|
|
|
18
|
|
47
|
pre => sub { parse_bool trim $_[1] }, |
42
|
18
|
|
|
18
|
|
35
|
valid => sub { check_bool $_[1] }, |
43
|
74
|
|
|
|
|
662
|
); |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
$app->vtype( |
46
|
|
|
|
|
|
|
logic => |
47
|
20
|
|
|
20
|
|
63
|
pre => sub { parse_logic trim $_[1] }, |
48
|
20
|
|
|
20
|
|
44
|
valid => sub { check_logic $_[1] }, |
49
|
|
|
|
|
|
|
post => sub { |
50
|
20
|
100
|
100
|
20
|
|
98
|
defined($_[1]) && $_[1] eq '' |
51
|
|
|
|
|
|
|
? undef |
52
|
|
|
|
|
|
|
: $_[1] |
53
|
|
|
|
|
|
|
; |
54
|
|
|
|
|
|
|
}, |
55
|
74
|
|
|
|
|
875
|
); |
56
|
|
|
|
|
|
|
|
57
|
74
|
|
|
|
|
285
|
return; |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
1; |