| 1 | package Class::Usul::L10N; | ||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||
| 3 | 3 | ▶ | use namespace::autoclean; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||
| 5 | 3 | ▶ | use Class::Null; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 6 | 3 | ▶ | use Class::Usul::Constants qw( FALSE LANG NUL SEP TRUE ); | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 7 | 3 | ▶ | use Class::Usul::Functions qw( assert is_arrayref | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 8 | 3 | is_hashref merge_attributes ); | |||||||||||||||||||||||||||||||||
| 9 | 3 | ▶ | use Class::Usul::Types qw( ArrayRef Bool HashRef Logger SimpleStr Str ); | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 10 | 3 | ▶ | use File::DataClass::Types qw( Directory Path ); | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 11 | 3 | ▶ | use File::Gettext; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 12 | 3 | ▶ | use File::Gettext::Constants qw( CONTEXT_SEP LOCALE_DIRS ); | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 13 | 3 | ▶ | use File::Spec::Functions qw( tmpdir ); | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 14 | 3 | ▶ | use Try::Tiny; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 15 | 3 | ▶ | use Unexpected::Functions qw( inflate_placeholders ); | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 16 | 3 | ▶ | use Moo; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||
| 18 | # Public attributes | ||||||||||||||||||||||||||||||||||
| 19 | 0 | ▶ | has 'l10n_attributes' => is => 'lazy', isa => HashRef, builder => sub { {} }; | ||||||||||||||||||||||||||||||||
|
Subroutine
_build_l10n_attributes: not called CC=1 SCAR=1.2
| |||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||
| 21 | 3 | has 'locale' => is => 'lazy', isa => SimpleStr, default => LANG; | |||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||
| 23 | has 'localedir' => is => 'lazy', isa => Path, coerce => TRUE, | ||||||||||||||||||||||||||||||||||
| 24 | 0 | ▶ | builder => sub { LOCALE_DIRS->[ 0 ] }; | ||||||||||||||||||||||||||||||||
|
Subroutine
_build_localedir: not called CC=1 SCAR=1.2
| |||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||
| 26 | has 'log' => is => 'ro', isa => Logger, | ||||||||||||||||||||||||||||||||||
| 27 | 0 | ▶ | builder => sub { Class::Null->new }; | ||||||||||||||||||||||||||||||||
|
Subroutine
_build_log: not called CC=1 SCAR=1.2
| |||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||
| 29 | has 'tempdir' => is => 'lazy', isa => Directory, coerce => TRUE, | ||||||||||||||||||||||||||||||||||
| 30 | 0 | ▶ | builder => sub { tmpdir }; | ||||||||||||||||||||||||||||||||
|
Subroutine
_build_tempdir: not called CC=1 SCAR=1.2
| |||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||
| 32 | # Private attributes | ||||||||||||||||||||||||||||||||||
| 33 | 2 | ▶ | has '_domains' => is => 'lazy', isa => ArrayRef[Str], builder => sub { | ||||||||||||||||||||||||||||||||
|
Subroutine
_build__domains: called CC=2 SCAR=7.6
Subroutine
__ANON__: called CC=2 SCAR=7.6
| |||||||||||||||||||||||||||||||||||
| 34 | 2 | ▶ | $_[ 0 ]->l10n_attributes->{domains} // [ 'messages' ] }, | ||||||||||||||||||||||||||||||||
|
Condition50%2/4
$_[0]->l10n_attributes->{"domains"} // ["messages"]
$_[0]->l10n_attributes->{"domains"} // ["messages"]
MC/DC0%0/1
$_[0]->l10n_attributes->{"domains"} // ["messages"]
$_[0]->l10n_attributes->{"domains"}
MC/DC0%0/1
$_[0]->l10n_attributes->{"domains"} // ["messages"]
$_[0]->l10n_attributes->{"domains"}
Truth table50%1/2
A
A= $_[0]->l10n_attributes->{"domains"}
Truth table50%1/2
A
A= $_[0]->l10n_attributes->{"domains"}
| |||||||||||||||||||||||||||||||||||
| 35 | 3 | reader => 'domains'; | |||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||
| 37 | 5 | ▶ | has '_source_name' => is => 'lazy', isa => SimpleStr, builder => sub { | ||||||||||||||||||||||||||||||||
|
Subroutine
_build__source_name: called CC=2 SCAR=7.6
| |||||||||||||||||||||||||||||||||||
| 38 | 5 | ▶ | $_[ 0 ]->l10n_attributes->{source_name} // 'po' }, | ||||||||||||||||||||||||||||||||
|
Condition50%1/2
$_[0]->l10n_attributes->{"source_name"} // "po"
MC/DC0%0/1
$_[0]->l10n_attributes->{"source_name"} // "po"
$_[0]->l10n_attributes->{"source_name"}
Truth table50%1/2
A
A= $_[0]->l10n_attributes->{"source_name"}
| |||||||||||||||||||||||||||||||||||
| 39 | 3 | reader => 'source_name'; | |||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||
| 41 | 3 | ▶ | has '_use_country' => is => 'lazy', isa => Bool, builder => sub { | ||||||||||||||||||||||||||||||||
|
Subroutine
_build__use_country: called CC=2 SCAR=7.6
| |||||||||||||||||||||||||||||||||||
| 42 | 3 | ▶ | $_[ 0 ]->l10n_attributes->{use_country} // FALSE }, | ||||||||||||||||||||||||||||||||
|
Condition50%1/2
$_[0]->l10n_attributes->{"use_country"} // 0
MC/DC0%0/1
$_[0]->l10n_attributes->{"use_country"} // 0
$_[0]->l10n_attributes->{"use_country"}
Truth table50%1/2
A
A= $_[0]->l10n_attributes->{"use_country"}
| |||||||||||||||||||||||||||||||||||
| 43 | 3 | reader => 'use_country'; | |||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||
| 45 | # Class attributes | ||||||||||||||||||||||||||||||||||
| 46 | 3 | my $domain_cache = {}; my $locale_cache = {}; | |||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||
| 48 | # Private methods | ||||||||||||||||||||||||||||||||||
| 49 | 19 | ▶ | my $_extract_lang_from = sub { | ||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||
| 50 | 19 | my ($self, $locale) = @_; | |||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||
| 52 | 19 | ▶ | exists $locale_cache->{ $locale } and return $locale_cache->{ $locale }; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||
| 54 | 3 | ▶ | my $sep = $self->use_country ? '.' : '_'; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 55 | 3 | my $lang = (split m{ \Q$sep\E }msx, $locale.$sep )[ 0 ]; | |||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||
| 57 | 3 | return $locale_cache->{ $locale } = $lang; | |||||||||||||||||||||||||||||||||
| 58 | 3 | }; | |||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||
| 60 | 19 | ▶ | my $_load_domains = sub { | ||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=10 SCAR=25.5
| |||||||||||||||||||||||||||||||||||
| 61 | 19 | my ($self, $args) = @_; my $charset; | |||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||
| 63 | 0 | ▶ | assert $self, sub { $args->{locale} }, 'No locale id'; | ||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||
| 65 | 19 | ▶ | my $locale = $args->{locale} or return; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 66 | 19 | my $lang = $self->$_extract_lang_from( $locale ); | |||||||||||||||||||||||||||||||||
| 67 | 19 | ▶ | my $names = $args->{domains} // $args->{domain_names} // $self->domains; | ||||||||||||||||||||||||||||||||
|
Condition33%2/6
($args->{"domains"} // $args->{"domain_names"}) // $self->domains
$args->{"domains"} // $args->{"domain_names"}
MC/DC0%0/3
($args->{"domains"} // $args->{"domain_names"}) // $self->domains
$args->{"domains"}
$args->{"domain_names"}
$self->domains
Truth table25%1/4
A // B // C
A= $args->{"domains"}B= $args->{"domain_names"}C= $self->domains
| |||||||||||||||||||||||||||||||||||
| 68 | 19 | ▶ | my @names = grep { defined and length } @{ $names }; | ||||||||||||||||||||||||||||||||
|
Condition33%1/3
defined $_ && length $_
MC/DC0%0/2
defined $_ && length $_
defined $_
length $_
Truth table33%1/3
A && B
A= defined $_B= length $_
| |||||||||||||||||||||||||||||||||||
| 69 | 19 | my $key = $lang.SEP.(join '+', @names ); | |||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||
| 71 | 19 | ▶ | defined $domain_cache->{ $key } and return $domain_cache->{ $key }; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||||
| 73 | 3 | my $attrs = { %{ $self->l10n_attributes }, builder => $self, | |||||||||||||||||||||||||||||||||
| 74 | source_name => $self->source_name, }; | ||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||
| 76 | 3 | ▶ | defined $self->localedir and $attrs->{localedir} = $self->localedir; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||
| 78 | 3 | ▶ | $locale =~ m{ \A (?: [a-z][a-z] ) | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 79 | (?: (?:_[A-Z][A-Z] )? \. ( [-_A-Za-z0-9]+ )? )? | ||||||||||||||||||||||||||||||||||
| 80 | (?: \@[-_A-Za-z0-9=;]+ )? \z }msx and $charset = $1; | ||||||||||||||||||||||||||||||||||
| 81 | 3 | ▶ | $charset and $attrs->{charset} = $charset; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||
| 83 | 3 | ▶ | my $domain = try { File::Gettext->new( $attrs )->load( $lang, @names ) } | ||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 84 | 0 | ▶ | catch { $self->log->error( $_ ); return }; | ||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=2.6
| |||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||
| 86 | 3 | ▶ | return $domain ? $domain_cache->{ $key } = $domain : undef; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 87 | 3 | }; | |||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||
| 89 | 18 | ▶ | my $_gettext = sub { | ||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=14 SCAR=27.6
| |||||||||||||||||||||||||||||||||||
| 90 | 18 | my ($self, $key, $args) = @_; | |||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||
| 92 | 18 | ▶ | my $count = $args->{count} || 1; | ||||||||||||||||||||||||||||||||
|
Condition100%2/2
$args->{'count'} || 1
MC/DC100%1/1
$args->{'count'} || 1
$args->{'count'}
Truth table100%2/2
A
A= $args->{'count'}
| |||||||||||||||||||||||||||||||||||
| 93 | 18 | ▶ | my $default = $args->{no_default} ? NUL : $key; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 94 | my $domain = $self->$_load_domains( $args ) | ||||||||||||||||||||||||||||||||||
| 95 | 18 | ▶ | or return ($default, $args->{plural_key})[ $count > 1 ] // $default; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
($default, $args->{"plural_key"})[$count > 1] // $default
MC/DC0%0/2
($default, $args->{"plural_key"})[$count > 1] // $default
($default, $args->{"plural_key"})[$count > 1]
$default
Truth table0%0/3
A // B
A= ($default, $args->{"plural_key"})[$count > 1]B= $default
| |||||||||||||||||||||||||||||||||||
| 96 | # Select either singular or plural translation | ||||||||||||||||||||||||||||||||||
| 97 | 18 | my ($nplurals, $plural) = (1, 0); | |||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||||
| 99 | 18 | ▶ | if ($count > 1) { # Some languages have more than one plural form | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 100 | 1 | ($nplurals, $plural) = $domain->{plural_func}->( $count ); | |||||||||||||||||||||||||||||||||
| 101 | 1 | ▶ | defined $nplurals or $nplurals = 0; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 102 | 1 | ▶ | defined $plural or $plural = 0; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 103 | 1 | ▶ | $plural > $nplurals and $plural = $nplurals; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 104 | } | ||||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||||
| 106 | my $id = defined $args->{context} | ||||||||||||||||||||||||||||||||||
| 107 | 18 | ▶ | ? $args->{context}.CONTEXT_SEP.$key : $key; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 108 | 18 | ▶ | my $msgs = $domain->{ $self->source_name } // {}; | ||||||||||||||||||||||||||||||||
|
Condition100%2/2
$$domain{$self->source_name} // {}
MC/DC100%1/1
$$domain{$self->source_name} // {}
$$domain{$self->source_name}
Truth table100%2/2
A
A= $$domain{$self->source_name}
| |||||||||||||||||||||||||||||||||||
| 109 | 18 | ▶ | my $msg = $msgs->{ $id } // {}; | ||||||||||||||||||||||||||||||||
|
Condition100%2/2
$msgs->{$id} // {}
MC/DC100%1/1
$msgs->{$id} // {}
$msgs->{$id}
Truth table100%2/2
A
A= $msgs->{$id}
| |||||||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||||||
| 111 | 18 | ▶ | return @{ $msg->{msgstr} // [] }[ $plural ] // $default; | ||||||||||||||||||||||||||||||||
|
Condition80%4/5
@{$msg->{"msgstr"} // [];}[$plural] // $default
$msg->{"msgstr"} // []
MC/DC0%0/2
@{$msg->{"msgstr"} // [];}[$plural] // $default
@{$msg->{"msgstr"} // [];}[$plural]
$default
MC/DC100%1/1
$msg->{"msgstr"} // []
$msg->{"msgstr"}
Truth table66%2/3
A // B
A= @{$msg->{"msgstr"} // [];}[$plural]B= $default
Truth table100%2/2
A
A= $msg->{"msgstr"}
| |||||||||||||||||||||||||||||||||||
| 112 | 3 | }; | |||||||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||||||
| 114 | # Construction | ||||||||||||||||||||||||||||||||||
| 115 | 5 | ▶ | around 'BUILDARGS' => sub { | ||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||
| 116 | 5 | my ($orig, $class, @args) = @_; my $attr = $orig->( $class, @args ); | |||||||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||||||||
| 118 | 5 | ▶ | my $builder = $attr->{builder} or return $attr; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 119 | 4 | ▶ | my $config = $builder->can( 'config' ) ? $builder->config : {}; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 120 | 4 | my $keys = [ qw( l10n_attributes locale localedir tempdir ) ]; | |||||||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||||||||
| 122 | 4 | merge_attributes $attr, $builder, [ 'log' ]; | |||||||||||||||||||||||||||||||||
| 123 | 4 | merge_attributes $attr, $config, $keys; | |||||||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||||||||
| 125 | 4 | return $attr; | |||||||||||||||||||||||||||||||||
| 126 | 3 | }; | |||||||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||||||||
| 128 | # Public methods | ||||||||||||||||||||||||||||||||||
| 129 | 1 | ▶ | sub get_po_header { | ||||||||||||||||||||||||||||||||
|
Subroutine
get_po_header: called CC=5 SCAR=17.8
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 130 | 1 | my ($self, $args) = @_; | |||||||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||||||||
| 132 | 1 | ▶ | my $domain = $self->$_load_domains( $args // {} ) or return {}; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$args // {}
MC/DC0%0/1
$args // {}
$args
Truth table50%1/2
A
A= $args
| |||||||||||||||||||||||||||||||||||
| 133 | 1 | ▶ | my $header = $domain->{po_header} or return {}; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||||||||
| 135 | 1 | ▶ | return $header->{msgstr} // {}; | ||||||||||||||||||||||||||||||||
|
Condition50%1/2
$header->{"msgstr"} // {}
MC/DC0%0/1
$header->{"msgstr"} // {}
$header->{"msgstr"}
Truth table50%1/2
A
A= $header->{"msgstr"}
| |||||||||||||||||||||||||||||||||||
| 136 | } | ||||||||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||||||||
| 138 | 0 | ▶ | sub invalidate_cache { | ||||||||||||||||||||||||||||||||
|
Subroutine
invalidate_cache: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 139 | 0 | $domain_cache = {}; return; | |||||||||||||||||||||||||||||||||
| 140 | } | ||||||||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||||||||
| 142 | 0 | ▶ | sub loc { | ||||||||||||||||||||||||||||||||
|
Subroutine
loc: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 143 | 0 | my $self = shift; return $self->localizer( $self->locale, @_ ); | |||||||||||||||||||||||||||||||||
| 144 | } | ||||||||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||||||||
| 146 | 18 | ▶ | sub localize { | ||||||||||||||||||||||||||||||||
|
Subroutine
localize: called CC=8 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 147 | 18 | my ($self, $key, $args) = @_; | |||||||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||||||||
| 149 | 18 | ▶ | defined $key or return; $key = "${key}"; chomp $key; $args //= {}; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$args //= {}
MC/DC0%0/1
$args //= {}
$args
Truth table50%1/2
A
A= $args
| |||||||||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||||||||
| 151 | # Lookup the message using the supplied key from the po file | ||||||||||||||||||||||||||||||||||
| 152 | 18 | my $text = $self->$_gettext( $key, $args ); | |||||||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||||||||
| 154 | 18 | ▶ | if (defined $args->{params} and ref $args->{params} eq 'ARRAY') { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $args->{"params"} and ref $args->{"params"} eq "ARRAY"
MC/DC50%1/2
defined $args->{"params"} and ref $args->{"params"} eq "ARRAY"
defined $args->{"params"}
ref $args->{"params"} eq "ARRAY"
Truth table66%2/3
A and B
A= defined $args->{"params"}B= ref $args->{"params"} eq "ARRAY"
| |||||||||||||||||||||||||||||||||||
| 155 | 12 | ▶ | 0 > index $text, '[_' and return $text; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||||||||
| 157 | # Expand positional parameters of the form [_<n>] | ||||||||||||||||||||||||||||||||||
| 158 | return inflate_placeholders [ '[?]', '[]', $args->{no_quote_bind_values}], | ||||||||||||||||||||||||||||||||||
| 159 | 4 | $text, @{ $args->{params} }; | |||||||||||||||||||||||||||||||||
| 160 | } | ||||||||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||||||||
| 162 | 6 | ▶ | 0 > index $text, '{' and return $text; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||||||||
| 164 | # Expand named parameters of the form {param_name} | ||||||||||||||||||||||||||||||||||
| 165 | 0 | my %args = %{ $args }; my $re = join '|', map { quotemeta $_ } keys %args; | |||||||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||||||||
| 167 | 0 | ▶ | $text =~ s{ \{($re)\} }{ defined $args{ $1 } ? $args{ $1 } : "{${1}?}" }egmx; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||||||||
| 169 | 0 | return $text; | |||||||||||||||||||||||||||||||||
| 170 | } | ||||||||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||||||||
| 172 | 7 | ▶ | sub localizer { | ||||||||||||||||||||||||||||||||
|
Subroutine
localizer: called CC=5 SCAR=16.4
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 173 | 7 | my ($self, $locale, $key, @args) = @_; my $car = $args[ 0 ]; | |||||||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||||||||
| 175 | 7 | ▶ | my $args = (is_hashref $car) ? { %{ $car } } | ||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||
| 176 | : { params => (is_arrayref $car) ? $car : [ @args ] }; | ||||||||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||||||||
| 178 | 7 | ▶ | $args->{locale } //= $locale; | ||||||||||||||||||||||||||||||||
|
Condition33%1/3
$args->{"locale"} //= $locale
MC/DC0%0/2
$args->{"locale"} //= $locale
$args->{"locale"}
$locale
Truth table33%1/3
A //= B
A= $args->{"locale"}B= $locale
| |||||||||||||||||||||||||||||||||||
| 179 | 7 | ▶ | $args->{no_quote_bind_values} //= TRUE; | ||||||||||||||||||||||||||||||||
|
Condition50%1/2
$args->{"no_quote_bind_values"} //= 1
MC/DC0%0/1
$args->{"no_quote_bind_values"} //= 1
$args->{"no_quote_bind_values"}
Truth table50%1/2
A
A= $args->{"no_quote_bind_values"}
| |||||||||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||||||||
| 181 | 7 | return $self->localize( $key, $args ); | |||||||||||||||||||||||||||||||||
| 182 | } | ||||||||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||||||||
| 184 | 3 | 1; | |||||||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||||||||
| 186 | __END__ | ||||||||||||||||||||||||||||||||||