Extract/Process.pm

filter: Statementstmt 28.2% 43 / 152 Branchbran 0.0% 0 / 48 Conditioncond 0.0% 0 / 13 MC/DCmcdc 0.0% 0 / 8 Subroutinesub 45.8% 11 / 24 Podpod 100% 7 / 7 totaltotal 24.2% 61 / 252 CC 39 SCAR 44.8
CC
39
Cov
20%
merge_extract
272.0
_plugin
72.0
remove_all_non_referenced
42.0
CRAP 88.2
« Extract/Process/Plugin/PO.pm ↑ Summary Extract/Base/RegexBasedExtractor.pm »
1 package Locale::TextDomain::OO::Extract::Process; ## no critic (TidyCode)
2
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use Carp qw(confess);
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use Clone qw(clone);
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use Class::Load qw(load_class);
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use Locale::TextDomain::OO::Util::JoinSplitLexiconKeys;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use MooX::StrictConstructor;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use MooX::Types::MooseLike::Base qw(HashRef Str);
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 ▶use Set::Scalar;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
14
15 1 our $VERSION = '2.015';
16
17 1 has category => (
18 is => 'rw',
19 isa => Str,
20 lazy => 1,
21 default => q{},
22 );
23
24 1 has domain => (
25 is => 'rw',
26 isa => Str,
27 lazy => 1,
28 default => q{},
29 );
30
31 1 has language => (
32 is => 'rw',
33 isa => Str,
34 lazy => 1,
35 default => 'i-default',
36 );
37
38 has project => (
39 is => 'rw',
40 0 ▶ isa => sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
41 0 my $project = shift;
42 0 ▶ defined $project
Branch: 1 branch
BranchTrueFalseTotal
defined $project or return 0 0 0
43 or return;
44 0 return Str->($project);
45 },
46 1 );
47
48 has lexicon_ref => (
49 is => 'rw',
50 isa => HashRef,
51 lazy => 1,
52 0 ▶ default => sub { {} },
Subroutine __ANON__: not called CC=1 SCAR=6.9
53 1 );
54
55 has plugin_ref => (
56 is => 'rw',
57 isa => HashRef,
58 lazy => 1,
59 0 ▶ default => sub { { po => 'PO' } },
Subroutine __ANON__: not called CC=1 SCAR=6.9
60 1 );
61
62 has _plugin_object_ref => (
63 is => 'ro',
64 init_arg => undef,
65 0 ▶ default => sub { {} },
Subroutine __ANON__: not called CC=1 SCAR=6.9
66 1 );
67
68 0 ▶sub add_plugin {
Subroutine add_plugin: not called CC=3 SCAR=24.8
Pod documented
69 0 my ( $self, $plugin_alias, $plugin ) = @_;
70
71 0 ▶ $plugin_alias
Branch: 1 branch
BranchTrueFalseTotal
$plugin_alias or confess("Plugin alias expected") 0 0 0
72 or confess 'Plugin alias expected';
73 0 ▶ $plugin
Branch: 1 branch
BranchTrueFalseTotal
$plugin or confess("Plugin name expected") 0 0 0
74 or confess 'Plugin name expected';
75 0 delete $self->_plugin_object_ref->{$plugin_alias};
76 0 $self->plugin_ref->{$plugin_alias} = $plugin;
77
78 0 return;
79 }
80
81 0 ▶sub _plugin {
Subroutine _plugin: not called CC=8 SCAR=42.8
82 0 my ( $self, $plugin_alias ) = @_;
83
84 0 ▶ $plugin_alias
Branch: 1 branch
BranchTrueFalseTotal
$plugin_alias or confess("Undef is not a plugin alias") 0 0 0
85 or confess 'Undef is not a plugin alias';
86 0 my $plugin_object_ref = $self->_plugin_object_ref;
87 0 ▶ if ( exists $plugin_object_ref->{$plugin_alias} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $plugin_object_ref->{$plugin_alias}) 0 0 0
88 0 my $object = $plugin_object_ref->{$plugin_alias};
89 0 $object->clear;
90 METHOD:
91 0 for my $method ( qw( category domain language lexicon_ref project ) ) {
92 0 my $value = $self->$method;
93 0 ▶ defined $value
Branch: 1 branch
BranchTrueFalseTotal
defined $value or next METHOD 0 0 0
94 or next METHOD;
95 0 $object->$method($value);
96 }
97 0 return $object;
98 }
99 0 ▶ my $plugin = $self->plugin_ref->{$plugin_alias}
Branch: 1 branch
BranchTrueFalseTotal
my $plugin = $self->plugin_ref->{$plugin_alias} or confess("Unknown plugin alias $plugin_alias") 0 0 0
100 or confess "Unknown plugin alias $plugin_alias";
101 0 ▶ my $class = $plugin =~ s{ \A [+] }{}xms
Branch: 1 branch
BranchTrueFalseTotal
$plugin =~ s/ \A [+] //msx ? : 0 0 0
102 ? $plugin
103 : "Locale::TextDomain::OO::Extract::Process::Plugin::$plugin";
104 my $object = load_class($class)->new(
105 map {
106 0 ▶ defined $self->$_
Branch: 1 branch
BranchTrueFalseTotal
defined $self->$_ ? : 0 0 0
107 ? ( $_ => $self->$_ )
108 : ();
109 }
110 qw( category domain language lexicon_ref project )
111 );
112 0 $plugin_object_ref->{$plugin_alias} = $object;
113
114 0 return $object;
115 }
116
117 0 ▶sub slurp {
Subroutine slurp: not called CC=1 SCAR=6.9
Pod documented
118 0 my ( $self, $plugin_alias, $filename ) = @_;
119
120 0 $self->_plugin($plugin_alias)->slurp($filename);
121
122 0 return;
123 }
124
125 0 ▶sub spew {
Subroutine spew: not called CC=1 SCAR=6.9
Pod documented
126 0 my ( $self, $plugin_alias, $filename ) = @_;
127
128 0 $self->_plugin($plugin_alias)->spew($filename);
129
130 0 return;
131 }
132
133 0 ▶sub remove_all_reference {
Subroutine remove_all_reference: not called CC=3 SCAR=24.8
Pod documented
134 0 my $self = shift;
135
136 0 my $lexicon_ref = $self->lexicon_ref;
137 0 for my $message_ref ( values %{$lexicon_ref} ) {
138 0 for my $value_ref ( values %{$message_ref} ) {
139 0 delete $value_ref->{reference};
140 }
141 }
142
143 0 return;
144 }
145
146 0 ▶sub remove_all_automatic {
Subroutine remove_all_automatic: not called CC=3 SCAR=24.8
Pod documented
147 0 my $self = shift;
148
149 0 my $lexicon_ref = $self->lexicon_ref;
150 0 for my $message_ref ( values %{$lexicon_ref} ) {
151 0 for my $value_ref ( values %{$message_ref} ) {
152 0 delete $value_ref->{automatic};
153 }
154 }
155
156 0 return;
157 }
158
159 0 ▶sub remove_all_non_referenced {
Subroutine remove_all_non_referenced: not called CC=6 SCAR=37.4
Pod documented
160 0 my $self = shift;
161
162 0 my $lexicon_ref = $self->lexicon_ref;
163 0 for my $message_ref ( values %{$lexicon_ref} ) {
164 MESSAGE_KEY:
165 0 for my $message_key ( keys %{$message_ref} ) {
166 0 ▶ length $message_key
Branch: 1 branch
BranchTrueFalseTotal
length $message_key or next MESSAGE_KEY 0 0 0
167 or next MESSAGE_KEY; # skip header
168 my $has_reference
169 = exists $message_ref->{$message_key}->{reference}
170 0 ▶ && $message_ref->{$message_key}->{reference} =~ m{\S}xms;
Condition0%0/3
exists $message_ref->{$message_key}{'reference'} && $message_ref->{$message_key}{'reference'} =~ /\S/msx
!ll&&!rl&&r
000
MC/DC0%0/2
exists $message_ref->{$message_key}{'reference'} && $message_ref->{$message_key}{'reference'} =~ /\S/msx
exists $message_ref->{$message_key}{'reference'} $message_ref->{$message_key}{'reference'} =~ /\S/msx
Truth table0%0/3
A && B
A= exists $message_ref->{$message_key}{'reference'}B= $message_ref->{$message_key}{'reference'} =~ /\S/msx
ABresult
0X0
100
111
171 $has_reference
172 0 ▶ or delete $message_ref->{$message_key};
Branch: 1 branch
BranchTrueFalseTotal
$has_reference or delete $message_ref->{$message_key} 0 0 0
173 }
174 }
175
176 0 return;
177 }
178
179 0 ▶sub merge_extract {
Subroutine merge_extract: not called CC=16 SCAR=56.1
Pod documented
180 0 my ( $self, $arg_ref ) = @_;
181
182 my $extract_lexicon_ref = $arg_ref->{lexicon_ref}
183 0 ▶ or confess 'Parameter lexicon_ref expected';
Branch: 1 branch
BranchTrueFalseTotal
my $extract_lexicon_ref = $arg_ref->{"lexicon_ref"} or confess("Parameter lexicon_ref expected") 0 0 0
184 0 ▶ ref $extract_lexicon_ref eq 'HASH'
Branch: 1 branch
BranchTrueFalseTotal
ref $extract_lexicon_ref eq "HASH" or confess("Parameter lexicon_ref is not a hash reference") 0 0 0
185 or confess 'Parameter lexicon_ref is not a hash reference';
186
187 0 my $key_util = Locale::TextDomain::OO::Util::JoinSplitLexiconKeys->instance;
188 # extracted to language i-default
189 my $extract_lexicon_key = $key_util->join_lexicon_key({(
190 map {
191 0 $_ => $arg_ref->{$_};
192 }
193 qw( category domain project )
194 )});
195 # merged to real language
196 my $lexicon_key = $key_util->join_lexicon_key({(
197 map {
198 0 $_ => $self->$_;
199 }
200 qw( category domain language project )
201 )});
202
203 0 ▶ my $message_ref = $self->lexicon_ref->{$lexicon_key} ||= {};
Condition0%0/2
$self->lexicon_ref->{$lexicon_key} ||= {}
l!l
00
MC/DC0%0/1
$self->lexicon_ref->{$lexicon_key} ||= {}
$self->lexicon_ref->{$lexicon_key}
Truth table0%0/2
A
A= $self->lexicon_ref->{$lexicon_key}
Aresult
11
00
204 0 my $message_keys = Set::Scalar->new( keys %{$message_ref} );
205 0 my $extract_message_ref = $extract_lexicon_ref->{$extract_lexicon_key};
206 0 my $extract_message_keys = Set::Scalar->new( keys %{$extract_message_ref} );
207 0 my $skip_new_messages = $arg_ref->{skip_new_messages};
208 my @new_message_keys
209 = ref $skip_new_messages ne 'HASH'
210 # simple
211 ? (
212 $skip_new_messages
213 # bool parameter true
214 ? ()
215 : $extract_message_keys->difference($message_keys)->elements
216 )
217 # extended
218 : ! $skip_new_messages->{on}
219 # hash parameter false
220 ? $extract_message_keys->difference($message_keys)->elements
221 0 ▶ : do {
Branch: 3 branches
BranchTrueFalseTotal
ref $skip_new_messages ne 'HASH' ? : 0 0 0
$skip_new_messages ? : 0 0 0
!$skip_new_messages->{'on'} ? : 0 0 0
222 0 ▶ my $to_regex = sub {
Subroutine __ANON__: not called CC=5 SCAR=34.0
223 0 my $any = shift;
224 my @parts
225 0 ▶ = map { ref $_ eq 'Regexp' ? $_ : qr{\Q$_\E}xmsi }
Branch: 1 branch
BranchTrueFalseTotal
ref $_ eq 'Regexp' ? : 0 0 0
226 0 ▶ grep { defined && length }
Branch: 1 branch
BranchTrueFalseTotal
ref $any eq 'ARRAY' ? : 0 0 0
Condition0%0/3
defined $_ && length $_
!ll&&!rl&&r
000
MC/DC0%0/2
defined $_ && length $_
defined $_ length $_
Truth table0%0/3
A && B
A= defined $_B= length $_
ABresult
0X0
100
111
227 0 ref $any eq 'ARRAY' ? @{$any} : $any;
228 return @parts
229 0 ▶ ? do {
Branch: 1 branch
BranchTrueFalseTotal
@parts ? : 0 0 0
230 0 my $joined = join ' | ', @parts;
231 0 qr{ $joined }xms;
232 }
233 : qr{ (?!) }xms;
234 0 };
235 0 my $regex = $to_regex->( $skip_new_messages->{no_skip_for} );
236 0 my $not_regex = $to_regex->( $skip_new_messages->{but_skip_for} );
237
238 0 ▶ grep { $_ =~ $regex && $_ !~ $not_regex }
Condition0%0/3
$_ =~ /$regex/ && !($_ =~ /$not_regex/)
!ll&&!rl&&r
000
MC/DC0%0/2
$_ =~ /$regex/ && !($_ =~ /$not_regex/)
$_ =~ /$regex/ !($_ =~ /$not_regex/)
Truth table0%0/3
A && not(B)
A= $_ =~ /$regex/B= !($_ =~ /$not_regex/)
ABresult
0X0
100
111
239 $extract_message_keys->difference($message_keys)->elements;
240 };
241 0 my @changed_message_keys = $extract_message_keys->intersection($message_keys)->elements;
242
243 # merge header
244 0 my $header_arg_ref = $arg_ref->{header_ref};
245 0 ▶ if ($header_arg_ref) {
Branch: 1 branch
BranchTrueFalseTotal
if ($header_arg_ref) 0 0 0
246 # overwrite them
247 0 ▶ if ( ref $arg_ref->{header_ref} eq 'HASH' ) {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $arg_ref->{'header_ref'} eq 'HASH') { } 0 0 0
elsif (ref $header_arg_ref eq 'CODE') { } 0 0 0
248 0 $message_ref->{ q{} } = clone($header_arg_ref);
249 }
250 # manipulate them
251 elsif ( ref $header_arg_ref eq 'CODE' ) {
252 0 ▶ local $_ = $message_ref->{ q{} } || {};
Condition0%0/2
$message_ref->{''} || {}
l!l
00
MC/DC0%0/1
$message_ref->{''} || {}
$message_ref->{''}
Truth table0%0/2
A
A= $message_ref->{''}
Aresult
11
00
253 0 $header_arg_ref->();
254 0 $message_ref->{ q{} } = clone($_);
255 }
256 }
257
258 MESSAGE_KEY:
259 0 for my $message_key (@new_message_keys) {
260 0 ▶ length $message_key
Branch: 1 branch
BranchTrueFalseTotal
length $message_key or next MESSAGE_KEY 0 0 0
261 or next MESSAGE_KEY;
262 $message_ref->{$message_key}
263 0 = clone( $extract_message_ref->{$message_key} );
264 }
265 MESSAGE_KEY:
266 0 for my $message_key (@changed_message_keys) {
267 0 ▶ length $message_key
Branch: 1 branch
BranchTrueFalseTotal
length $message_key or next MESSAGE_KEY 0 0 0
268 or next MESSAGE_KEY;
269 my $extract_message_value_ref
270 0 = clone( $extract_message_ref->{$message_key} );
271 0 @{ $message_ref->{$message_key} }{ keys %{$extract_message_value_ref} }
272 0 = values %{ $extract_message_value_ref };
273 }
274
275 0 return;
276 }
277
278 1 __PACKAGE__->meta->make_immutable;
279
280 1 1;
281
282 __END__
« Extract/Process/Plugin/PO.pm ↑ Summary Extract/Base/RegexBasedExtractor.pm »