| 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
| |||||||||||||||
| 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
| |||||||||||||||
| 20 | 6 | ▶ | $value =~ s/%(\d+)/ defined $args[$1 - 1] ? $args[$1 - 1] : '' /ge; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 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
| |||||||||||||||
| 32 | 1 | $is_method = 0; | |||||||||||||
| 33 | } elsif ( $code = $self->can($method) ) { | ||||||||||||||
| 34 | 3 | $is_method = 1; | |||||||||||||
| 35 | } | ||||||||||||||
| 36 | 4 | ▶ | if (! $code) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 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
| |||||||||||||||
| 43 | 6 | $_ = $args->[ $1 - 1 ]; | |||||||||||||
| 44 | } | ||||||||||||||
| 45 | } | ||||||||||||||
| 46 | |||||||||||||||
| 47 | 4 | my @args = ( $lang, \@embedded_args ); | |||||||||||||
| 48 | 4 | ▶ | if ($is_method) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 49 | 3 | unshift @args, $self; | |||||||||||||
| 50 | } | ||||||||||||||
| 51 | 4 | return $code->(@args); | |||||||||||||
| 52 | } | ||||||||||||||
| 53 | |||||||||||||||
| 54 | 1 | 1; | |||||||||||||
| 55 | |||||||||||||||
| 56 | __END__ | ||||||||||||||