Localize/Localizer.pm

filter: Statementstmt 94.2% 33 / 35 Branchbran 66.6% 4 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 11 / 11 Podpod 66.6% 2 / 3 totaltotal 90.9% 50 / 55 CC 4 SCAR 4.7
CC
4
Cov
90%
localize_for
3.1
register
2.1
BEGIN
1.0
CRAP 1.6
« Localize/Gettext.pm ↑ Summary Localize/Storage.pm »
1 package Data::Localize::Localizer;
2 6 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 6 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 6 ▶use Carp ();
Subroutine BEGIN: called CC=1 SCAR=0.0
5 6 ▶use Data::Localize;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 6 ▶use Encode ();
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 6 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
9 6 if (Data::Localize::DEBUG) {
10 require Data::Localize::Log;
11 Data::Localize::Log->import
12 }
13 }
14  
15 6 has _localizer => (
16 is => 'rw',
17 weak_ref => 1,
18 );
19  
20 6 has initialized => (
21 is => 'rw',
22 default => 0,
23 init_arg => undef,
24 );
25  
26 has formatter => (
27 is => 'rw',
28 lazy => 1,
29 11 ▶ isa => sub { $_[0]->isa('Data::Localize::Format') },
Subroutine __ANON__: called CC=1 SCAR=0.0
30 6 builder => "_build_formatter",
31 required => 1,
32 handles => { format_string => 'format' },
33 );
34  
35 7 ▶sub _build_formatter {
Subroutine _build_formatter: called CC=1 SCAR=0.0
36 7 Module::Load::load('Data::Localize::Format::Maketext');
37 7 return Data::Localize::Format::Maketext->new();
38 }
39  
40 15 ▶sub BUILD {
Subroutine BUILD: called CC=1 SCAR=0.0
Pod undocumented
41 15 $_[0]->initialized(1);
42 }
43  
44 5 ▶sub register {
Subroutine register: called CC=2 SCAR=7.6
Pod documented
45 5 my ($self, $loc) = @_;
46 5 ▶ if ($self->_localizer) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_localizer) 0 5 5
47 0 Carp::confess("Localizer $self is already attached to another Data::Localize object ($loc)");
48 }
49 5 $self->_localizer( $loc );
50 }
51  
52 33 ▶sub localize_for {
Subroutine localize_for: called CC=3 SCAR=11.2
Pod documented
53 33 my ($self, %args) = @_;
54 33 my ($lang, $id, $args) = @args{ qw(lang id args) };
55  
56 33 ▶ my $value = $self->get_lexicon($lang, $id) or return ();
Branch: 1 branch
BranchTrueFalseTotal
my $value = $self->get_lexicon($lang, $id) or return () 27 6 33
57 27 if (Data::Localize::DEBUG()) {
58 debugf("localize_for - '%s' -> '%s'",
59 $id,
60 defined($value) ? Encode::encode_utf8($value) : '(null)'
61 );
62 }
63 27 ▶ if ( $value ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($value) 27 0 27
64 27 return $self->format_string($lang, $value, @$args);
65 }
66 0 return ();
67 }
68  
69 6 1;
70  
71 __END__
« Localize/Gettext.pm ↑ Summary Localize/Storage.pm »