File Coverage

blib/lib/Locale/TextDomain/OO/Plugin/Expand/Gettext/Loc.pm
Criterion Covered Total %
statement 50 54 92.5
branch 18 26 69.2
condition n/a
subroutine 11 11 100.0
pod 4 4 100.0
total 83 95 87.3


line stmt bran cond sub pod time code
1             package Locale::TextDomain::OO::Plugin::Expand::Gettext::Loc; ## no critic (TidyCode)
2            
3 6     6   9410 use strict;
  6         16  
  6         180  
4 6     6   51 use warnings;
  6         14  
  6         165  
5 6     6   1054 use Locale::Utils::PlaceholderNamed;
  6         11434  
  6         138  
6 6     6   36 use Moo::Role;
  6         13  
  6         40  
7            
8             our $VERSION = '1.027';
9            
10             requires qw(
11             translate
12             filter
13             run_filter
14             );
15            
16             has expand_gettext_loc => (
17             is => 'rw',
18             default => sub {
19             return Locale::Utils::PlaceholderNamed->new;
20             },
21             );
22            
23             sub loc_x {
24 8     8 1 1889 my ($self, $msgid, @args) = @_;
25            
26 8         36 my $translation = $self->translate(undef, $msgid);
27             @args and $translation = $self->expand_gettext_loc->expand_named(
28             $translation,
29 8 50       160 @args == 1 ? %{ $args[0] } : @args,
  0 100       0  
30             );
31 8 50       330 $self->filter
32             and $self->run_filter(\$translation);
33            
34 8         97 return $translation;
35             }
36            
37             sub loc_nx {
38 4     4 1 14 my ($self, $msgid, $msgid_plural, $count, @args) = @_;
39            
40 4         13 my $translation = $self->translate(undef, $msgid, $msgid_plural, $count, 1);
41             @args and $translation = $self->expand_gettext_loc->expand_named(
42             $translation,
43 4 50       23 @args == 1 ? %{ $args[0] } : @args,
  0 100       0  
44             );
45 4 50       216 $self->filter
46             and $self->run_filter(\$translation);
47            
48 4         38 return $translation;
49             }
50            
51             sub loc_px {
52 5     5 1 26 my ($self, $msgctxt, $msgid, @args) = @_;
53            
54 5         23 my $translation = $self->translate($msgctxt, $msgid);
55             @args and $translation = $self->expand_gettext_loc->expand_named(
56             $translation,
57 5 50       27 @args == 1 ? %{ $args[0] } : @args,
  0 100       0  
58             );
59 5 50       175 $self->filter
60             and $self->run_filter(\$translation);
61            
62 5         59 return $translation;
63             }
64            
65             sub loc_npx { ## no critic (ManyArgs)
66 4     4 1 15 my ($self, $msgctxt, $msgid, $msgid_plural, $count, @args) = @_;
67            
68 4         14 my $translation = $self->translate($msgctxt, $msgid, $msgid_plural, $count, 1);
69             @args and $translation = $self->expand_gettext_loc->expand_named(
70             $translation,
71 4 50       21 @args == 1 ? %{ $args[0] } : @args,
  0 100       0  
72             );
73 4 50       249 $self->filter
74             and $self->run_filter(\$translation);
75            
76 4         41 return $translation;
77             }
78            
79             BEGIN {
80 6     6   4546 no warnings qw(redefine); ## no critic (NoWarnings)
  6         15  
  6         986  
81 6     6   42 *loc_ = \&loc_x;
82 6         18 *loc_n = \&loc_nx;
83 6         14 *loc_p = \&loc_px;
84 6         13 *loc_np = \&loc_npx;
85            
86             # Dummy methods for string marking.
87             my $dummy = sub {
88 9     9   1787 my (undef, @more) = @_;
89 9 100       79 return wantarray ? @more : $more[0];
90 6         24 };
91 6         14 *Nloc_ = $dummy;
92 6         13 *Nloc_x = $dummy;
93 6         12 *Nloc_n = $dummy;
94 6         12 *Nloc_nx = $dummy;
95 6         21 *Nloc_p = $dummy;
96 6         14 *Nloc_px = $dummy;
97 6         16 *Nloc_np = $dummy;
98 6         183 *Nloc_npx = $dummy;
99             }
100            
101             1;
102            
103             __END__