| 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
| |||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||
| 30 | 0 | $self->{_data} = $data; | |||||||||||||||||||||||||||||||||
| 31 | } | ||||||||||||||||||||||||||||||||||
| 32 | ▶ | elsif (-e $data && -f _ && -r _) { | |||||||||||||||||||||||||||||||||
|
Condition0%0/6
-e $data and -f _ and -r _
-e $data and -f _
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 _
| |||||||||||||||||||||||||||||||||||
| 33 | 0 | eval { | |||||||||||||||||||||||||||||||||
| 34 | 0 | $self->{_data} = YAML::LoadFile($data); | |||||||||||||||||||||||||||||||||
| 35 | }; | ||||||||||||||||||||||||||||||||||
| 36 | 0 | ▶ | if ($@) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 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
Condition0%0/3
$self->decode_from and not &Encode::is_utf8($msg)
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)
| |||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||
| 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
Condition0%0/3
$action and exists $data->{$action}
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}
| |||||||||||||||||||||||||||||||||||
| 68 | 0 | ▶ | if ( exists $data->{DEFAULT} ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 69 | 0 | ▶ | if ( exists $data->{DEFAULT}{$name} ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 70 | 0 | my $conf = $data->{DEFAULT}{$name}; | |||||||||||||||||||||||||||||||||
| 71 | 0 | ▶ | if ( exists $conf->{$type} ) { | ||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||
| 87 | 0 | my $conf = $data->{$action}{$name}; | |||||||||||||||||||||||||||||||||
| 88 | 0 | ▶ | if ( exists $conf->{$type} ) { | ||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||
| 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}
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}
| |||||||||||||||||||||||||||||||||||
| 95 | && exists $data->{DEFAULT}{$name} ) { | ||||||||||||||||||||||||||||||||||
| 96 | 0 | my $conf = $data->{DEFAULT}{$name}; | |||||||||||||||||||||||||||||||||
| 97 | 0 | ▶ | if ( exists $conf->{$type} ) { | ||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||
| 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}
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}
| |||||||||||||||||||||||||||||||||||
| 106 | && exists $data->{DEFAULT}{$name} ) { | ||||||||||||||||||||||||||||||||||
| 107 | 0 | my $conf = $data->{DEFAULT}{$name}; | |||||||||||||||||||||||||||||||||
| 108 | 0 | ▶ | if ( exists $conf->{$type} ) { | ||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||
| 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__ | ||||||||||||||||||||||||||||||||||