OO/Lexicon/Hash.pm

filter: Statementstmt 100% 52 / 52 Branchbran 66.6% 12 / 18 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 10 / 10 Podpod 100% 1 / 1 totaltotal 92.5% 75 / 81 CC 11 SCAR 19.1
CC
11
Cov
91%
lexicon_ref
11.4
BEGIN
1.0
BEGIN
1.0
CRAP 6.7
« OO/Plugin/Expand/BabelFish/Loc.pm ↑ Summary OO/Lexicon/Role/File.pm »
1 package Locale::TextDomain::OO::Lexicon::Hash; ## no critic (TidyCode)
2
3 9 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 9 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 9 ▶use Carp qw(confess);
Subroutine BEGIN: called CC=1 SCAR=0.0
6 9 ▶use Locale::TextDomain::OO::Singleton::Lexicon;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 9 ▶use Locale::TextDomain::OO::Util::ExtractHeader;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 9 ▶use Locale::TextDomain::OO::Util::JoinSplitLexiconKeys;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 9 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 9 ▶use MooX::StrictConstructor;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 9 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
12
13 9 our $VERSION = '1.031';
14
15 9 with qw(
16 Locale::TextDomain::OO::Role::Logger
17 );
18
19 9 ▶sub lexicon_ref {
Subroutine lexicon_ref: called CC=11 SCAR=24.3
Pod documented
20 9 my ($self, $hash_lexicon) = @_;
21
22 9 ▶ ref $hash_lexicon eq 'HASH'
Branch: 1 branch
BranchTrueFalseTotal
ref $hash_lexicon eq "HASH" or confess("The given lexicon should be a hash reference") 9 0 9
23 or confess 'The given lexicon should be a hash reference';
24 9 my $instance = Locale::TextDomain::OO::Singleton::Lexicon->instance;
25 9 ▶ $self->logger and $instance->logger( $self->logger );
Branch: 1 branch
BranchTrueFalseTotal
$self->logger and $instance->logger($self->logger) 9 0 9
26 9 my $lexicon = $instance->data;
27 9 my $key_util = Locale::TextDomain::OO::Util::JoinSplitLexiconKeys->instance;
28 9 ▶ while ( my ($lexicon_key, $lexicon_value) = each %{$hash_lexicon} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %{$hash_lexicon;}) 18 8 26
29 18 my $header = $lexicon_value->[0];
30 my $header_msgstr = $header->{msgstr}
31 18 ▶ or confess 'msgstr of header not found';
Branch: 1 branch
BranchTrueFalseTotal
my $header_msgstr = $header->{"msgstr"} or confess("msgstr of header not found") 18 0 18
32 18 $lexicon_value->[0] = Locale::TextDomain::OO::Util::ExtractHeader
33 ->instance
34 ->extract_header_msgstr($header_msgstr);
35 18 my $nplurals = $lexicon_value->[0]->{nplurals};
36 VALUE:
37 18 for my $value ( @{$lexicon_value} ) {
38 # move to lexicon
39 my $msg_key = $key_util->join_message_key({
40 msgctxt => delete $value->{msgctxt},
41 msgid => my $msgid = delete $value->{msgid},
42 msgid_plural => my $msgid_plural = delete $value->{msgid_plural},
43 60 });
44 60 $lexicon->{$lexicon_key}->{$msg_key} = $value;
45 # structure faults
46 exists $value->{msgstr_plural}
47 60 ▶ or next VALUE;
Branch: 1 branch
BranchTrueFalseTotal
exists $value->{"msgstr_plural"} or next VALUE 13 47 60
48 13 my $plural_count = @{ $value->{msgstr_plural} };
49 13 ▶ $plural_count <= $nplurals or confess sprintf
Branch: 3 branches
BranchTrueFalseTotal
$plural_count <= $nplurals or confess(sprintf("Count of msgstr_plural=%s but nplurals=%s for msgid=\"%s\" msgid_plural=\"%s\"", $plural_count, $nplurals, defined $msgid ? $msgid : "", defined $msgid_plural ? $msgid_plural : "")) 12 1 13
defined $msgid ? : 1 0 1
defined $msgid_plural ? : 1 0 1
50 'Count of msgstr_plural=%s but nplurals=%s for msgid="%s" msgid_plural="%s"',
51 $plural_count,
52 $nplurals,
53 ( defined $msgid ? $msgid : q{} ),
54 ( defined $msgid_plural ? $msgid_plural : q{} );
55 }
56 $self->logger
57 17 ▶ and $self->logger->(
Branch: 1 branch
BranchTrueFalseTotal
$self->logger and $self->logger->(qq[Lexicon "$lexicon_key" loaded from hash.], {"object", $self, "type", "debug", "event", "lexicon,load"}) 17 0 17
58 qq{Lexicon "$lexicon_key" loaded from hash.},
59 {
60 object => $self,
61 type => 'debug',
62 event => 'lexicon,load',
63 },
64 );
65 }
66
67 8 return $self;
68 }
69
70 9 1;
71
72 __END__
« OO/Plugin/Expand/BabelFish/Loc.pm ↑ Summary OO/Lexicon/Role/File.pm »