| 1 | package YATT::Lite::Partial::Gettext; sub MY () {__PACKAGE__} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | 52 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 52 | ▶ | use warnings qw(FATAL all NONFATAL misc); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | use YATT::Lite::Partial | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 52 | ▶ | (fields => [qw/_locale_cache/] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 52 | , requires => [qw/error use_encoded_config/]); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 52 | ▶ | use YATT::Lite::Util qw/ckeval/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | #======================================== | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | # Locale support. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | #======================================== | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 52 | ▶ | use YATT::Lite::Util::Enum (_E_ => [qw/MTIME DICT LIST | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 52 | FORMULA NPLURALS HEADER/]); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 5 | ▶ | sub configure_locale { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
configure_locale: called CC=3 SCAR=11.6
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 5 | (my MY $self, my $spec) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 5 | require Locale::PO; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 5 | ▶ | if (ref $spec eq 'ARRAY') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 5 | my ($type, @args) = @$spec; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 5 | ▶ | my $sub = $self->can("configure_locale_$type") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | or $self->error("Unknown locale spec: %s", $type); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 5 | $sub->($self, @args); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 0 | die "NIMPL"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | 5 | ▶ | sub configure_locale_data { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
configure_locale_data: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 5 | (my MY $self, my $value) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 5 | ▶ | my $cache = $self->{_locale_cache} ||= {}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$self->{"_locale_cache"} ||= {}
MC/DC100%1/1
$self->{"_locale_cache"} ||= {}
$self->{"_locale_cache"}
Truth table100%2/2
A
A= $self->{"_locale_cache"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 5 | foreach my $lang (keys %$value) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 8 | my $entry = []; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | 8 | $entry->[_E_LIST] = my $list = $value->{$lang}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 8 | $entry->[_E_DICT] = my $hash = {}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 8 | foreach my $po (@$list) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 10 | $hash->{$po->dequote($po->msgid)} = $po; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 8 | $self->lang_parse_header($entry); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 8 | $cache->{$lang} = $entry; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 8 | ▶ | sub lang_parse_header { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
lang_parse_header: called CC=4 SCAR=14.3
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 8 | (my MY $self, my $entry) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 8 | ▶ | my $header = $entry->[_E_DICT]->{''} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | or return; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | 3 | my $xhf = YATT::Lite::XHF::parse_xhf | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | ($header->dequote($header->msgstr)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 3 | my ($sub, $nplurals); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 3 | ▶ | if (my $form = $xhf->{'Plural-Forms'}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | 3 | ▶ | if (($nplurals, my $formula) = $form =~ m{^\s*nplurals\s*=\s*(\d+)\s*; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | \s*plural\s*=\s*([^;]+)}x) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 3 | $formula =~ s/\bn\b/\$n/g; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 3 | $sub = ckeval(sprintf q|sub {my ($n) = @_; %s}|, $formula); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 0 | $sub = \&lang_plural_formula_en; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 0 | $nplurals = 2; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 3 | @{$entry}[_E_FORMULA, _E_NPLURALS, _E_HEADER] = ($sub, $nplurals, $xhf); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | 0 | ▶ | sub lang_load_msgcat { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
lang_load_msgcat: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 0 | (my MY $self, my ($lang, $fn)) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | 0 | require Locale::PO; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | 0 | my $entry = []; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 0 | $entry->[_E_DICT] = my $hash = {}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 0 | $entry->[_E_LIST] = my $res = Locale::PO->load_file_asarray($fn); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 0 | my $use_encoding = $self->use_encoded_config; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | 0 | foreach my $loc (@$res) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 0 | ▶ | if ($use_encoding) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | 0 | $loc->msgid(Encode::decode("utf-8", $loc->dequote($loc->msgid))); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | 0 | $loc->msgstr(Encode::decode("utf-8", $loc->dequote($loc->msgstr))); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 0 | my $id = $loc->dequote($loc->msgid); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 0 | $hash->{$id} = $loc; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 0 | $self->lang_parse_header($entry); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 0 | $self->{_locale_cache}{$lang} = $entry; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | 0 | ▶ | sub _lang_dequote { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_lang_dequote: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 0 | shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 0 | my $string = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 0 | $string =~ s/^"(.*)"/$1/s; # XXX: Locale::PO::dequote is not enough. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | 0 | $string =~ s/\\"/"/g; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 0 | return $string; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | 4 | ▶ | sub lang_plural_formula_en { my ($n) = @_; $n != 1 } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
lang_plural_formula_en: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | 7 | ▶ | sub lang_gettext { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
lang_gettext: called CC=3 SCAR=11.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | 7 | (my MY $self, my ($lang, $msgid)) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | 7 | ▶ | my $entry = $self->lang_getmsg($lang, $msgid) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | or return $msgid; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | 2 | ▶ | $entry->dequote($entry->msgstr) || $msgid; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | 6 | ▶ | sub lang_ngettext { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
lang_ngettext: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | 6 | (my MY $self, my ($lang, $msgid, $msg_plural, $num)) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | 6 | ▶ | if (my ($locale, $entry) = $self->lang_getmsg($lang, $msgid)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | 2 | my $ix = $locale->[_E_FORMULA]->($num); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | 2 | my $hash = $entry->msgstr_n; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 2 | ▶ | if (defined (my $hit = $hash->{$ix})) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | 2 | return $entry->dequote($hit); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | 4 | return ($msgid, $msg_plural)[lang_plural_formula_en($num)]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | 0 | ▶ | sub lang_msgcat { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
lang_msgcat: not called CC=6 SCAR=37.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | 0 | (my MY $self, my $lang) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | 0 | my ($catalog); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | return unless defined $lang | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | 0 | ▶ | and $catalog = $self->{_locale_cache}{$lang}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $lang and $catalog = $self->{"_locale_cache"}{$lang}
MC/DC0%0/2
defined $lang and $catalog = $self->{"_locale_cache"}{$lang}
defined $lang
$catalog = $self->{"_locale_cache"}{$lang}
Truth table0%0/3
A and B
A= defined $langB= $catalog = $self->{"_locale_cache"}{$lang}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | 0 | ▶ | if (wantarray) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | # For later use in lang_extract_lcmsg | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | 0 | ▶ | ($catalog->[_E_LIST] //= [], $catalog->[_E_DICT] //= {}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/4
$catalog->[2] //= []
$catalog->[1] //= {}
MC/DC0%0/1
$catalog->[2] //= []
$catalog->[2]
MC/DC0%0/1
$catalog->[1] //= {}
$catalog->[1]
Truth table0%0/2
A
A= $catalog->[2]
Truth table0%0/2
A
A= $catalog->[1]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | 0 | $catalog; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | 13 | ▶ | sub lang_getmsg { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
lang_getmsg: called CC=6 SCAR=18.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | 13 | (my MY $self, my ($lang, $msgid)) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | 13 | my ($catalog, $msg); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | 13 | ▶ | if (defined $msgid and defined $lang | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition77%7/9
defined $msgid and defined $lang and $catalog = $self->{"_locale_cache"}{$lang} and $msg = $catalog->[1]{$msgid}
defined $msgid and defined $lang and $catalog = $self->{"_locale_cache"}{$lang}
defined $msgid and defined $lang
MC/DC50%2/4
defined $msgid and defined $lang and $catalog = $self->{"_locale_cache"}{$lang} and $msg = $catalog->[1]{$msgid}
defined $msgid
defined $lang
$catalog = $self->{"_locale_cache"}{$lang}
$msg = $catalog->[1]{$msgid}
Truth table60%3/5
A and B and C and D
A= defined $msgidB= defined $langC= $catalog = $self->{"_locale_cache"}{$lang}D= $msg = $catalog->[1]{$msgid}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | and $catalog = $self->{_locale_cache}{$lang} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | and $msg = $catalog->[_E_DICT]{$msgid}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | 4 | ▶ | wantarray ? ($catalog, $msg) : $msg; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | 9 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | 52 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||