line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
4
|
|
|
4
|
|
49366
|
use strict; use warnings; |
|
4
|
|
|
4
|
|
6
|
|
|
4
|
|
|
|
|
118
|
|
|
4
|
|
|
|
|
15
|
|
|
4
|
|
|
|
|
6
|
|
|
4
|
|
|
|
|
371
|
|
2
|
|
|
|
|
|
|
package boolean; |
3
|
|
|
|
|
|
|
our $VERSION = '0.44'; |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
my ($true, $false); |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
use overload |
8
|
59467
|
|
|
59467
|
|
61508
|
'""' => sub { ${$_[0]} }, |
|
59467
|
|
|
|
|
171612
|
|
9
|
465
|
100
|
|
465
|
|
406
|
'!' => sub { ${$_[0]} ? $false : $true }, |
|
465
|
|
|
|
|
801
|
|
10
|
4
|
|
|
4
|
|
3030
|
fallback => 1; |
|
4
|
|
|
|
|
2920
|
|
|
4
|
|
|
|
|
37
|
|
11
|
|
|
|
|
|
|
|
12
|
4
|
|
|
4
|
|
257
|
use base 'Exporter'; |
|
4
|
|
|
|
|
6
|
|
|
4
|
|
|
|
|
1064
|
|
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
|
|
70
|
my @options = grep $_ ne '-truth', @_; |
22
|
7
|
100
|
|
|
|
24
|
$_[0]->truth if @options != @_; |
23
|
7
|
|
|
|
|
10
|
@_ = @options; |
24
|
7
|
|
|
|
|
3756
|
goto &Exporter::import; |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
my ($true_val, $false_val, $bool_vals); |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
BEGIN { |
30
|
4
|
|
|
4
|
|
9
|
my $t = 1; |
31
|
4
|
|
|
|
|
4
|
my $f = 0; |
32
|
4
|
|
|
|
|
5
|
$true = do {bless \$t, 'boolean'}; |
|
4
|
|
|
|
|
10
|
|
33
|
4
|
|
|
|
|
4
|
$false = do {bless \$f, 'boolean'}; |
|
4
|
|
|
|
|
11
|
|
34
|
|
|
|
|
|
|
|
35
|
4
|
|
|
|
|
11
|
$true_val = overload::StrVal($true); |
36
|
4
|
|
|
|
|
24
|
$false_val = overload::StrVal($false); |
37
|
4
|
|
|
|
|
1258
|
$bool_vals = {$true_val => 1, $false_val => 1}; |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
52
|
|
|
52
|
1
|
239
|
sub true() { $true } |
41
|
42
|
|
|
42
|
1
|
4566
|
sub false() { $false } |
42
|
|
|
|
|
|
|
sub boolean($) { |
43
|
14
|
100
|
|
14
|
1
|
2013
|
die "Not enough arguments for boolean::boolean" if scalar(@_) == 0; |
44
|
13
|
100
|
|
|
|
36
|
die "Too many arguments for boolean::boolean" if scalar(@_) > 1; |
45
|
12
|
100
|
|
|
|
47
|
return not(defined $_[0]) ? false : |
|
|
100
|
|
|
|
|
|
46
|
|
|
|
|
|
|
"$_[0]" ? $true : $false; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
sub isTrue($) { |
49
|
6
|
100
|
|
6
|
1
|
23
|
not(defined $_[0]) ? false : |
|
|
50
|
|
|
|
|
|
50
|
|
|
|
|
|
|
(overload::StrVal($_[0]) eq $true_val) ? true : false; |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
sub isFalse($) { |
53
|
9
|
100
|
|
9
|
1
|
32
|
not(defined $_[0]) ? false : |
|
|
100
|
|
|
|
|
|
54
|
|
|
|
|
|
|
(overload::StrVal($_[0]) eq $false_val) ? true : false; |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
sub isBoolean($) { |
57
|
14
|
100
|
|
14
|
1
|
46
|
not(defined $_[0]) ? false : |
|
|
100
|
|
|
|
|
|
58
|
|
|
|
|
|
|
(exists $bool_vals->{overload::StrVal($_[0])}) ? true : false; |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
sub truth { |
62
|
1
|
50
|
|
1
|
0
|
3
|
die "-truth not supported on Perl 5.22 or later" if $] >= 5.021005; |
63
|
|
|
|
|
|
|
# enable modifying true and false |
64
|
1
|
|
|
|
|
4
|
&Internals::SvREADONLY( \ !!0, 0); |
65
|
1
|
|
|
|
|
2
|
&Internals::SvREADONLY( \ !!1, 0); |
66
|
|
|
|
|
|
|
# turn perl internal booleans into blessed booleans: |
67
|
1
|
|
|
|
|
1
|
${ \ !!0 } = $false; |
|
1
|
|
|
|
|
1
|
|
68
|
1
|
|
|
|
|
1
|
${ \ !!1 } = $true; |
|
1
|
|
|
|
|
1
|
|
69
|
|
|
|
|
|
|
# make true and false read-only again |
70
|
1
|
|
|
|
|
2
|
&Internals::SvREADONLY( \ !!0, 1); |
71
|
1
|
|
|
|
|
2
|
&Internals::SvREADONLY( \ !!1, 1); |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
3
|
100
|
|
3
|
0
|
3
|
sub TO_JSON { ${$_[0]} ? \1 : \0 } |
|
3
|
|
|
|
|
64
|
|
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
1; |