File Coverage

blib/lib/Getopt/Yath/Option/Bool.pm
Criterion Covered Total %
statement 29 34 85.2
branch 5 12 41.6
condition n/a
subroutine 16 17 94.1
pod 0 13 0.0
total 50 76 65.7


line stmt bran cond sub pod time code
1             package Getopt::Yath::Option::Bool;
2 1     1   6 use strict;
  1         1  
  1         31  
3 1     1   3 use warnings;
  1         2  
  1         66  
4              
5             our $VERSION = '2.000007';
6              
7 1     1   19 use parent 'Getopt::Yath::Option';
  1         1  
  1         7  
8 1     1   86 use Getopt::Yath::HashBase;
  1         1  
  1         6  
9              
10 3     3 0 12 sub allows_shortval { 0 }
11 1     1 0 17 sub allows_default { 1 }
12 9     9 0 57 sub allows_arg { 0 }
13 6     6 0 16 sub requires_arg { 0 }
14 6     6 0 9 sub allows_autofill { 0 }
15 4     4 0 10 sub requires_autofill { 0 }
16              
17 6     6 0 14 sub no_arg_value { 1 } # --bool
18              
19             # undef is not populated, otherwise qw have 1 or 0
20 162 100   162 0 181 sub is_populated { defined(${$_[1]}) ? 1 : 0 }
  162         421  
21              
22 337     337 0 386 sub add_value { ${$_[1]} = $_[2] }
  337         654  
23 3     3 0 4 sub clear_field { ${$_[1]} = 0 } # --no-bool
  3         6  
24              
25             # Default to 0 unless otherwise specified
26             sub get_default_value {
27 156     156 0 186 my $self = shift;
28 156 50       245 return undef if $self->{+MAYBE};
29 156 100       261 return $self->SUPER::get_default_value(@_) ? 1 : 0;
30             }
31              
32 165     165 0 264 sub can_set_env { 1 }
33              
34             sub get_env_value {
35 0     0 0   my $opt = shift;
36 0           my ($var, $ref) = @_;
37              
38 0 0         my $b = $$ref ? 1 : 0;
39 0 0         return $b unless $var =~ m/^!/;
40 0 0         return $b ? 0 : 1;
41             }
42              
43             1;
44              
45             __END__