Enbld/Target/Attribute.pm

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