| 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
| |||||||||||||||||||
| 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
| |||||||||||||||||||
| 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
| |||||||||||||||||||
| 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
| |||||||||||||||||||
| 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
| |||||||||||||||||||
| 48 | 13 | my $plural_count = @{ $value->{msgstr_plural} }; | |||||||||||||||||
| 49 | 13 | ▶ | $plural_count <= $nplurals or confess sprintf | ||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||
| 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
| |||||||||||||||||||
| 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__ | ||||||||||||||||||