I18N.pm

filter: Statementstmt 100% 52 / 52 Branchbran 50.0% 1 / 2 Conditioncond 77.7% 7 / 9 MC/DCmcdc 40.0% 2 / 5 Subroutinesub 100% 13 / 13 Podpod 100% 4 / 4 totaltotal 92.9% 79 / 85 CC 6 SCAR 8.0
CC
6
Cov
95%
new
5.0
handle
2.0
BEGIN
1.0
CRAP 2.2
« I18N/Lexicon/Gettext.pm ↑ Summary I18N/Handle.pm »
1 package Plack::I18N;
2 3 ▶use 5.008001;
Subroutine BEGIN: called CC=1 SCAR=0.0
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 our $VERSION = "0.04";
7  
8 3 ▶use Carp qw(croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 3 ▶use Locale::Maketext;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 3 ▶use Plack::Util ();
Subroutine BEGIN: called CC=1 SCAR=0.0
11 3 ▶use Plack::I18N::Handle;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 21 ▶sub new {
Subroutine new: called CC=5 SCAR=16.2
Pod documented
14 21 my $class = shift;
15 21 my (%params) = @_;
16  
17 21 ▶ croak 'lexicon required' unless $params{lexicon};
Branch: 1 branch
BranchTrueFalseTotal
unless $params{"lexicon"} 0 21 21
18  
19 21 my $self = {};
20 21 bless $self, $class;
21  
22 21 ▶ $self->{i18n_class} = $params{i18n_class} || __PACKAGE__ . '::Auto';
Condition50%1/2
$params{'i18n_class'} || 'Plack::I18N::Auto'
l!l
210
MC/DC0%0/1
$params{'i18n_class'} || 'Plack::I18N::Auto'
$params{'i18n_class'}
Truth table50%1/2
A
A= $params{'i18n_class'}
Aresult
11
00
23 21 $self->{locale_dir} = $params{locale_dir};
24 21 ▶ $self->{default_language} = $params{default_language} || 'en';
Condition100%2/2
$params{'default_language'} || 'en'
l!l
120
MC/DC100%1/1
$params{'default_language'} || 'en'
$params{'default_language'}
Truth table100%2/2
A
A= $params{'default_language'}
Aresult
11
00
25  
26 $self->{lexicon} = $self->_build_lexicon(
27 $params{lexicon},
28 i18n_class => $self->{i18n_class},
29 locale_dir => $self->{locale_dir},
30 default_language => $self->{default_language}
31 21 );
32  
33 $self->{languages} =
34 21 ▶ $params{languages} || [sort $self->{lexicon}->detect_languages];
Condition100%2/2
$params{'languages'} || [sort($self->{'lexicon'}->detect_languages)]
l!l
120
MC/DC100%1/1
$params{'languages'} || [sort($self->{'lexicon'}->detect_languages)]
$params{'languages'}
Truth table100%2/2
A
A= $params{'languages'}
Aresult
11
00
35  
36 21 return $self;
37 }
38  
39 16 ▶sub default_language {
Subroutine default_language: called CC=1 SCAR=0.0
Pod documented
40 16 my $self = shift;
41  
42 16 return $self->{default_language};
43 }
44  
45 22 ▶sub languages {
Subroutine languages: called CC=1 SCAR=0.0
Pod documented
46 22 my $self = shift;
47  
48 22 return @{$self->{languages}};
49 }
50  
51 17 ▶sub handle {
Subroutine handle: called CC=2 SCAR=6.9
Pod documented
52 17 my $self = shift;
53 17 my ($language) = @_;
54  
55 17 my $i18n_class = $self->{i18n_class};
56  
57 17 ▶ $self->{handles}->{$language} ||= do {
Condition66%2/3
$self->{"handles"}{$language} ||= do { my $handle = $i18n_class->get_handle($language); $handle->fail_with(sub { $_[1]; } ); "Plack::I18N::Handle"->new("handle", $handle, "language", $language) }
l!l&&r!l&&!r
1160
MC/DC0%0/2
$self->{"handles"}{$language} ||= do { my $handle = $i18n_class->get_handle($language); $handle->fail_with(sub { $_[1]; } ); "Plack::I18N::Handle"->new("handle", $handle, "language", $language) }
$self->{"handles"}{$language} do { my $handle = $i18n_class->get_handle($language); $handle->fail_with(sub { $_[1]; } ); "Plack::I18N::Handle"->new("handle", $handle, "language", $language) }
Truth table66%2/3
A ||= B
A= $self->{"handles"}{$language}B= do { my $handle = $i18n_class->get_handle($language); $handle->fail_with(sub { $_[1]; } ); "Plack::I18N::Handle"->new("handle", $handle, "language", $language) }
ABresult
1X1
011
000
58 16 my $handle = $i18n_class->get_handle($language);
59 16 ▶ $handle->fail_with(sub { $_[1] });
Subroutine __ANON__: called CC=1 SCAR=0.0
60  
61 16 Plack::I18N::Handle->new(handle => $handle, language => $language);
62 };
63  
64 17 return $self->{handles}->{$language};
65 }
66  
67 21 ▶sub _build_lexicon {
Subroutine _build_lexicon: called CC=1 SCAR=0.0
68 21 my $self = shift;
69 21 my ($lexicon, %params) = @_;
70  
71 21 my $lexicon_class = __PACKAGE__ . '::Lexicon::' . ucfirst($lexicon);
72  
73 21 Plack::Util::load_class($lexicon_class);
74  
75 21 return $lexicon_class->new(%params);
76 }
77  
78 3 1;
79 __END__
« I18N/Lexicon/Gettext.pm ↑ Summary I18N/Handle.pm »