| 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
| |||||||||||||||||||||
| 25 | |||||||||||||||||||||
| 26 | 6 | ▶ | unless (exists $args{dictionary}) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 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
| |||||||||||||||||||||
| 32 | |||||||||||||||||||||
| 33 | 6 | ▶ | $args{style} ||= Localizer::Style::Gettext->new(); | ||||||||||||||||||
|
Condition66%2/3
$args{"style"} ||= "Localizer::Style::Gettext"->new
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
| |||||||||||||||||||||
| 34 | |||||||||||||||||||||
| 35 | 6 | my $functions = do { | |||||||||||||||||||
| 36 | 6 | ▶ | if (exists $args{functions}) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 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
| |||||||||||||||||||||
| 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
| |||||||||||||||||||||
| 68 | |||||||||||||||||||||
| 69 | 28 | ▶ | if (ref $compiled eq 'CODE') { | ||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||
| 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
| |||||||||||||||||||||
| 82 | 5 | return $code; | |||||||||||||||||||
| 83 | } | ||||||||||||||||||||
| 84 | |||||||||||||||||||||
| 85 | 30 | ▶ | my $fmt = $self->dictionary->msgstr($msgid) || return; | ||||||||||||||||||
|
Condition50%1/2
$self->dictionary->msgstr($msgid) || (return)
MC/DC0%0/1
$self->dictionary->msgstr($msgid) || (return)
$self->dictionary->msgstr($msgid)
Truth table50%1/2
A
A= $self->dictionary->msgstr($msgid)
| |||||||||||||||||||||
| 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__ | ||||||||||||||||||||