Localize/MultiLevel.pm

filter: Statementstmt 70.7% 58 / 82 Branchbran 37.5% 9 / 24 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 86.6% 13 / 15 Podpod 100% 1 / 1 totaltotal 64.5% 82 / 127 CC 18 SCAR 18.8
CC
18
Cov
62%
_rstore
20.0
_rfetch
11.2
__ANON__
6.0
CRAP 6.6
« Localize/Gettext/Parser.pm ↑ Summary Localize.pm »
1 package Data::Localize::MultiLevel;
2 1 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 ▶use Config::Any;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use Data::Localize;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use MooX::Types::MooseLike::Base qw(ArrayRef);
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 if (Data::Localize::DEBUG) {
8 require Data::Localize::Log;
9 Data::Localize::Log->import;
10 }
11 }
12  
13 1 extends 'Data::Localize::Localizer';
14 1 with 'Data::Localize::Trait::WithStorage';
15  
16 has paths => (
17 is => 'ro',
18 isa => ArrayRef,
19 1 ▶ trigger => sub {
Subroutine __ANON__: called CC=3 SCAR=14.2
20 1 my $self = shift;
21 1 ▶ if ($self->initialized) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->initialized) 0 1 1
22 0 $self->load_from_path($_) for @{$_[0]};
23 }
24 },
25 1 );
26  
27 1 ▶after BUILD => sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
28 1 my $self = shift;
29 1 my $paths = $self->paths;
30 1 foreach my $path (@$paths) {
31 1 $self->load_from_path($path);
32 }
33 1 };
34  
35 1 ▶after register => sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
36 1 my ($self, $loc) = @_;
37 1 $loc->add_localizer_map('*', $self);
38 $loc->add_localizer_map( $_, $self )
39 1 for keys %{ $self->lexicon_map }
40 1 };
41  
42 20 ▶around get_lexicon => sub{
Subroutine __ANON__: called CC=2 SCAR=6.9
43 20 my ($next, $self, $lang, $key) = @_;
44  
45 20 my ($storage_key, @key_path) = split /\./, $key;
46 20 my $lexicon = $self->$next($lang, $storage_key);
47  
48 20 ▶ return _rfetch( $lexicon, 0, \@key_path )
Branch: 1 branch
BranchTrueFalseTotal
if @key_path 18 2 20
49 if @key_path;
50  
51 2 return $lexicon;
52 1 };
53  
54 0 ▶around set_lexicon => sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
55 0 my ($next, $self, $lang, $key, $value) = @_;
56  
57 0 my ($storage_key, @key_path) = split /\./, $key;
58  
59 0 ▶ if ( @key_path ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@key_path) { } 0 0 0
60 0 my $lexicon = $self->get_lexicon($lang, $storage_key);
61 0 _rstore( $lexicon, 0, \@key_path, $value );
62 0 $self->$next( $storage_key, $lexicon );
63 }
64 else {
65 0 $self->$next( $storage_key, $value );
66 }
67  
68 0 return;
69 1 };
70  
71 1 ▶sub _build_formatter {
Subroutine _build_formatter: called CC=1 SCAR=0.0
72 1 Module::Load::load('Data::Localize::Format::NamedArgs');
73 1 return Data::Localize::Format::NamedArgs->new();
74 }
75  
76 1 ▶sub load_from_path {
Subroutine load_from_path: called CC=3 SCAR=11.0
Pod documented
77 1 my ($self, $path) = @_;
78  
79 1 ▶ my @files = glob( $path );
Subroutine BEGIN: called CC=1 SCAR=0.0
80 1 my $cfg = Config::Any->load_files({ files => \@files, use_ext => 1 });
81  
82 1 foreach my $x (@$cfg) {
83 2 my ($filename, $lexicons) = %$x;
84 # should have one root item
85 2 my ($lang) = keys %$lexicons;
86  
87 2 if (Data::Localize::DEBUG) {
88 debugf("load_from_path - Loaded %s for languages %s",
89 Scalar::Util::blessed($self),
90 $filename,
91 $lang,
92 );
93 }
94  
95 2 $self->merge_lexicon($lang, $lexicons->{$lang});
96 2 ▶ $self->_localizer->add_localizer_map($lang, $self) if $self->_localizer;
Branch: 1 branch
BranchTrueFalseTotal
if $self->_localizer 0 2 2
97 }
98 }
99  
100 18 ▶sub _rfetch {
Subroutine _rfetch: called CC=7 SCAR=24.1
101 18 my ($lexicon, $i, $keys) = @_;
102  
103 18 ▶ return unless $lexicon;
Branch: 1 branch
BranchTrueFalseTotal
unless $lexicon 6 12 18
104  
105 12 my $thing = $lexicon->{$keys->[$i]};
106 12 ▶ return unless defined $thing;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $thing 0 12 12
107  
108 12 my $ref = ref $thing;
109 12 ▶ return unless $ref || length $thing;
Branch: 1 branch
BranchTrueFalseTotal
unless $ref or length $thing 0 12 12
Condition33%1/3
$ref or length $thing
l!l&&r!l&&!r
0120
MC/DC0%0/2
$ref or length $thing
$ref length $thing
Truth table33%1/3
A or B
A= $refB= length $thing
ABresult
1X1
011
000
110  
111 12 ▶ if (@$keys <= $i + 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$keys <= $i + 1) 12 0 12
112 12 return $thing;
113 }
114  
115 0 ▶ if ($ref ne 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if ($ref ne "HASH") 0 0 0
116 0 if (Data::Localize::DEBUG) {
117 debugf("%s does not point to a hash",
118 join('.', map { $keys->[$_] } 0..$i)
119 );
120 }
121 0 return ();
122 }
123  
124 0 return _rfetch( $thing, $i + 1, $keys )
125 }
126  
127 0 ▶sub _rstore {
Subroutine _rstore: not called CC=4 SCAR=30.0
128 0 my ($lexicon, $i, $keys, $value) = @_;
129  
130 0 ▶ return unless $lexicon;
Branch: 1 branch
BranchTrueFalseTotal
unless $lexicon 0 0 0
131  
132 0 ▶ if (@$keys <= $i + 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$keys <= $i + 1) 0 0 0
133 0 $lexicon->{ $keys->[$i] } = $value;
134 0 return;
135 }
136  
137 0 my $thing = $lexicon->{$keys->[$i]};
138  
139 0 ▶ if (ref $thing ne 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $thing ne "HASH") 0 0 0
140 0 if (Data::Localize::DEBUG) {
141 debugf("%s does not point to a hash",
142 join('.', map { $keys->[$_] } 0..$i)
143 );
144 }
145 0 return ();
146 }
147  
148 0 return _rstore( $thing, $i + 1, $keys, $value );
149 }
150  
151 1 1;
152  
153 __END__
« Localize/Gettext/Parser.pm ↑ Summary Localize.pm »