Factory/Control/Role/BooleanValue.pm

filter: Statementstmt 83.7% 31 / 37 Branchbran 66.6% 12 / 18 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 85.7% 6 / 7 Podpod 100% 2 / 2 totaltotal 79.6% 51 / 64 CC 10 SCAR 13.7
CC
10
Cov
78%
is_currently_true
6.6
__ANON__
4.0
_is_it_true
3.0
CRAP 4.0
« Factory/Result.pm ↑ Summary Factory/Control/SelectMany.pm »
1 package Form::Factory::Control::Role::BooleanValue;
2 1 $Form::Factory::Control::Role::BooleanValue::VERSION = '0.022';
3 1 ▶use Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 1 excludes qw(
6 Form::Factory::Control::Role::ListValue
7 Form::Factory::Control::Role::ScalarValue
8 );
9  
10 # ABSTRACT: boolean valued controls
11  
12  
13 1 has true_value => (
14 is => 'ro',
15 required => 1,
16 default => 1,
17 );
18  
19  
20 1 has false_value => (
21 is => 'ro',
22 required => 1,
23 default => '',
24 );
25  
26  
27 6 ▶sub _is_it_true {
Subroutine _is_it_true: called CC=3 SCAR=11.0
28 6 my ($self, $value) = @_;
29  
30 # blow off these warnings rather than test for them
31 1 ▶ no warnings 'uninitialized';
Subroutine BEGIN: called CC=1 SCAR=0.0
32  
33 6 ▶ return 1 if $value eq $self->true_value;
Branch: 1 branch
BranchTrueFalseTotal
if $value eq $self->true_value 4 2 6
34 2 ▶ return '' if $value eq $self->false_value;
Branch: 1 branch
BranchTrueFalseTotal
if $value eq $self->false_value 0 2 2
35 2 return scalar undef;
36 }
37  
38 12 ▶sub is_currently_true {
Subroutine is_currently_true: called CC=5 SCAR=18.9
Pod documented
39 12 my $self = shift;
40  
41 12 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 12 12
42 0 my $is_true = shift;
43 0 ▶ $self->current_value($is_true ? $self->true_value : $self->false_value);
Branch: 1 branch
BranchTrueFalseTotal
$is_true ? : 0 0 0
44 }
45  
46 12 ▶ return $self->_is_it_true($self->value) if $self->has_value;
Branch: 1 branch
BranchTrueFalseTotal
if $self->has_value 5 7 12
47 7 ▶ return $self->_is_it_true($self->default_value) if $self->has_default_value;
Branch: 1 branch
BranchTrueFalseTotal
if $self->has_default_value 0 7 7
48 7 return scalar undef;
49 }
50  
51  
52 1 ▶sub is_true {
Subroutine is_true: called CC=1 SCAR=0.0
Pod documented
53 1 my $self = shift;
54 1 return $self->_is_it_true($self->value);
55 }
56  
57  
58 12 ▶around current_value => sub {
Subroutine __ANON__: called CC=4 SCAR=14.0
59 12 my $next = shift;
60 12 my $self = shift;
61 12 my $truth = $self->is_currently_true;
62  
63 12 ▶ $self->value(@_) if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 5 7 12
64  
65 12 ▶ if ($truth) {
Branch: 2 branches
BranchTrueFalseTotal
if ($truth) { } 4 8 12
elsif (defined $truth) { } 0 8 8
66 4 return $self->true_value;
67 }
68 elsif (defined $truth) {
69 0 return $self->false_value;
70 }
71 else {
72 8 return scalar undef;
73 }
74 1 };
75  
76  
77 0 ▶around has_current_value => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
78 0 my $next = shift;
79 0 my $self = shift;
80 0 return defined $self->is_currently_true;
81 1 };
82  
83 1 1;
84  
85 __END__
« Factory/Result.pm ↑ Summary Factory/Control/SelectMany.pm »