| 1 | package Plack::I18N::Lexicon::Gettext; | ||||||||||||||||||||
| 2 | |||||||||||||||||||||
| 3 | 1 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 4 | 1 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 5 | |||||||||||||||||||||
| 6 | 1 | ▶ | use Carp qw(croak); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 7 | 1 | ▶ | use List::Util qw(first); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 8 | 1 | ▶ | use Locale::Maketext; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 9 | 1 | ▶ | use Plack::I18N::Util qw(try_load_class); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 10 | 1 | ▶ | use Plack::I18N::Handle; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 11 | |||||||||||||||||||||
| 12 | 4 | ▶ | sub new { | ||||||||||||||||||
|
Subroutine
new: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||
| 13 | 4 | my $class = shift; | |||||||||||||||||||
| 14 | 4 | my (%params) = @_; | |||||||||||||||||||
| 15 | |||||||||||||||||||||
| 16 | 4 | my $self = {}; | |||||||||||||||||||
| 17 | 4 | bless $self, $class; | |||||||||||||||||||
| 18 | |||||||||||||||||||||
| 19 | 4 | ▶ | $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 | 3 | ▶ | $self->{default_language} = $params{default_language} || 'en'; | ||||||||||||||||||
|
Condition50%1/2
$params{'default_language'} || 'en'
MC/DC0%0/1
$params{'default_language'} || 'en'
$params{'default_language'}
Truth table50%1/2
A
A= $params{'default_language'}
| |||||||||||||||||||||
| 21 | |||||||||||||||||||||
| 22 | 3 | ▶ | $self->{locale_dir} = $params{locale_dir} || croak 'locale_dir required'; | ||||||||||||||||||
|
Condition100%2/2
$params{'locale_dir'} || croak('locale_dir required')
MC/DC100%1/1
$params{'locale_dir'} || croak('locale_dir required')
$params{'locale_dir'}
Truth table100%2/2
A
A= $params{'locale_dir'}
| |||||||||||||||||||||
| 23 | |||||||||||||||||||||
| 24 | 2 | $self->_init_lexicon; | |||||||||||||||||||
| 25 | |||||||||||||||||||||
| 26 | 2 | return $self; | |||||||||||||||||||
| 27 | } | ||||||||||||||||||||
| 28 | |||||||||||||||||||||
| 29 | 2 | ▶ | sub _init_lexicon { | ||||||||||||||||||
|
Subroutine
_init_lexicon: called CC=3 SCAR=11.0
| |||||||||||||||||||||
| 30 | 2 | my $self = shift; | |||||||||||||||||||
| 31 | |||||||||||||||||||||
| 32 | 2 | my $i18n_class = $self->{i18n_class}; | |||||||||||||||||||
| 33 | |||||||||||||||||||||
| 34 | 2 | ▶ | if (!try_load_class($i18n_class)) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 35 | 1 | ▶ | eval <<"EOC" || croak $@; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Branch: 1 branch
| |||||||||||||||||||||
| 36 | package $i18n_class; | ||||||||||||||||||||
| 37 | use parent 'Locale::Maketext'; | ||||||||||||||||||||
| 38 | use Locale::Maketext::Lexicon { | ||||||||||||||||||||
| 39 | '*' => [Gettext => "$self->{locale_dir}/*.po"], | ||||||||||||||||||||
| 40 | _auto => 1, | ||||||||||||||||||||
| 41 | _decode => 1, | ||||||||||||||||||||
| 42 | _preload => 1 | ||||||||||||||||||||
| 43 | }; | ||||||||||||||||||||
| 44 | 1; | ||||||||||||||||||||
| 45 | EOC | ||||||||||||||||||||
| 46 | } | ||||||||||||||||||||
| 47 | } | ||||||||||||||||||||
| 48 | |||||||||||||||||||||
| 49 | 1 | ▶ | sub detect_languages { | ||||||||||||||||||
|
Subroutine
detect_languages: called CC=5 SCAR=16.3
Pod
documented
| |||||||||||||||||||||
| 50 | 1 | my $self = shift; | |||||||||||||||||||
| 51 | |||||||||||||||||||||
| 52 | 1 | my $path = $self->{locale_dir}; | |||||||||||||||||||
| 53 | |||||||||||||||||||||
| 54 | 1 | ▶ | opendir(my $dh, $path) or croak "Can't opendir $path: $!"; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 55 | 1 | ▶ | 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/$_"
| |||||||||||||||||||||
| 56 | 1 | closedir $dh; | |||||||||||||||||||
| 57 | |||||||||||||||||||||
| 58 | 1 | my @languages = @files; | |||||||||||||||||||
| 59 | 1 | s{\.p[om]$}{} for @languages; | |||||||||||||||||||
| 60 | |||||||||||||||||||||
| 61 | unshift @languages, $self->{default_language} | ||||||||||||||||||||
| 62 | 1 | ▶ | unless first { $_ eq $self->{default_language} } @languages; | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.2
Branch: 1 branch
| |||||||||||||||||||||
| 63 | |||||||||||||||||||||
| 64 | 1 | return @languages; | |||||||||||||||||||
| 65 | } | ||||||||||||||||||||
| 66 | |||||||||||||||||||||
| 67 | 1 | 1; | |||||||||||||||||||
| 68 | __END__ | ||||||||||||||||||||