Enbld/Target/Attribute.pm

filter: Statementstmt 100% 50 / 50 Branchbran 100% 14 / 14 Conditioncond 100% 3 / 3 MC/DCmcdc 100% 2 / 2 Subroutinesub 100% 10 / 10 Podpod 0.0% 0 / 7 totaltotal 91.8% 79 / 86 CC 9 SCAR 8.0
CC
9
Cov
100%
new
3.0
validate
3.0
to_value
3.0
CRAP 2.2
« Enbld/Target/Attribute/Dependencies.pm ↑ Summary Enbld/Target/Attribute/CommandTest.pm »
1 package Enbld::Target::Attribute;
2  
3 19 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 19 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 19 ▶use Module::Load::Conditional qw/can_load/;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 19 require Enbld::Exception;
9  
10 1404 ▶sub new {
Subroutine new: called CC=3 SCAR=11.0
Pod undocumented
11 1404 my ( $class, $name, $param ) = @_;
12  
13 1404 ▶ if ( ! $name ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($name) 1 1403 1404
14 1 Enbld::Exception->throw( "'$class' requires name" );
15 }
16  
17 1403 my $module = "Enbld::Target::Attribute::$name";
18  
19 1403 ▶ can_load( modules => { $module => 0 } ) or
Branch: 1 branch
BranchTrueFalseTotal
can_load("modules", {$module, 0}) or "Enbld::Exception"->throw("Attribute '${name}' is invalid name") 1402 1 1403
20 Enbld::Exception->throw( "Attribute '$name' is invalid name" );
21  
22 1402 my $self = {
23 attributes => undef,
24 value => undef,
25 callback => undef,
26 is_evaluated => undef,
27 };
28  
29 1402 bless $self, $module;
30  
31 1402 $self->initialize( $param );
32  
33 1384 return $self;
34 }
35  
36 714 ▶sub initialize {
Subroutine initialize: called CC=2 SCAR=6.9
Pod undocumented
37 714 my ( $self, $param ) = @_;
38  
39 714 ▶ if ( ref( $param ) eq 'CODE' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $param eq "CODE") 44 670 714
40 44 $self->{callback} = $param;
41 44 return $self;
42 }
43  
44 670 $self->{value} = $param;
45 670 $self->{is_evaluated}++;
46 670 return $self;
47 }
48  
49 1135 ▶sub validate {
Subroutine validate: called CC=3 SCAR=11.0
Pod undocumented
50 1135 my ( $self, $string ) = @_;
51  
52 1135 ▶ if ( ! $string ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($string) 13 1122 1135
53 13 my $type = ref( $self );
54 13 $type =~ s/.*:://;
55 13 Enbld::Exception->throw( "Attribute '$type' is empty string" );
56 }
57  
58 1122 ▶ if ( ref( $string ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $string) 15 1107 1122
59 15 my $type = ref( $self );
60 15 $type =~ s/.*:://;
61 15 Enbld::Exception->throw( "Attribute '$type' isn't scalar value" );
62 }
63  
64 1107 return $string;
65 }
66  
67 1509 ▶sub evaluate {
Subroutine evaluate: called CC=2 SCAR=6.9
Pod undocumented
68 1509 my $self = shift;
69  
70 1509 ▶ return $self->{value} if $self->{is_evaluated};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"is_evaluated"} 1193 316 1509
71
72 316 $self->{value} = $self->{callback}->( $self->{attributes} );
73 315 $self->{is_evaluated}++;
74  
75 315 return $self->{value};
76 }
77  
78 1306 ▶sub to_value {
Subroutine to_value: called CC=3 SCAR=11.0
Pod undocumented
79 1306 my $self = shift;
80  
81 1306 my $value = $self->evaluate;
82  
83 1305 ▶ return '' if ( ( ! $value ) && $self->is_omitable );
Branch: 1 branch
BranchTrueFalseTotal
if not $value and $self->is_omitable 123 1182 1305
Condition100%3/3
not $value and $self->is_omitable
!ll&&!rl&&r
116913123
MC/DC100%2/2
not $value and $self->is_omitable
not $value $self->is_omitable
Truth table100%3/3
not(A) and B
A= not $valueB= $self->is_omitable
ABresult
0X0
100
111
84  
85 1182 $self->validate( $value );
86  
87 1133 return $value;
88 }
89  
90 13 ▶sub is_omitable {
Subroutine is_omitable: called CC=1 SCAR=0.0
Pod undocumented
91 13 return; # if attribute is not omitable, override this method in sub class.
92 }
93  
94 1384 ▶sub link_to_collector {
Subroutine link_to_collector: called CC=1 SCAR=0.0
Pod undocumented
95 1384 my ( $self, $collector ) = @_;
96  
97 1384 $self->{attributes} = $collector;
98 }
99  
100 19 1;
« Enbld/Target/Attribute/Dependencies.pm ↑ Summary Enbld/Target/Attribute/CommandTest.pm »