line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Data::Localize::Format::Gettext; |
2
|
1
|
|
|
1
|
|
474
|
use Moo; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
5
|
|
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
extends 'Data::Localize::Format'; |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
has functions => ( |
7
|
|
|
|
|
|
|
is => 'ro', |
8
|
|
|
|
|
|
|
default => sub { {} } |
9
|
|
|
|
|
|
|
); |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
sub format { |
12
|
7
|
|
|
7
|
1
|
140
|
my ($self, $lang, $value, @args) = @_; |
13
|
|
|
|
|
|
|
|
14
|
7
|
100
|
|
|
|
28
|
if ( index($value, '(') > -1 ) { |
15
|
4
|
|
|
|
|
21
|
$value =~ s|%(\w+)\(([^\)]+)\)| |
16
|
4
|
|
|
|
|
14
|
$self->_call_function_or_method( $lang, $1, $2, \@args ) |
17
|
|
|
|
|
|
|
|gex; |
18
|
|
|
|
|
|
|
} |
19
|
7
|
100
|
|
|
|
61
|
if (@args) { |
20
|
6
|
50
|
|
|
|
29
|
$value =~ s/%(\d+)/ defined $args[$1 - 1] ? $args[$1 - 1] : '' /ge; |
|
3
|
|
|
|
|
18
|
|
21
|
|
|
|
|
|
|
} |
22
|
|
|
|
|
|
|
|
23
|
7
|
|
|
|
|
34
|
return $value; |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub _call_function_or_method { |
27
|
4
|
|
|
4
|
|
8
|
my ($self, $lang, $method, $embedded, $args) = @_; |
28
|
|
|
|
|
|
|
|
29
|
4
|
|
|
|
|
3
|
my $code; |
30
|
|
|
|
|
|
|
my $is_method; |
31
|
4
|
100
|
|
|
|
32
|
if ( $code = $self->functions->{$method} ) { |
|
|
50
|
|
|
|
|
|
32
|
1
|
|
|
|
|
2
|
$is_method = 0; |
33
|
|
|
|
|
|
|
} elsif ( $code = $self->can($method) ) { |
34
|
3
|
|
|
|
|
4
|
$is_method = 1; |
35
|
|
|
|
|
|
|
} |
36
|
4
|
50
|
|
|
|
9
|
if (! $code) { |
37
|
0
|
|
|
|
|
0
|
Carp::confess(Scalar::Util::blessed($self) . " does not implement method '$method'"); |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
4
|
|
|
|
|
14
|
my @embedded_args = split /,/, $embedded; |
41
|
4
|
|
|
|
|
7
|
for (@embedded_args) { |
42
|
9
|
100
|
|
|
|
25
|
if ( $_ =~ /%(\d+)/ ) { |
43
|
6
|
|
|
|
|
18
|
$_ = $args->[ $1 - 1 ]; |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
4
|
|
|
|
|
5
|
my @args = ( $lang, \@embedded_args ); |
48
|
4
|
100
|
|
|
|
9
|
if ($is_method) { |
49
|
3
|
|
|
|
|
4
|
unshift @args, $self; |
50
|
|
|
|
|
|
|
} |
51
|
4
|
|
|
|
|
10
|
return $code->(@args); |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
1; |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
__END__ |