line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Locale::TextDomain::OO::Lexicon::Role::StoreFilter; ## no critic (TidyCode)
|
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
1142
|
use strict;
|
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
65
|
|
4
|
2
|
|
|
2
|
|
10
|
use warnings;
|
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
57
|
|
5
|
2
|
|
|
2
|
|
11
|
use Carp qw(confess);
|
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
90
|
|
6
|
2
|
|
|
2
|
|
890
|
use Clone qw(clone);
|
|
2
|
|
|
|
|
5211
|
|
|
2
|
|
|
|
|
118
|
|
7
|
2
|
|
|
2
|
|
19
|
use Locale::TextDomain::OO::Singleton::Lexicon;
|
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
48
|
|
8
|
2
|
|
|
2
|
|
11
|
use Locale::TextDomain::OO::Util::JoinSplitLexiconKeys;
|
|
2
|
|
|
|
|
7
|
|
|
2
|
|
|
|
|
39
|
|
9
|
2
|
|
|
2
|
|
11
|
use Moo::Role;
|
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
12
|
|
10
|
2
|
|
|
2
|
|
697
|
use MooX::Types::MooseLike::Base qw(HashRef);
|
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
116
|
|
11
|
2
|
|
|
2
|
|
14
|
use namespace::autoclean;
|
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
12
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
our $VERSION = '1.017';
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
for my $name ( qw( language category domain project ) ) {
|
16
|
|
|
|
|
|
|
has "filter_$name" => (
|
17
|
|
|
|
|
|
|
is => 'rw',
|
18
|
|
|
|
|
|
|
isa => sub {
|
19
|
|
|
|
|
|
|
my $value = shift;
|
20
|
|
|
|
|
|
|
defined $value
|
21
|
|
|
|
|
|
|
or return;
|
22
|
|
|
|
|
|
|
my $ref = ref $value;
|
23
|
|
|
|
|
|
|
$ref eq 'Regexp'
|
24
|
|
|
|
|
|
|
and return;
|
25
|
|
|
|
|
|
|
$ref eq 'CODE'
|
26
|
|
|
|
|
|
|
and return;
|
27
|
|
|
|
|
|
|
$ref
|
28
|
|
|
|
|
|
|
and confess 'Undef, Str, RegexpRef or CodeRef expected';
|
29
|
|
|
|
|
|
|
},
|
30
|
|
|
|
|
|
|
);
|
31
|
|
|
|
|
|
|
}
|
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub clear_filter {
|
34
|
3
|
|
|
3
|
1
|
12
|
my $self = shift;
|
35
|
|
|
|
|
|
|
|
36
|
3
|
|
|
|
|
51
|
$self->filter_language(undef);
|
37
|
3
|
|
|
|
|
63
|
$self->filter_category(undef);
|
38
|
3
|
|
|
|
|
64
|
$self->filter_domain(undef);
|
39
|
3
|
|
|
|
|
63
|
$self->filter_project(undef);
|
40
|
|
|
|
|
|
|
|
41
|
3
|
|
|
|
|
22
|
return $self;
|
42
|
|
|
|
|
|
|
};
|
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
has data => (
|
45
|
|
|
|
|
|
|
is => 'ro',
|
46
|
|
|
|
|
|
|
isa => HashRef,
|
47
|
|
|
|
|
|
|
lazy => 1,
|
48
|
|
|
|
|
|
|
default => sub { {} },
|
49
|
|
|
|
|
|
|
);
|
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
my $is_expected_lexicon_key = sub {
|
52
|
|
|
|
|
|
|
my ( $self, $lexicon_key ) = @_;
|
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
my $key_ref = Locale::TextDomain::OO::Util::JoinSplitLexiconKeys
|
55
|
|
|
|
|
|
|
->instance
|
56
|
|
|
|
|
|
|
->split_lexicon_key($lexicon_key);
|
57
|
|
|
|
|
|
|
NAME:
|
58
|
|
|
|
|
|
|
for my $name ( qw( language category domain project ) ) {
|
59
|
|
|
|
|
|
|
defined $key_ref->{$name}
|
60
|
|
|
|
|
|
|
or $key_ref->{$name} = q{};
|
61
|
|
|
|
|
|
|
my $method = "filter_$name";
|
62
|
|
|
|
|
|
|
my $filter = $self->$method;
|
63
|
|
|
|
|
|
|
if ( defined $filter ) {
|
64
|
|
|
|
|
|
|
local $_ = $key_ref->{$name};
|
65
|
|
|
|
|
|
|
my $ref = ref $filter;
|
66
|
|
|
|
|
|
|
$ref eq 'Regexp'
|
67
|
|
|
|
|
|
|
? $_ =~ $filter
|
68
|
|
|
|
|
|
|
: $ref eq 'CODE'
|
69
|
|
|
|
|
|
|
? $filter->($method)
|
70
|
|
|
|
|
|
|
: $_ eq $filter
|
71
|
|
|
|
|
|
|
or return;
|
72
|
|
|
|
|
|
|
}
|
73
|
|
|
|
|
|
|
}
|
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
return 1;
|
76
|
|
|
|
|
|
|
};
|
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
my $prepare_lexicon = sub {
|
79
|
|
|
|
|
|
|
my ( $self, $lexicon_ref ) = @_;
|
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
$lexicon_ref = clone($lexicon_ref);
|
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
# not able to serialize code references
|
84
|
|
|
|
|
|
|
delete $lexicon_ref->{ q{} }->{plural_code};
|
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
my $key_util = Locale::TextDomain::OO::Util::JoinSplitLexiconKeys->instance;
|
87
|
|
|
|
|
|
|
MESSAGE_KEY:
|
88
|
|
|
|
|
|
|
for my $message_key ( keys %{$lexicon_ref} ) {
|
89
|
|
|
|
|
|
|
length $message_key
|
90
|
|
|
|
|
|
|
or next MESSAGE_KEY;
|
91
|
|
|
|
|
|
|
my $new_message_key = $key_util->join_message_key(
|
92
|
|
|
|
|
|
|
$key_util->split_message_key($message_key),
|
93
|
|
|
|
|
|
|
'JSON',
|
94
|
|
|
|
|
|
|
);
|
95
|
|
|
|
|
|
|
$lexicon_ref->{$new_message_key} = delete $lexicon_ref->{$message_key};
|
96
|
|
|
|
|
|
|
}
|
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
return $lexicon_ref;
|
99
|
|
|
|
|
|
|
};
|
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
sub copy {
|
102
|
29
|
|
|
29
|
1
|
4361
|
my $self = shift;
|
103
|
|
|
|
|
|
|
|
104
|
29
|
|
|
|
|
104
|
my $data = Locale::TextDomain::OO::Singleton::Lexicon->instance->data;
|
105
|
29
|
|
|
|
|
351
|
for my $lexicon_key ( keys %{$data} ) {
|
|
29
|
|
|
|
|
114
|
|
106
|
|
|
|
|
|
|
$self->$is_expected_lexicon_key($lexicon_key)
|
107
|
|
|
|
|
|
|
and $self->data->{$lexicon_key}
|
108
|
319
|
100
|
|
|
|
2079
|
= $self->$prepare_lexicon( $data->{$lexicon_key} );
|
109
|
|
|
|
|
|
|
}
|
110
|
|
|
|
|
|
|
|
111
|
29
|
|
|
|
|
215
|
return $self;
|
112
|
|
|
|
|
|
|
}
|
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
sub remove {
|
115
|
1
|
|
|
1
|
1
|
10
|
my $self = shift;
|
116
|
|
|
|
|
|
|
|
117
|
1
|
|
|
|
|
29
|
my $data = $self->data;
|
118
|
1
|
|
|
|
|
9
|
for my $lexicon_key ( keys %{$data} ) {
|
|
1
|
|
|
|
|
5
|
|
119
|
|
|
|
|
|
|
$self->$is_expected_lexicon_key($lexicon_key)
|
120
|
8
|
100
|
|
|
|
19
|
and delete $data->{$lexicon_key};
|
121
|
|
|
|
|
|
|
}
|
122
|
|
|
|
|
|
|
|
123
|
1
|
|
|
|
|
4
|
return $self;
|
124
|
|
|
|
|
|
|
}
|
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
1;
|
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
__END__
|