File Coverage

blib/lib/Sidef/Types/Bool/Bool.pm
Criterion Covered Total %
statement 14 34 41.1
branch 0 16 0.0
condition 0 4 0.0
subroutine 5 18 27.7
pod 6 9 66.6
total 25 81 30.8


line stmt bran cond sub pod time code
1             package Sidef::Types::Bool::Bool {
2              
3 1     1   14 use 5.014;
  1         2  
4              
5             use overload
6             q{bool} => \&get_value,
7             q{0+} => \&get_value,
8 1 0   1   787 q{""} => sub { ${$_[0]} ? 'true' : 'false' };
  1     0   705  
  1         7  
  0         0  
  0         0  
9              
10             use constant {
11 1         56 TRUE => (bless \(my $t = 1), __PACKAGE__),
12             FALSE => (bless \(my $f = 0), __PACKAGE__),
13 1     1   92 };
  1         2  
14              
15 1     1   293 use parent qw(Sidef::Object::Object);
  1         217  
  1         5  
16              
17             sub new {
18 0 0   0 1   $_[1] ? (TRUE) : (FALSE);
19             }
20              
21             *call = \&new;
22              
23 0     0 1   sub true { (TRUE) }
24 0     0 1   sub false { (FALSE) }
25              
26             sub pick {
27 0 0   0 1   CORE::rand(1) < 0.5 ? (TRUE) : (FALSE);
28             }
29              
30             *rand = \&pick;
31              
32 0     0 0   sub get_value { ${$_[0]} }
  0            
33 0     0 0   sub to_bool { $_[0] }
34             *to_b = \&to_bool;
35              
36             {
37 1     1   267 no strict 'refs';
  1         4  
  1         407  
38              
39             *{__PACKAGE__ . '::' . '|'} = sub {
40 0     0     my ($self, $arg) = @_;
41 0 0         $$self ? $self : $arg;
42             };
43              
44             *{__PACKAGE__ . '::' . '&'} = sub {
45 0     0     my ($self, $arg) = @_;
46 0 0         $$self ? $arg : $self;
47             };
48              
49             *{__PACKAGE__ . '::' . '^'} = sub {
50 0     0     my ($self, $arg) = @_;
51 0 0 0       ($$self xor $arg) ? (TRUE) : (FALSE);
52             };
53             }
54              
55 0     0 1   sub is_true { $_[0] }
56              
57             sub not {
58 0 0   0 0   ${$_[0]} ? (FALSE) : (TRUE);
  0            
59             }
60              
61             *is_false = \¬
62             *flip = \¬
63             *toggle = \¬
64             *neg = \¬
65              
66             sub dump {
67 0     0 1   my ($self) = @_;
68 0 0         Sidef::Types::String::String->new($$self ? 'true' : 'false');
69             }
70              
71             };
72              
73             1