line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
4
|
|
|
4
|
|
39971
|
use strict; use warnings; |
|
4
|
|
|
4
|
|
6
|
|
|
4
|
|
|
|
|
84
|
|
|
4
|
|
|
|
|
11
|
|
|
4
|
|
|
|
|
4
|
|
|
4
|
|
|
|
|
331
|
|
2
|
|
|
|
|
|
|
package boolean; |
3
|
|
|
|
|
|
|
our $VERSION = '0.46'; |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
my ($true, $false); |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
use overload |
8
|
111
|
|
|
111
|
|
8446
|
'""' => sub { ${$_[0]} }, |
|
111
|
|
|
|
|
251
|
|
9
|
16
|
100
|
|
16
|
|
13
|
'!' => sub { ${$_[0]} ? $false : $true }, |
|
16
|
|
|
|
|
50
|
|
10
|
4
|
|
|
4
|
|
2579
|
fallback => 1; |
|
4
|
|
|
|
|
2123
|
|
|
4
|
|
|
|
|
29
|
|
11
|
|
|
|
|
|
|
|
12
|
4
|
|
|
4
|
|
210
|
use base 'Exporter'; |
|
4
|
|
|
|
|
4
|
|
|
4
|
|
|
|
|
826
|
|
13
|
|
|
|
|
|
|
@boolean::EXPORT = qw(true false boolean); |
14
|
|
|
|
|
|
|
@boolean::EXPORT_OK = qw(isTrue isFalse isBoolean); |
15
|
|
|
|
|
|
|
%boolean::EXPORT_TAGS = ( |
16
|
|
|
|
|
|
|
all => [@boolean::EXPORT, @boolean::EXPORT_OK], |
17
|
|
|
|
|
|
|
test => [qw(isTrue isFalse isBoolean)], |
18
|
|
|
|
|
|
|
); |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub import { |
21
|
7
|
|
|
7
|
|
58
|
my @options = grep $_ ne '-truth', @_; |
22
|
7
|
50
|
|
|
|
19
|
$_[0]->truth if @options != @_; |
23
|
7
|
|
|
|
|
11
|
@_ = @options; |
24
|
7
|
|
|
|
|
4054
|
goto &Exporter::import; |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
my ($true_val, $false_val, $bool_vals); |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
BEGIN { |
30
|
4
|
|
|
4
|
|
5
|
my $t = 1; |
31
|
4
|
|
|
|
|
10
|
my $f = 0; |
32
|
4
|
|
|
|
|
8
|
$true = do {bless \$t, 'boolean'}; |
|
4
|
|
|
|
|
6
|
|
33
|
4
|
|
|
|
|
4
|
$false = do {bless \$f, 'boolean'}; |
|
4
|
|
|
|
|
5
|
|
34
|
|
|
|
|
|
|
|
35
|
4
|
|
|
|
|
13
|
$true_val = overload::StrVal($true); |
36
|
4
|
|
|
|
|
17
|
$false_val = overload::StrVal($false); |
37
|
4
|
|
|
|
|
1166
|
$bool_vals = {$true_val => 1, $false_val => 1}; |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
# refaddrs change on thread spawn, so CLONE fixes them up |
41
|
|
|
|
|
|
|
sub CLONE { |
42
|
0
|
|
|
0
|
|
0
|
$true_val = overload::StrVal($true); |
43
|
0
|
|
|
|
|
0
|
$false_val = overload::StrVal($false); |
44
|
0
|
|
|
|
|
0
|
$bool_vals = {$true_val => 1, $false_val => 1}; |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
52
|
|
|
52
|
1
|
186
|
sub true() { $true } |
48
|
42
|
|
|
42
|
1
|
4297
|
sub false() { $false } |
49
|
|
|
|
|
|
|
sub boolean($) { |
50
|
14
|
100
|
|
14
|
1
|
1081
|
die "Not enough arguments for boolean::boolean" if scalar(@_) == 0; |
51
|
13
|
100
|
|
|
|
32
|
die "Too many arguments for boolean::boolean" if scalar(@_) > 1; |
52
|
12
|
100
|
|
|
|
40
|
return not(defined $_[0]) ? false : |
|
|
100
|
|
|
|
|
|
53
|
|
|
|
|
|
|
"$_[0]" ? $true : $false; |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
sub isTrue($) { |
56
|
6
|
100
|
|
6
|
1
|
21
|
not(defined $_[0]) ? false : |
|
|
50
|
|
|
|
|
|
57
|
|
|
|
|
|
|
(overload::StrVal($_[0]) eq $true_val) ? true : false; |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
sub isFalse($) { |
60
|
9
|
100
|
|
9
|
1
|
26
|
not(defined $_[0]) ? false : |
|
|
100
|
|
|
|
|
|
61
|
|
|
|
|
|
|
(overload::StrVal($_[0]) eq $false_val) ? true : false; |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
sub isBoolean($) { |
64
|
|
|
|
|
|
|
not(defined $_[0]) ? false : |
65
|
14
|
100
|
|
14
|
1
|
42
|
(exists $bool_vals->{overload::StrVal($_[0])}) ? true : false; |
|
|
100
|
|
|
|
|
|
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
sub truth { |
69
|
0
|
0
|
|
0
|
0
|
0
|
die "-truth not supported on Perl 5.22 or later" if $] >= 5.021005; |
70
|
|
|
|
|
|
|
# enable modifying true and false |
71
|
0
|
|
|
|
|
0
|
&Internals::SvREADONLY( \ !!0, 0); |
72
|
0
|
|
|
|
|
0
|
&Internals::SvREADONLY( \ !!1, 0); |
73
|
|
|
|
|
|
|
# turn perl internal booleans into blessed booleans: |
74
|
0
|
|
|
|
|
0
|
${ \ !!0 } = $false; |
|
0
|
|
|
|
|
0
|
|
75
|
0
|
|
|
|
|
0
|
${ \ !!1 } = $true; |
|
0
|
|
|
|
|
0
|
|
76
|
|
|
|
|
|
|
# make true and false read-only again |
77
|
0
|
|
|
|
|
0
|
&Internals::SvREADONLY( \ !!0, 1); |
78
|
0
|
|
|
|
|
0
|
&Internals::SvREADONLY( \ !!1, 1); |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
|
81
|
3
|
100
|
|
3
|
0
|
3
|
sub TO_JSON { ${$_[0]} ? \1 : \0 } |
|
3
|
|
|
|
|
40
|
|
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
1; |