Simple/Messages.pm

filter: Statementstmt 31.2% 20 / 64 Branchbran 0.0% 0 / 40 Conditioncond 0.0% 0 / 18 MC/DCmcdc 0.0% 0 / 11 Subroutinesub 60.0% 6 / 10 Podpod 50.0% 2 / 4 totaltotal 19.0% 28 / 147 CC 27 SCAR 53.4
CC
27
Cov
16%
_get
380.0
load
42.0
get
12.0
CRAP 209.1
↑ Summary Simple/Validator.pm »
1 package FormValidator::Simple::Messages;
2 8 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 8 ▶use base 'Class::Accessor::Fast';
Subroutine BEGIN: called CC=1 SCAR=0.0
4 8 ▶use YAML;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 8 ▶use FormValidator::Simple::Exception;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 8 __PACKAGE__->mk_accessors(qw/decode_from/);
8 8 ▶use Encode;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 8 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod documented
11 8 my $class = shift;
12 8 my $self = bless {
13 _data => undef,
14 _format => "%s",
15 }, $class;
16 8 return $self;
17 }
18  
19 0 ▶sub format {
Subroutine format: not called CC=2 SCAR=17.9
Pod undocumented
20 0 my ($self, $format) = @_;
21 0 ▶ if ($format) {
Branch: 1 branch
BranchTrueFalseTotal
if ($format) 0 0 0
22 0 $self->{_format} = $format;
23 }
24 0 $self->{_format};
25 }
26  
27 0 ▶sub load {
Subroutine load: not called CC=6 SCAR=37.4
Pod undocumented
28 0 my ($self, $data) = @_;
29 0 ▶ if (ref $data eq 'HASH') {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $data eq 'HASH') { } 0 0 0
elsif (-e $data and -f _ and -r _) { } 0 0 0
30 0 $self->{_data} = $data;
31 }
32 ▶ elsif (-e $data && -f _ && -r _) {
Condition0%0/6
-e $data and -f _ and -r _
!ll&&!rl&&r
000
-e $data and -f _
!ll&&!rl&&r
000
MC/DC0%0/3
-e $data and -f _ and -r _
-e $data -f _ -r _
Truth table0%0/4
A and B and C
A= -e $dataB= -f _C= -r _
ABCresult
0XX0
10X0
1100
1111
33 0 eval {
34 0 $self->{_data} = YAML::LoadFile($data);
35 };
36 0 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
37 0 FormValidator::Simple::Exception->throw(
38 qq/failed to load YAML file. "$@"/
39 );
40 }
41 }
42 else {
43 0 FormValidator::Simple::Exception->throw(
44 qq/set hash reference or YAML file path./
45 );
46 }
47 }
48  
49 0 ▶sub get {
Subroutine get: not called CC=3 SCAR=24.8
Pod documented
50 0 my $self = shift;
51 0 my $msg = $self->_get(@_);
52 0 ▶ if ($self->decode_from && !Encode::is_utf8($msg)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->decode_from and not &Encode::is_utf8($msg)) 0 0 0
Condition0%0/3
$self->decode_from and not &Encode::is_utf8($msg)
!ll&&!rl&&r
000
MC/DC0%0/2
$self->decode_from and not &Encode::is_utf8($msg)
$self->decode_from not &Encode::is_utf8($msg)
Truth table0%0/3
A and not(B)
A= $self->decode_fromB= not &Encode::is_utf8($msg)
ABresult
0X0
100
111
53 0 $msg = Encode::decode($self->decode_from, $msg);
54 }
55 0 return sprintf $self->format, $msg;
56 }
57  
58 0 ▶sub _get {
Subroutine _get: not called CC=19 SCAR=59.4
59 0 my ($self, $action, $name, $type) = @_;
60 0 my $data = $self->{_data};
61 0 ▶ unless ($data) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($data) 0 0 0
62 0 FormValidator::Simple::Exception->throw(
63 qq/set messages before calling get()./
64 );
65 }
66  
67 0 ▶ unless ( $action && exists $data->{$action} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($action and exists $data->{$action}) 0 0 0
Condition0%0/3
$action and exists $data->{$action}
!ll&&!rl&&r
000
MC/DC0%0/2
$action and exists $data->{$action}
$action exists $data->{$action}
Truth table0%0/3
A and B
A= $actionB= exists $data->{$action}
ABresult
0X0
100
111
68 0 ▶ if ( exists $data->{DEFAULT} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $data->{'DEFAULT'}) { } 0 0 0
69 0 ▶ if ( exists $data->{DEFAULT}{$name} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $data->{'DEFAULT'}{$name}) { } 0 0 0
70 0 my $conf = $data->{DEFAULT}{$name};
71 0 ▶ if ( exists $conf->{$type} ) {
Branch: 2 branches
BranchTrueFalseTotal
if (exists $conf->{$type}) { } 0 0 0
elsif (exists $conf->{'DEFAULT'}) { } 0 0 0
72 0 return $conf->{$type};
73 }
74 elsif ( exists $conf->{DEFAULT} ) {
75 0 return $conf->{DEFAULT};
76 }
77 }
78 else {
79 0 return "$name is invalid.";
80 }
81 }
82 else {
83 0 return "$name is invalid.";
84 }
85 }
86 0 ▶ if ( exists $data->{$action}{$name} ) {
Branch: 2 branches
BranchTrueFalseTotal
if (exists $data->{$action}{$name}) { } 0 0 0
elsif (exists $data->{'DEFAULT'} and exists $data->{'DEFAULT'}{$name}) { } 0 0 0
87 0 my $conf = $data->{$action}{$name};
88 0 ▶ if ( exists $conf->{$type} ) {
Branch: 3 branches
BranchTrueFalseTotal
if (exists $conf->{$type}) { } 0 0 0
elsif (exists $conf->{'DEFAULT'}) { } 0 0 0
elsif (exists $data->{'DEFAULT'} and exists $data->{'DEFAULT'}{$name}) { } 0 0 0
89 0 return $conf->{$type};
90 }
91 elsif ( exists $conf->{DEFAULT} ) {
92 0 return $conf->{DEFAULT};
93 }
94 ▶ elsif ( exists $data->{DEFAULT}
Condition0%0/3
exists $data->{"DEFAULT"} and exists $data->{"DEFAULT"}{$name}
!ll&&!rl&&r
000
MC/DC0%0/2
exists $data->{"DEFAULT"} and exists $data->{"DEFAULT"}{$name}
exists $data->{"DEFAULT"} exists $data->{"DEFAULT"}{$name}
Truth table0%0/3
A and B
A= exists $data->{"DEFAULT"}B= exists $data->{"DEFAULT"}{$name}
ABresult
0X0
100
111
95 && exists $data->{DEFAULT}{$name} ) {
96 0 my $conf = $data->{DEFAULT}{$name};
97 0 ▶ if ( exists $conf->{$type} ) {
Branch: 2 branches
BranchTrueFalseTotal
if (exists $conf->{$type}) { } 0 0 0
elsif (exists $conf->{'DEFAULT'}) { } 0 0 0
98 0 return $conf->{$type};
99 }
100 elsif ( exists $conf->{DEFAULT} ) {
101 0 return $conf->{DEFAULT};
102 }
103 }
104 }
105 ▶ elsif ( exists $data->{DEFAULT}
Condition0%0/3
exists $data->{"DEFAULT"} and exists $data->{"DEFAULT"}{$name}
!ll&&!rl&&r
000
MC/DC0%0/2
exists $data->{"DEFAULT"} and exists $data->{"DEFAULT"}{$name}
exists $data->{"DEFAULT"} exists $data->{"DEFAULT"}{$name}
Truth table0%0/3
A and B
A= exists $data->{"DEFAULT"}B= exists $data->{"DEFAULT"}{$name}
ABresult
0X0
100
111
106 && exists $data->{DEFAULT}{$name} ) {
107 0 my $conf = $data->{DEFAULT}{$name};
108 0 ▶ if ( exists $conf->{$type} ) {
Branch: 2 branches
BranchTrueFalseTotal
if (exists $conf->{$type}) { } 0 0 0
elsif (exists $conf->{'DEFAULT'}) { } 0 0 0
109 0 return $conf->{$type};
110 }
111 elsif ( exists $conf->{DEFAULT} ) {
112 0 return $conf->{DEFAULT};
113 }
114 }
115 0 return "$name is invalid.";
116 }
117  
118 8 1;
119 __END__
↑ Summary Simple/Validator.pm »