| 1 | package Plack::I18N::Lexicon::Maketext; | ||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||
| 3 | 3 | ▶ | use strict; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 4 | 3 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||
| 6 | 3 | ▶ | use Carp qw(croak); | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 7 | 3 | ▶ | use List::Util qw(first); | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 8 | 3 | ▶ | use Locale::Maketext; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 9 | 3 | ▶ | use Plack::I18N::Util qw(try_load_class); | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 10 | 3 | ▶ | use Plack::I18N::Handle; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||
| 12 | 24 | ▶ | sub new { | ||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 13 | 24 | my $class = shift; | |||||||||||||||||||||||||||||||||
| 14 | 24 | my (%params) = @_; | |||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||
| 16 | 24 | my $self = {}; | |||||||||||||||||||||||||||||||||
| 17 | 24 | bless $self, $class; | |||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||
| 19 | 24 | ▶ | $self->{i18n_class} = $params{i18n_class} || croak 'i18n_class required'; | ||||||||||||||||||||||||||||||||
|
Condition100%2/2
$params{'i18n_class'} || croak('i18n_class required')
MC/DC100%1/1
$params{'i18n_class'} || croak('i18n_class required')
$params{'i18n_class'}
Truth table100%2/2
A
A= $params{'i18n_class'}
| |||||||||||||||||||||||||||||||||||
| 20 | 23 | $self->{locale_dir} = $params{locale_dir}; | |||||||||||||||||||||||||||||||||
| 21 | 23 | ▶ | $self->{default_language} = $params{default_language} || 'en'; | ||||||||||||||||||||||||||||||||
|
Condition100%2/2
$params{'default_language'} || 'en'
MC/DC100%1/1
$params{'default_language'} || 'en'
$params{'default_language'}
Truth table100%2/2
A
A= $params{'default_language'}
| |||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||
| 23 | 23 | $self->_init_lexicon; | |||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||
| 25 | 23 | return $self; | |||||||||||||||||||||||||||||||||
| 26 | } | ||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||
| 28 | 23 | ▶ | sub _init_lexicon { | ||||||||||||||||||||||||||||||||
|
Subroutine
_init_lexicon: called CC=5 SCAR=16.4
| |||||||||||||||||||||||||||||||||||
| 29 | 23 | my $self = shift; | |||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||
| 31 | 23 | my $i18n_class = $self->{i18n_class}; | |||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||||
| 33 | 23 | ▶ | if (!try_load_class($i18n_class)) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 34 | 0 | ▶ | eval <<"EOC" or croak $@; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.2
Subroutine
_loaded: not called CC=1 SCAR=0.2
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 35 | package $i18n_class; | ||||||||||||||||||||||||||||||||||
| 36 | use parent 'Locale::Maketext'; | ||||||||||||||||||||||||||||||||||
| 37 | sub _loaded {1} | ||||||||||||||||||||||||||||||||||
| 38 | 1; | ||||||||||||||||||||||||||||||||||
| 39 | EOC | ||||||||||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||
| 42 | 23 | my $default_i18n_class = "$i18n_class\::$self->{default_language}"; | |||||||||||||||||||||||||||||||||
| 43 | 23 | ▶ | if (!try_load_class($default_i18n_class)) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 44 | 0 | ▶ | eval <<"EOC" or croak $@; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.2
Subroutine
_loaded: not called CC=1 SCAR=0.2
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 45 | package $default_i18n_class; | ||||||||||||||||||||||||||||||||||
| 46 | use parent -norequire, '$i18n_class'; | ||||||||||||||||||||||||||||||||||
| 47 | our %Lexicon = (_AUTO => 1); | ||||||||||||||||||||||||||||||||||
| 48 | sub _loaded {1} | ||||||||||||||||||||||||||||||||||
| 49 | 1; | ||||||||||||||||||||||||||||||||||
| 50 | EOC | ||||||||||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||
| 54 | 21 | ▶ | sub detect_languages { | ||||||||||||||||||||||||||||||||
|
Subroutine
detect_languages: called CC=7 SCAR=20.5
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 55 | 21 | my $self = shift; | |||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||
| 57 | my $path = $self->{locale_dir} || $INC{$self->{i18n_class}} || join '/', | ||||||||||||||||||||||||||||||||||
| 58 | 21 | ▶ | 'lib', split /::/, $self->{i18n_class}; | ||||||||||||||||||||||||||||||||
|
Condition33%2/6
$self->{'locale_dir'} || $INC{$self->{'i18n_class'}} || join('/', 'lib', split(/::/, $self->{'i18n_class'}, 0))
$self->{"locale_dir"} or $INC{$self->{"i18n_class"}}
MC/DC0%0/3
$self->{'locale_dir'} || $INC{$self->{'i18n_class'}} || join('/', 'lib', split(/::/, $self->{'i18n_class'}, 0))
$self->{"locale_dir"}
$INC{$self->{"i18n_class"}}
join('/', 'lib', split(/::/, $self->{'i18n_class'}, 0))
Truth table25%1/4
A or B || C
A= $self->{"locale_dir"}B= $INC{$self->{"i18n_class"}}C= join('/', 'lib', split(/::/, $self->{'i18n_class'}, 0))
| |||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||
| 60 | 21 | ▶ | opendir(my $dh, $path) or croak "Can't opendir $path: $!"; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 61 | 21 | ▶ | my @files = grep { /\.p[om]$/ && -e "$path/$_" } sort readdir($dh); | ||||||||||||||||||||||||||||||||
|
Condition66%2/3
/\.p[om]$/ && -e "$path/$_"
MC/DC50%1/2
/\.p[om]$/ && -e "$path/$_"
/\.p[om]$/
-e "$path/$_"
Truth table66%2/3
A && B
A= /\.p[om]$/B= -e "$path/$_"
| |||||||||||||||||||||||||||||||||||
| 62 | 21 | closedir $dh; | |||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||||
| 64 | 21 | my @languages = @files; | |||||||||||||||||||||||||||||||||
| 65 | 21 | s{\.pm$}{} for @languages; | |||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||
| 67 | unshift @languages, $self->{default_language} | ||||||||||||||||||||||||||||||||||
| 68 | 21 | ▶ | unless first { $_ eq $self->{default_language} } @languages; | ||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||||
| 70 | 21 | return @languages; | |||||||||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||||
| 73 | 3 | 1; | |||||||||||||||||||||||||||||||||
| 74 | __END__ | ||||||||||||||||||||||||||||||||||