| 1 | package Data::Localize; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | 6 | ▶ | use Moo; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 3 | 6 | ▶ | use Module::Load (); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 6 | ▶ | use Scalar::Util (); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | 6 | ▶ | use I18N::LangTags (); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | 6 | ▶ | use I18N::LangTags::Detect (); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | 6 | ▶ | use 5.008; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||
| 9 | 6 | our $VERSION = '0.00028'; | |||||||||||||||||||||||||||||||||||||||||
| 10 | 6 | our $AUTHORITY = 'cpan:DMAKI'; | |||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||
| 12 | 6 | ▶ | BEGIN { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=2 SCAR=7.1
| |||||||||||||||||||||||||||||||||||||||||||
| 13 | 6 | ▶ | if (! defined &DEBUG) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 14 | 6 | require constant; | |||||||||||||||||||||||||||||||||||||||||
| 15 | 6 | constant->import(DEBUG => !!$ENV{DATA_LOCALIZE_DEBUG}); | |||||||||||||||||||||||||||||||||||||||||
| 16 | } | ||||||||||||||||||||||||||||||||||||||||||
| 17 | } | ||||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||
| 19 | 6 | ▶ | BEGIN { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 20 | 6 | if (DEBUG) { | |||||||||||||||||||||||||||||||||||||||||
| 21 | require Data::Localize::Log; | ||||||||||||||||||||||||||||||||||||||||||
| 22 | Data::Localize::Log->import; | ||||||||||||||||||||||||||||||||||||||||||
| 23 | } | ||||||||||||||||||||||||||||||||||||||||||
| 24 | } | ||||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||
| 26 | has auto => ( | ||||||||||||||||||||||||||||||||||||||||||
| 27 | is => 'rw', | ||||||||||||||||||||||||||||||||||||||||||
| 28 | 4 | ▶ | default => sub { 1 }, | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 29 | 6 | ); | |||||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||||||
| 31 | has auto_localizer => ( | ||||||||||||||||||||||||||||||||||||||||||
| 32 | is => 'rw', | ||||||||||||||||||||||||||||||||||||||||||
| 33 | lazy => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 34 | builder => "_build_auto_localizer", | ||||||||||||||||||||||||||||||||||||||||||
| 35 | 2 | ▶ | isa => sub { $_[0]->isa('Data::Localize::Auto') }, | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 36 | 6 | ); | |||||||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||||||||
| 38 | 6 | has _languages => ( | |||||||||||||||||||||||||||||||||||||||||
| 39 | is => 'rw', | ||||||||||||||||||||||||||||||||||||||||||
| 40 | lazy => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 41 | builder => "_build__languages", | ||||||||||||||||||||||||||||||||||||||||||
| 42 | init_arg => 'languages', | ||||||||||||||||||||||||||||||||||||||||||
| 43 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||||||||
| 45 | 6 | has _fallback_languages => ( | |||||||||||||||||||||||||||||||||||||||||
| 46 | is => 'rw', | ||||||||||||||||||||||||||||||||||||||||||
| 47 | lazy => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 48 | builder => "_build__fallback_languages", | ||||||||||||||||||||||||||||||||||||||||||
| 49 | init_arg => 'fallback_languages', | ||||||||||||||||||||||||||||||||||||||||||
| 50 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||||||||
| 52 | has _localizers => ( | ||||||||||||||||||||||||||||||||||||||||||
| 53 | is => 'rw', | ||||||||||||||||||||||||||||||||||||||||||
| 54 | 7 | ▶ | coerce => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=6 SCAR=31.2
| |||||||||||||||||||||||||||||||||||||||||||
| 55 | 7 | ▶ | if (ref $_[0] ne 'ARRAY') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 56 | 0 | Carp::croak("localizer list must be a list of Localizer objects"); | |||||||||||||||||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||||||||||
| 59 | # XXX Want to deprecate this auto-instantiation | ||||||||||||||||||||||||||||||||||||||||||
| 60 | 7 | foreach my $args (@{$_[0]}) { | |||||||||||||||||||||||||||||||||||||||||
| 61 | 0 | ▶ | if (Scalar::Util::blessed($args)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 62 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||||||||||
| 65 | 0 | my $klass = delete $args->{class}; | |||||||||||||||||||||||||||||||||||||||||
| 66 | 0 | ▶ | if (! $klass) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 67 | 0 | Carp::croak("No class provided for localizer list"); | |||||||||||||||||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||||||||||||||||
| 69 | 0 | ▶ | if ($klass !~ s/^\+//) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 70 | 0 | $klass = "Data::Localize::$klass"; | |||||||||||||||||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||||||||||||||||
| 72 | 0 | Module::Load::load($klass); | |||||||||||||||||||||||||||||||||||||||||
| 73 | 0 | $args = $klass->new(%$args); | |||||||||||||||||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||||||||||||||||
| 75 | 7 | $_[0]; | |||||||||||||||||||||||||||||||||||||||||
| 76 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 77 | 7 | ▶ | default => sub { +[] }, | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 78 | 6 | init_arg => 'localizers', | |||||||||||||||||||||||||||||||||||||||||
| 79 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||||||||||
| 81 | has localizer_map => ( | ||||||||||||||||||||||||||||||||||||||||||
| 82 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||
| 83 | 7 | ▶ | default => sub { +{} }, | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 84 | 6 | ); | |||||||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||||||||
| 86 | 7 | ▶ | sub BUILD { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BUILD: called CC=3 SCAR=14.2
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 87 | 7 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||||||||||
| 89 | 7 | ▶ | if ($self->count_localizers > 0) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 90 | 0 | foreach my $loc (@{ $self->_localizers }) { | |||||||||||||||||||||||||||||||||||||||||
| 91 | 0 | $loc->register($self); | |||||||||||||||||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||||||||||||||||
| 94 | 7 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||||||||||
| 97 | 2 | ▶ | sub _build__fallback_languages { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_build__fallback_languages: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 98 | 2 | return [ 'en' ]; | |||||||||||||||||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||||||||||
| 101 | 3 | ▶ | sub _build__languages { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_build__languages: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 102 | 3 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 103 | 3 | $self->detect_languages(); | |||||||||||||||||||||||||||||||||||||||||
| 104 | } | ||||||||||||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||||||||||||
| 106 | 2 | ▶ | sub _build_auto_localizer { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_build_auto_localizer: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 107 | 2 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 108 | 2 | require Data::Localize::Auto; | |||||||||||||||||||||||||||||||||||||||||
| 109 | 2 | Data::Localize::Auto->new(); | |||||||||||||||||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||||||||||||||
| 112 | 3 | ▶ | sub set_languages { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
set_languages: called CC=2 SCAR=7.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 113 | 3 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 114 | 3 | ▶ | $self->_languages([ @_ > 0 ? @_ : $self->detect_languages ]); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 115 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||||||||||||||||
| 118 | 0 | ▶ | sub add_fallback_languages { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
add_fallback_languages: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 119 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 120 | 0 | push @{$self->_fallback_languages}, @_; | |||||||||||||||||||||||||||||||||||||||||
| 121 | } | ||||||||||||||||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||||||||||||||||
| 123 | 3 | ▶ | sub fallback_languages { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
fallback_languages: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 124 | 3 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 125 | 3 | return @{$self->_fallback_languages}; | |||||||||||||||||||||||||||||||||||||||||
| 126 | } | ||||||||||||||||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||||||||||||||||
| 128 | 27 | ▶ | sub languages { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
languages: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 129 | 27 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 130 | 27 | return @{$self->_languages}; | |||||||||||||||||||||||||||||||||||||||||
| 131 | } | ||||||||||||||||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||||||||||||||||
| 133 | 3 | ▶ | sub localizers { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
localizers: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 134 | 3 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 135 | 3 | return $self->_localizers; | |||||||||||||||||||||||||||||||||||||||||
| 136 | } | ||||||||||||||||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||||||||||||||||
| 138 | 8 | ▶ | sub count_localizers { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
count_localizers: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 139 | 8 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 140 | 8 | return scalar @{$self->_localizers}; | |||||||||||||||||||||||||||||||||||||||||
| 141 | } | ||||||||||||||||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||||||||||||||||
| 143 | 0 | ▶ | sub grep_localizers { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
grep_localizers: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 144 | 0 | my ($self, $cb) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 145 | 0 | grep { $cb->($_) } @{$self->_localizers}; | |||||||||||||||||||||||||||||||||||||||||
| 146 | } | ||||||||||||||||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||||||||||||||||
| 148 | 44 | ▶ | sub get_localizer_from_lang { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_localizer_from_lang: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 149 | 44 | my ($self, $key) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 150 | 44 | return $self->localizer_map->{$key}; | |||||||||||||||||||||||||||||||||||||||||
| 151 | } | ||||||||||||||||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||||||||||||||||
| 153 | 14 | ▶ | sub set_localizer_map { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
set_localizer_map: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 154 | 14 | my ($self, $key, $value) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 155 | 14 | return $self->localizer_map->{$key} = $value; | |||||||||||||||||||||||||||||||||||||||||
| 156 | } | ||||||||||||||||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||||||||||||||||
| 158 | 3 | ▶ | sub detect_languages { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
detect_languages: called CC=3 SCAR=12.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 159 | 3 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 160 | 3 | ▶ | my @lang = I18N::LangTags::implicate_supers( | ||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
&I18N::LangTags::Detect::detect() || $self->fallback_languages
MC/DC0%0/2
&I18N::LangTags::Detect::detect() || $self->fallback_languages
&I18N::LangTags::Detect::detect()
$self->fallback_languages
Truth table33%1/3
A || B
A= &I18N::LangTags::Detect::detect()B= $self->fallback_languages
| |||||||||||||||||||||||||||||||||||||||||||
| 161 | I18N::LangTags::Detect::detect() || | ||||||||||||||||||||||||||||||||||||||||||
| 162 | $self->fallback_languages, | ||||||||||||||||||||||||||||||||||||||||||
| 163 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 164 | 3 | if (DEBUG) { | |||||||||||||||||||||||||||||||||||||||||
| 165 | local $Log::Minimal::AUTODUMP = 1; | ||||||||||||||||||||||||||||||||||||||||||
| 166 | debugf("detect_languages: auto-detected %s", \@lang);; | ||||||||||||||||||||||||||||||||||||||||||
| 167 | } | ||||||||||||||||||||||||||||||||||||||||||
| 168 | 3 | ▶ | return wantarray ? @lang : \@lang; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 169 | } | ||||||||||||||||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||||||||||||||||
| 171 | 0 | ▶ | sub detect_languages_from_header { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
detect_languages_from_header: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 172 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 173 | my @lang = I18N::LangTags::implicate_supers( | ||||||||||||||||||||||||||||||||||||||||||
| 174 | 0 | ▶ | I18N::LangTags::Detect->http_accept_langs( $_[0] || $ENV{HTTP_ACCEPT_LANGUAGE}), | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$_[0] || $ENV{'HTTP_ACCEPT_LANGUAGE'}
MC/DC0%0/2
$_[0] || $ENV{'HTTP_ACCEPT_LANGUAGE'}
$_[0]
$ENV{'HTTP_ACCEPT_LANGUAGE'}
Truth table0%0/3
A || B
A= $_[0]B= $ENV{'HTTP_ACCEPT_LANGUAGE'}
| |||||||||||||||||||||||||||||||||||||||||||
| 175 | $self->fallback_languages, | ||||||||||||||||||||||||||||||||||||||||||
| 176 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 177 | 0 | if (DEBUG) { | |||||||||||||||||||||||||||||||||||||||||
| 178 | local $Log::Minimal::AUTODUMP = 1; | ||||||||||||||||||||||||||||||||||||||||||
| 179 | debugf("detect_languages_from_header detected %s", \@lang); | ||||||||||||||||||||||||||||||||||||||||||
| 180 | } | ||||||||||||||||||||||||||||||||||||||||||
| 181 | 0 | ▶ | return wantarray ? @lang : \@lang; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 182 | } | ||||||||||||||||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||||||||||||||||
| 184 | 24 | ▶ | sub localize { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
localize: called CC=10 SCAR=23.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 185 | 24 | my ($self, $key, @args) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||||||||||||||||
| 187 | 24 | if (DEBUG) { | |||||||||||||||||||||||||||||||||||||||||
| 188 | debugf("localize - Looking up key '%s'", $key); | ||||||||||||||||||||||||||||||||||||||||||
| 189 | } | ||||||||||||||||||||||||||||||||||||||||||
| 190 | 24 | my @languages = $self->languages ; | |||||||||||||||||||||||||||||||||||||||||
| 191 | 24 | if (DEBUG) { | |||||||||||||||||||||||||||||||||||||||||
| 192 | local $Log::Minimal::AUTODUMP = 1; | ||||||||||||||||||||||||||||||||||||||||||
| 193 | debugf("localize - Loaded languages %s", \@languages); | ||||||||||||||||||||||||||||||||||||||||||
| 194 | } | ||||||||||||||||||||||||||||||||||||||||||
| 195 | 24 | foreach my $lang (@languages) { | |||||||||||||||||||||||||||||||||||||||||
| 196 | 25 | if (DEBUG) { | |||||||||||||||||||||||||||||||||||||||||
| 197 | debugf("localize - Attempting language '%s'", $lang); | ||||||||||||||||||||||||||||||||||||||||||
| 198 | } | ||||||||||||||||||||||||||||||||||||||||||
| 199 | 25 | ▶ | my $localizers = $self->get_localizer_from_lang($lang) || []; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$self->get_localizer_from_lang($lang) || []
MC/DC100%1/1
$self->get_localizer_from_lang($lang) || []
$self->get_localizer_from_lang($lang)
Truth table100%2/2
A
A= $self->get_localizer_from_lang($lang)
| |||||||||||||||||||||||||||||||||||||||||||
| 200 | 25 | if (DEBUG) { | |||||||||||||||||||||||||||||||||||||||||
| 201 | debugf("localize - Loaded %d localizers for lang %s", | ||||||||||||||||||||||||||||||||||||||||||
| 202 | scalar @$localizers, | ||||||||||||||||||||||||||||||||||||||||||
| 203 | $lang | ||||||||||||||||||||||||||||||||||||||||||
| 204 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 205 | } | ||||||||||||||||||||||||||||||||||||||||||
| 206 | 25 | foreach my $localizer (@$localizers) { | |||||||||||||||||||||||||||||||||||||||||
| 207 | 22 | if (DEBUG) { | |||||||||||||||||||||||||||||||||||||||||
| 208 | local $Log::Minimal::AUTODUMP = 1; | ||||||||||||||||||||||||||||||||||||||||||
| 209 | debugf("localize - Trying with %s", $localizer); | ||||||||||||||||||||||||||||||||||||||||||
| 210 | } | ||||||||||||||||||||||||||||||||||||||||||
| 211 | 22 | my $out = $localizer->localize_for( | |||||||||||||||||||||||||||||||||||||||||
| 212 | lang => $lang, | ||||||||||||||||||||||||||||||||||||||||||
| 213 | id => $key, | ||||||||||||||||||||||||||||||||||||||||||
| 214 | args => \@args | ||||||||||||||||||||||||||||||||||||||||||
| 215 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 216 | |||||||||||||||||||||||||||||||||||||||||||
| 217 | 22 | ▶ | if ($out) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 218 | 19 | if (DEBUG) { | |||||||||||||||||||||||||||||||||||||||||
| 219 | debugf("localize - Got localization: '%s'", $out); | ||||||||||||||||||||||||||||||||||||||||||
| 220 | } | ||||||||||||||||||||||||||||||||||||||||||
| 221 | 19 | return $out; | |||||||||||||||||||||||||||||||||||||||||
| 222 | } | ||||||||||||||||||||||||||||||||||||||||||
| 223 | } | ||||||||||||||||||||||||||||||||||||||||||
| 224 | } | ||||||||||||||||||||||||||||||||||||||||||
| 225 | |||||||||||||||||||||||||||||||||||||||||||
| 226 | 5 | if (DEBUG) { | |||||||||||||||||||||||||||||||||||||||||
| 227 | debugf("localize - nothing found in registered languages"); | ||||||||||||||||||||||||||||||||||||||||||
| 228 | } | ||||||||||||||||||||||||||||||||||||||||||
| 229 | |||||||||||||||||||||||||||||||||||||||||||
| 230 | # if we got here, we missed on all languages. | ||||||||||||||||||||||||||||||||||||||||||
| 231 | # one last shot. try the '*' slot | ||||||||||||||||||||||||||||||||||||||||||
| 232 | 5 | ▶ | foreach my $localizer (@{$self->get_localizer_from_lang('*') || []}) { | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$self->get_localizer_from_lang('*') || []
MC/DC100%1/1
$self->get_localizer_from_lang('*') || []
$self->get_localizer_from_lang('*')
Truth table100%2/2
A
A= $self->get_localizer_from_lang('*')
| |||||||||||||||||||||||||||||||||||||||||||
| 233 | 3 | foreach my $lang ($self->languages) { | |||||||||||||||||||||||||||||||||||||||||
| 234 | 4 | if (DEBUG) { | |||||||||||||||||||||||||||||||||||||||||
| 235 | debugf("localize - trying %s for '*' with localizer %s", | ||||||||||||||||||||||||||||||||||||||||||
| 236 | $lang, | ||||||||||||||||||||||||||||||||||||||||||
| 237 | $localizer | ||||||||||||||||||||||||||||||||||||||||||
| 238 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 239 | } | ||||||||||||||||||||||||||||||||||||||||||
| 240 | 4 | my $out = $localizer->localize_for( | |||||||||||||||||||||||||||||||||||||||||
| 241 | lang => $lang, | ||||||||||||||||||||||||||||||||||||||||||
| 242 | id => $key, | ||||||||||||||||||||||||||||||||||||||||||
| 243 | args => \@args | ||||||||||||||||||||||||||||||||||||||||||
| 244 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 245 | 4 | ▶ | if ($out) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 246 | 1 | if (DEBUG) { | |||||||||||||||||||||||||||||||||||||||||
| 247 | debugf("localize - found for %s, adding to map", $lang); | ||||||||||||||||||||||||||||||||||||||||||
| 248 | } | ||||||||||||||||||||||||||||||||||||||||||
| 249 | |||||||||||||||||||||||||||||||||||||||||||
| 250 | # oh, found one? set it in the localizer map so we don't have | ||||||||||||||||||||||||||||||||||||||||||
| 251 | # to look it up again | ||||||||||||||||||||||||||||||||||||||||||
| 252 | 1 | $self->add_localizer_map($lang, $localizer); | |||||||||||||||||||||||||||||||||||||||||
| 253 | 1 | return $out; | |||||||||||||||||||||||||||||||||||||||||
| 254 | } | ||||||||||||||||||||||||||||||||||||||||||
| 255 | } | ||||||||||||||||||||||||||||||||||||||||||
| 256 | } | ||||||||||||||||||||||||||||||||||||||||||
| 257 | |||||||||||||||||||||||||||||||||||||||||||
| 258 | # if you got here, and you /still/ can't find a proper localization, | ||||||||||||||||||||||||||||||||||||||||||
| 259 | # then we fallback to 'auto' feature | ||||||||||||||||||||||||||||||||||||||||||
| 260 | 4 | ▶ | if ($self->auto) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 261 | 3 | if (DEBUG) { | |||||||||||||||||||||||||||||||||||||||||
| 262 | debugf("localize - trying auto-lexicon for '%s'", $key); | ||||||||||||||||||||||||||||||||||||||||||
| 263 | } | ||||||||||||||||||||||||||||||||||||||||||
| 264 | 3 | return $self->auto_localizer->localize_for(id => $key, args => \@args); | |||||||||||||||||||||||||||||||||||||||||
| 265 | } | ||||||||||||||||||||||||||||||||||||||||||
| 266 | |||||||||||||||||||||||||||||||||||||||||||
| 267 | 1 | return (); | |||||||||||||||||||||||||||||||||||||||||
| 268 | } | ||||||||||||||||||||||||||||||||||||||||||
| 269 | |||||||||||||||||||||||||||||||||||||||||||
| 270 | 6 | ▶ | sub add_localizer { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
add_localizer: called CC=7 SCAR=19.6
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 271 | 6 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 272 | |||||||||||||||||||||||||||||||||||||||||||
| 273 | 6 | my $localizer; | |||||||||||||||||||||||||||||||||||||||||
| 274 | 6 | ▶ | if (@_ == 1) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 275 | 2 | $localizer = $_[0]; | |||||||||||||||||||||||||||||||||||||||||
| 276 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 277 | 4 | my %args = @_; | |||||||||||||||||||||||||||||||||||||||||
| 278 | |||||||||||||||||||||||||||||||||||||||||||
| 279 | 4 | my $klass = delete $args{class}; | |||||||||||||||||||||||||||||||||||||||||
| 280 | 4 | ▶ | if ($klass !~ s/^\+//) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 281 | 4 | $klass = "Data::Localize::$klass"; | |||||||||||||||||||||||||||||||||||||||||
| 282 | } | ||||||||||||||||||||||||||||||||||||||||||
| 283 | 4 | Module::Load::load($klass); | |||||||||||||||||||||||||||||||||||||||||
| 284 | 4 | if (Data::Localize::DEBUG) { | |||||||||||||||||||||||||||||||||||||||||
| 285 | local $Log::Minimal::AUTODUMP = 1; | ||||||||||||||||||||||||||||||||||||||||||
| 286 | debugf("Creating localizer '%s' (%s)", $klass, \%args); | ||||||||||||||||||||||||||||||||||||||||||
| 287 | } | ||||||||||||||||||||||||||||||||||||||||||
| 288 | 4 | $localizer = $klass->new(%args); | |||||||||||||||||||||||||||||||||||||||||
| 289 | } | ||||||||||||||||||||||||||||||||||||||||||
| 290 | |||||||||||||||||||||||||||||||||||||||||||
| 291 | 6 | ▶ | if (! $localizer || ! Scalar::Util::blessed($localizer) || ! $localizer->isa( 'Data::Localize::Localizer' ) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%4/6
$localizer and builtin::blessed($localizer) and $localizer->isa("Data::Localize::Localizer")
$localizer and builtin::blessed($localizer)
MC/DC33%1/3
$localizer and builtin::blessed($localizer) and $localizer->isa("Data::Localize::Localizer")
$localizer
builtin::blessed($localizer)
$localizer->isa("Data::Localize::Localizer")
Truth table50%2/4
A and B and C
A= $localizerB= builtin::blessed($localizer)C= $localizer->isa("Data::Localize::Localizer")
| |||||||||||||||||||||||||||||||||||||||||||
| 292 | 1 | ▶ | Carp::confess("Bad localizer: '" . ( defined $localizer ? $localizer : '(null)' ) . "'"); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 293 | } | ||||||||||||||||||||||||||||||||||||||||||
| 294 | |||||||||||||||||||||||||||||||||||||||||||
| 295 | 5 | if (DEBUG()) { | |||||||||||||||||||||||||||||||||||||||||
| 296 | debugf("add_localizer: %s", $localizer); | ||||||||||||||||||||||||||||||||||||||||||
| 297 | } | ||||||||||||||||||||||||||||||||||||||||||
| 298 | 5 | $localizer->register($self); | |||||||||||||||||||||||||||||||||||||||||
| 299 | 5 | push @{ $self->_localizers }, $localizer; | |||||||||||||||||||||||||||||||||||||||||
| 300 | } | ||||||||||||||||||||||||||||||||||||||||||
| 301 | |||||||||||||||||||||||||||||||||||||||||||
| 302 | 0 | ▶ | sub find_localizers { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
find_localizers: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 303 | 0 | my ($self, %args) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 304 | |||||||||||||||||||||||||||||||||||||||||||
| 305 | 0 | ▶ | if (my $isa = $args{isa}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 306 | 0 | ▶ | return $self->grep_localizers(sub { $_[0]->isa($isa) }); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 307 | } | ||||||||||||||||||||||||||||||||||||||||||
| 308 | } | ||||||||||||||||||||||||||||||||||||||||||
| 309 | |||||||||||||||||||||||||||||||||||||||||||
| 310 | 14 | ▶ | sub add_localizer_map { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
add_localizer_map: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 311 | 14 | my ($self, $lang, $localizer) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 312 | |||||||||||||||||||||||||||||||||||||||||||
| 313 | 14 | if (DEBUG) { | |||||||||||||||||||||||||||||||||||||||||
| 314 | debugf("add_localizer_map %s -> %s", $lang, $localizer); | ||||||||||||||||||||||||||||||||||||||||||
| 315 | } | ||||||||||||||||||||||||||||||||||||||||||
| 316 | 14 | my $list = $self->get_localizer_from_lang($lang); | |||||||||||||||||||||||||||||||||||||||||
| 317 | 14 | ▶ | if (! $list) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 318 | 14 | $list = []; | |||||||||||||||||||||||||||||||||||||||||
| 319 | 14 | $self->set_localizer_map($lang, $list); | |||||||||||||||||||||||||||||||||||||||||
| 320 | } | ||||||||||||||||||||||||||||||||||||||||||
| 321 | 14 | unshift @$list, $localizer; | |||||||||||||||||||||||||||||||||||||||||
| 322 | } | ||||||||||||||||||||||||||||||||||||||||||
| 323 | |||||||||||||||||||||||||||||||||||||||||||
| 324 | 6 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 325 | |||||||||||||||||||||||||||||||||||||||||||
| 326 | __END__ | ||||||||||||||||||||||||||||||||||||||||||