Localizer/Resource.pm

filter: Statementstmt 94.6% 53 / 56 Branchbran 72.2% 13 / 18 Conditioncond 60.0% 3 / 5 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 100% 11 / 11 Podpod 100% 2 / 2 totaltotal 86.3% 82 / 95 CC 13 SCAR 14.9
CC
13
Cov
87%
new
8.5
maketext
4.2
_compile
3.0
CRAP 4.4
« Localizer/BuiltinFunctions.pm ↑ Summary Localizer/Lexicon.pm »
1 package Localizer::Resource;
2 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 5 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 5 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 5 ▶use 5.010_001;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 5 ▶use Localizer::Style::Gettext;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 5 ▶use Localizer::BuiltinFunctions;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 5 ▶use Localizer::Lexicon;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 5 our $BUILTIN_FUNCTIONS = {
12 numf => \&Localizer::BuiltinFunctions::numf,
13 numerate => \&Localizer::BuiltinFunctions::numerate,
14 quant => \&Localizer::BuiltinFunctions::quant,
15 sprintf => \&Localizer::BuiltinFunctions::sprintf,
16 };
17  
18 5 ▶use Class::Accessor::Lite 0.05 (
Subroutine BEGIN: called CC=1 SCAR=0.0
19 5 rw => [qw(dictionary compiled precompile style functions)],
20 5 );
21  
22 6 ▶sub new {
Subroutine new: called CC=8 SCAR=21.4
Pod documented
23 6 my $class = shift;
24 0 ▶ my %args = @_==1 ? %{$_[0]} : @_;
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 ? : 0 6 6
25  
26 6 ▶ unless (exists $args{dictionary}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $args{"dictionary"}) 0 6 6
27 0 Carp::confess("Missing mandatory parameter: dictionary");
28 }
29  
30 $args{dictionary} = Localizer::Lexicon->new($args{dictionary})
31 6 ▶ if ref($args{dictionary}) eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
if ref $args{"dictionary"} eq "HASH" 6 0 6
32  
33 6 ▶ $args{style} ||= Localizer::Style::Gettext->new();
Condition66%2/3
$args{"style"} ||= "Localizer::Style::Gettext"->new
l!l&&r!l&&!r
240
MC/DC0%0/2
$args{"style"} ||= "Localizer::Style::Gettext"->new
$args{"style"} "Localizer::Style::Gettext"->new
Truth table66%2/3
A ||= B
A= $args{"style"}B= "Localizer::Style::Gettext"->new
ABresult
1X1
011
000
34  
35 6 my $functions = do {
36 6 ▶ if (exists $args{functions}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $args{'functions'}) { } 2 4 6
37 +{
38 %$BUILTIN_FUNCTIONS,
39 2 %{delete $args{functions}},
40 };
41 } else {
42 4 $BUILTIN_FUNCTIONS
43 }
44 };
45  
46 6 my $self = bless {
47 compiled => +{},
48 precompile => 1,
49 functions => $functions,
50 %args,
51 }, $class;
52  
53 # Compile dictionary data to CodeRef or ScalarRef
54 6 ▶ if ($self->precompile) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->precompile) 3 3 6
55 3 for my $msgid ($self->dictionary->msgids) {
56 5 $self->_compile($msgid);
57 }
58 }
59  
60 6 return $self;
61 }
62  
63 30 ▶sub maketext {
Subroutine maketext: called CC=4 SCAR=14.3
Pod documented
64 30 my ($self, $msgid, @args) = @_;
65  
66 30 my $compiled = $self->_compile($msgid);
67 28 ▶ return unless defined $compiled;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $compiled 0 28 28
68  
69 28 ▶ if (ref $compiled eq 'CODE') {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $compiled eq 'CODE') { } 19 9 28
elsif (ref $compiled eq 'SCALAR') { } 9 0 9
70 19 return $compiled->($self, @args);
71 } elsif (ref $compiled eq 'SCALAR') {
72 9 return $$compiled;
73 } else {
74 0 die "SHOULD NOT REACH HERE";
75 }
76 }
77  
78 35 ▶sub _compile {
Subroutine _compile: called CC=3 SCAR=11.0
79 35 my ($self, $msgid) = @_;
80  
81 35 ▶ if (my $code = $self->compiled->{$msgid}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $code = $self->compiled->{$msgid}) 5 30 35
82 5 return $code;
83 }
84  
85 30 ▶ my $fmt = $self->dictionary->msgstr($msgid) || return;
Condition50%1/2
$self->dictionary->msgstr($msgid) || (return)
l!l
300
MC/DC0%0/1
$self->dictionary->msgstr($msgid) || (return)
$self->dictionary->msgstr($msgid)
Truth table50%1/2
A
A= $self->dictionary->msgstr($msgid)
Aresult
11
00
86 30 my $code = $self->style->compile($msgid, $fmt, $self->functions);
87 28 $self->compiled->{$msgid} = $code;
88 28 return $code;
89 }
90  
91 5 1;
92  
93 __END__
« Localizer/BuiltinFunctions.pm ↑ Summary Localizer/Lexicon.pm »