line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Locale::TextDomain::OO::Plugin::Expand::Gettext::Named; ## no critic (TidyCode)
|
2
|
|
|
|
|
|
|
|
3
|
5
|
|
|
5
|
|
6962
|
use strict;
|
|
5
|
|
|
|
|
13
|
|
|
5
|
|
|
|
|
141
|
|
4
|
5
|
|
|
5
|
|
39
|
use warnings;
|
|
5
|
|
|
|
|
10
|
|
|
5
|
|
|
|
|
146
|
|
5
|
5
|
|
|
5
|
|
24
|
use Carp qw(cluck confess);
|
|
5
|
|
|
|
|
31
|
|
|
5
|
|
|
|
|
326
|
|
6
|
5
|
|
|
5
|
|
2348
|
use Hash::Util qw(lock_keys);
|
|
5
|
|
|
|
|
12502
|
|
|
5
|
|
|
|
|
27
|
|
7
|
5
|
|
|
5
|
|
2107
|
use Locale::Utils::PlaceholderNamed;
|
|
5
|
|
|
|
|
20505
|
|
|
5
|
|
|
|
|
127
|
|
8
|
5
|
|
|
5
|
|
44
|
use Moo::Role;
|
|
5
|
|
|
|
|
11
|
|
|
5
|
|
|
|
|
25
|
|
9
|
5
|
|
|
5
|
|
1671
|
use Try::Tiny;
|
|
5
|
|
|
|
|
13
|
|
|
5
|
|
|
|
|
3647
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
our $VERSION = '1.027';
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
requires qw(
|
14
|
|
|
|
|
|
|
translate
|
15
|
|
|
|
|
|
|
filter
|
16
|
|
|
|
|
|
|
run_filter
|
17
|
|
|
|
|
|
|
category
|
18
|
|
|
|
|
|
|
domain
|
19
|
|
|
|
|
|
|
);
|
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
has _shadow_domains_named => (
|
22
|
|
|
|
|
|
|
is => 'rw',
|
23
|
|
|
|
|
|
|
default => sub { [] },
|
24
|
|
|
|
|
|
|
);
|
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
has _shadow_categories_named => (
|
27
|
|
|
|
|
|
|
is => 'rw',
|
28
|
|
|
|
|
|
|
default => sub { [] },
|
29
|
|
|
|
|
|
|
);
|
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
has expand_gettext_named => (
|
32
|
|
|
|
|
|
|
is => 'rw',
|
33
|
|
|
|
|
|
|
default => sub {
|
34
|
|
|
|
|
|
|
return Locale::Utils::PlaceholderNamed->new;
|
35
|
|
|
|
|
|
|
},
|
36
|
|
|
|
|
|
|
);
|
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
my $begin_d = sub {
|
39
|
|
|
|
|
|
|
my ($self, $domain) = @_;
|
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
defined $domain
|
42
|
|
|
|
|
|
|
or confess 'Domain is not defined';
|
43
|
|
|
|
|
|
|
push
|
44
|
|
|
|
|
|
|
@{ $self->_shadow_domains_named },
|
45
|
|
|
|
|
|
|
$self->domain;
|
46
|
|
|
|
|
|
|
$self->domain($domain);
|
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
return $self;
|
49
|
|
|
|
|
|
|
};
|
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
my $begin_c = sub {
|
52
|
|
|
|
|
|
|
my ($self, $category) = @_;
|
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
defined $category
|
55
|
|
|
|
|
|
|
or confess 'Category is not defined';
|
56
|
|
|
|
|
|
|
push
|
57
|
|
|
|
|
|
|
@{ $self->_shadow_categories_named },
|
58
|
|
|
|
|
|
|
$self->category;
|
59
|
|
|
|
|
|
|
$self->category($category);
|
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
return $self;
|
62
|
|
|
|
|
|
|
};
|
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
my $end_d = sub {
|
65
|
|
|
|
|
|
|
my $self = shift;
|
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
if ( ! @{ $self->_shadow_domains_named } ) {
|
68
|
|
|
|
|
|
|
cluck 'Tried to get the domain from stack but no domain is not stored';
|
69
|
|
|
|
|
|
|
return $self;
|
70
|
|
|
|
|
|
|
}
|
71
|
|
|
|
|
|
|
$self->domain( pop @{ $self->_shadow_domains_named } );
|
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
return $self;
|
74
|
|
|
|
|
|
|
};
|
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
my $end_c = sub {
|
77
|
|
|
|
|
|
|
my $self = shift;
|
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
if ( ! @{ $self->_shadow_categories_named } ) {
|
80
|
|
|
|
|
|
|
cluck 'Tried to get the category from stack but no category is stored',
|
81
|
|
|
|
|
|
|
return $self;
|
82
|
|
|
|
|
|
|
}
|
83
|
|
|
|
|
|
|
$self->category( pop @{ $self->_shadow_categories_named } );
|
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
return $self;
|
86
|
|
|
|
|
|
|
};
|
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
sub locn {
|
89
|
21
|
|
|
21
|
1
|
6722
|
my ($self, @args) = @_;
|
90
|
|
|
|
|
|
|
|
91
|
21
|
100
|
|
|
|
112
|
my $arg_ref = ref $args[0] eq 'HASH' ? $args[0] : { @args };
|
92
|
|
|
|
|
|
|
try {
|
93
|
21
|
|
|
21
|
|
954
|
lock_keys( %{$arg_ref}, qw( category domain context text plural replace ) );
|
|
21
|
|
|
|
|
87
|
|
94
|
|
|
|
|
|
|
exists $arg_ref->{plural}
|
95
|
21
|
100
|
|
|
|
1282
|
or return;
|
96
|
8
|
|
|
|
|
15
|
lock_keys( %{ $arg_ref->{plural} }, qw( singular plural count ) );
|
|
8
|
|
|
|
|
23
|
|
97
|
|
|
|
|
|
|
}
|
98
|
|
|
|
|
|
|
catch {
|
99
|
0
|
|
|
0
|
|
0
|
confess $_;
|
100
|
21
|
|
|
|
|
140
|
};
|
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
$arg_ref->{domain}
|
103
|
21
|
100
|
|
|
|
652
|
and $self->$begin_d( $arg_ref->{domain} );
|
104
|
|
|
|
|
|
|
$arg_ref->{category}
|
105
|
21
|
100
|
|
|
|
61
|
and $self->$begin_c( $arg_ref->{category} );
|
106
|
|
|
|
|
|
|
my $translation
|
107
|
|
|
|
|
|
|
= exists $arg_ref->{text}
|
108
|
|
|
|
|
|
|
? $self->translate(
|
109
|
13
|
|
|
|
|
53
|
@{$arg_ref}{ qw( context text ) },
|
110
|
|
|
|
|
|
|
)
|
111
|
|
|
|
|
|
|
: exists $arg_ref->{plural}
|
112
|
|
|
|
|
|
|
? $self->translate(
|
113
|
|
|
|
|
|
|
$arg_ref->{context},
|
114
|
21
|
50
|
|
|
|
70
|
@{ $arg_ref->{plural} }{ qw( singular plural count ) },
|
|
8
|
100
|
|
|
|
31
|
|
115
|
|
|
|
|
|
|
1,
|
116
|
|
|
|
|
|
|
)
|
117
|
|
|
|
|
|
|
: q{};
|
118
|
|
|
|
|
|
|
$arg_ref->{replace}
|
119
|
|
|
|
|
|
|
and $translation = $self->expand_gettext_named->expand_named(
|
120
|
|
|
|
|
|
|
$translation,
|
121
|
|
|
|
|
|
|
$arg_ref->{replace},
|
122
|
21
|
100
|
|
|
|
84
|
);
|
123
|
21
|
50
|
|
|
|
882
|
$self->filter
|
124
|
|
|
|
|
|
|
and $self->run_filter(\$translation);
|
125
|
21
|
50
|
66
|
|
|
183
|
if ( exists $arg_ref->{text} || exists $arg_ref->{plural} ) {
|
126
|
|
|
|
|
|
|
$arg_ref->{domain}
|
127
|
21
|
100
|
|
|
|
67
|
and $self->$end_d;
|
128
|
|
|
|
|
|
|
$arg_ref->{category}
|
129
|
21
|
100
|
|
|
|
56
|
and $self->$end_c;
|
130
|
|
|
|
|
|
|
}
|
131
|
|
|
|
|
|
|
|
132
|
21
|
|
|
|
|
147
|
return $translation;
|
133
|
|
|
|
|
|
|
}
|
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
sub Nlocn { ## no critic (Capitalization)
|
136
|
0
|
|
|
0
|
1
|
|
my (undef, @args) = @_;
|
137
|
|
|
|
|
|
|
|
138
|
0
|
0
|
|
|
|
|
my $arg_ref = ref $args[0] eq 'HASH' ? $args[0] : { @args };
|
139
|
|
|
|
|
|
|
|
140
|
0
|
0
|
|
|
|
|
return wantarray ? @args : $args[0];
|
141
|
|
|
|
|
|
|
}
|
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
1;
|
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
__END__
|