Localize/Format/Gettext.pm

filter: Statementstmt 96.6% 29 / 30 Branchbran 81.2% 13 / 16 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 4 / 4 Podpod 100% 1 / 1 totaltotal 92.1% 47 / 51 CC 10 SCAR 16.5
CC
10
Cov
91%
_call_function_or_method
7.1
format
4.0
BEGIN
1.0
CRAP 5.2
« Localize/Format/Maketext.pm ↑ Summary Localize/Trait/WithStorage.pm »
1 package Data::Localize::Format::Gettext;
2 1 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 1 extends 'Data::Localize::Format';
5  
6 has functions => (
7 is => 'ro',
8 2 ▶ default => sub { {} }
Subroutine __ANON__: called CC=1 SCAR=0.0
9 1 );
10  
11 7 ▶sub format {
Subroutine format: called CC=4 SCAR=13.9
Pod documented
12 7 my ($self, $lang, $value, @args) = @_;
13  
14 7 ▶ if ( index($value, '(') > -1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (index($value, "(") != -1) 4 3 7
15 4 $value =~ s|%(\w+)\(([^\)]+)\)|
16 4 $self->_call_function_or_method( $lang, $1, $2, \@args )
17 |gex;
18 }
19 7 ▶ if (@args) {
Branch: 1 branch
BranchTrueFalseTotal
if (@args) 6 1 7
20 6 ▶ $value =~ s/%(\d+)/ defined $args[$1 - 1] ? $args[$1 - 1] : '' /ge;
Branch: 1 branch
BranchTrueFalseTotal
defined $args[$1 - 1] ? : 3 0 3
21 }
22  
23 7 return $value;
24 }
25  
26 4 ▶sub _call_function_or_method {
Subroutine _call_function_or_method: called CC=7 SCAR=19.6
27 4 my ($self, $lang, $method, $embedded, $args) = @_;
28  
29 4 my $code;
30 my $is_method;
31 4 ▶ if ( $code = $self->functions->{$method} ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($code = $self->functions->{$method}) { } 1 3 4
elsif ($code = $self->can($method)) { } 3 0 3
32 1 $is_method = 0;
33 } elsif ( $code = $self->can($method) ) {
34 3 $is_method = 1;
35 }
36 4 ▶ if (! $code) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($code) 0 4 4
37 0 Carp::confess(Scalar::Util::blessed($self) . " does not implement method '$method'");
38 }
39  
40 4 my @embedded_args = split /,/, $embedded;
41 4 for (@embedded_args) {
42 9 ▶ if ( $_ =~ /%(\d+)/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_ =~ /%(\d+)/) 6 3 9
43 6 $_ = $args->[ $1 - 1 ];
44 }
45 }
46  
47 4 my @args = ( $lang, \@embedded_args );
48 4 ▶ if ($is_method) {
Branch: 1 branch
BranchTrueFalseTotal
if ($is_method) 3 1 4
49 3 unshift @args, $self;
50 }
51 4 return $code->(@args);
52 }
53  
54 1 1;
55  
56 __END__
« Localize/Format/Maketext.pm ↑ Summary Localize/Trait/WithStorage.pm »