Extract/YAML.pm

filter: Statementstmt 77.3% 65 / 84 Branchbran 28.5% 4 / 14 Conditioncond 27.2% 3 / 11 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 100% 12 / 12 Podpod 100% 3 / 3 totaltotal 66.9% 87 / 130 CC 13 SCAR 16.6
CC
13
Cov
66%
__ANON__
14.9
__ANON__
5.5
preprocess
3.7
CRAP 5.2
« Extract/JavaScript.pm ↑ Summary Extract/HTML.pm »
1 package Locale::TextDomain::OO::Extract::YAML; ## no critic (TidyCode)
2
3 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use MooX::Types::MooseLike::Base qw(ArrayRef Str);
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
8
9 2 our $VERSION = '2.011';
10
11 2 extends qw(
12 Locale::TextDomain::OO::Extract::Base::RegexBasedExtractor
13 );
14 2 with qw(
15 Locale::TextDomain::OO::Extract::Role::File
16 );
17
18 has filter => (
19 is => 'rw',
20 isa => ArrayRef[Str],
21 lazy => 1,
22 1 ▶ default => sub {[ 'all' ]},
Subroutine __ANON__: called CC=1 SCAR=0.0
23 2 );
24
25 4 ▶sub _filtered_start_rule {
Subroutine _filtered_start_rule: called CC=2 SCAR=7.4
26 4 my $self = shift;
27
28 4 my %filter_of = map { $_ => 1 } @{ $self->filter };
29 16 ▶ my $list_if = sub {
Subroutine __ANON__: called CC=4 SCAR=17.1
30 16 my ( $key, @list ) = @_;
31 my $condition
32 = $filter_of{all} && ! $filter_of{"!$key"}
33 16 ▶ || $filter_of{$key};
Condition33%2/6
$filter_of{'all'} && !$filter_of{"!$key"} || $filter_of{$key}
l!l&&r!l&&!r
1600
$filter_of{"all"} and not $filter_of{"!$key"}
!ll&&!rl&&r
0016
MC/DC0%0/3
$filter_of{'all'} && !$filter_of{"!$key"} || $filter_of{$key}
$filter_of{"all"} not $filter_of{"!$key"} $filter_of{$key}
Truth table20%1/5
A and not(B) || C
A= $filter_of{"all"}B= not $filter_of{"!$key"}C= $filter_of{$key}
ABCresult
11X1
0X11
1011
0X00
1000
34 16 ▶ return $condition ? @list : ();
Branch: 1 branch
BranchTrueFalseTotal
$condition ? : 16 0 16
35 4 };
36 4 my $hash_key_suffix = join "\n| ", (
37 $list_if->('Gettext', qr{ __ \b }xms),
38 $list_if->('Maketext::Loc', qr{ _loc \b }xms),
39 $list_if->('Gettext::Loc', qr{ _loc_ \b }xms),
40 $list_if->('BabelFish::Loc', qr{ _loc_b \b }xms),
41 );
42 4 ▶ $hash_key_suffix ||= '(?!)';
Condition50%1/2
$hash_key_suffix ||= "(?!)"
l!l
40
MC/DC0%0/1
$hash_key_suffix ||= "(?!)"
$hash_key_suffix
Truth table50%1/2
A
A= $hash_key_suffix
Aresult
11
00
43
44 4 return qr{
45 ^ [ -]*
46 (?: content | label | message | value )
47 (?:
48 $hash_key_suffix
49 )
50 [ ]* [:]
51 }xms;
52 }
53
54 ## no critic (ComplexRegexes)
55 2 my $text_rule
56 = [
57 [
58 # '...'
59 qr{
60 [ ]*
61 [']
62 (
63 [^\\']* # normal text
64 (?: \\ . [^\\']* )* # maybe followed by escaped char and normal text
65 )
66 [']
67 }xms,
68 ],
69 'or',
70 [
71 # "..."
72 qr{
73 [ ]*
74 ["]
75 (
76 [^\\"]* # normal text
77 (?: \\ . [^\\"]* )* # maybe followed by escaped char and normal text
78 )
79 ["]
80 }xms,
81 ],
82 'or',
83 [
84 # ...
85 qr{
86 [ ]*
87 (
88 .*? # normal text
89 )
90 [ ]* $
91 }xms,
92 ],
93 ];
94
95 my $rules = [
96 # content_loc: |
97 # text
98 # ...
99 [
100 'begin',
101 16 ▶ sub {
Subroutine __ANON__: called CC=5 SCAR=27.0
102 16 my $content_ref = shift;
103
104 16 my $regex = qr{
105 ^ ( [ -]* )
106 (?: content | label | message | value ) _ (?: _ | loc_b? | loc )
107 [ ]* [:] [ ]* [|] [ ]* \n
108 }xms;
109 16 ▶ $content_ref
Branch: 1 branch
BranchTrueFalseTotal
$content_ref or return $regex 16 0 16
110 or return $regex;
111 # full match begins here
112 16 my $pos = pos ${$content_ref};
113 # begin of heredoc with |
114 16 ▶ my ( $full_match, $indent ) = ${$content_ref} =~ m{ \G ( $regex ) }xms
Branch: 1 branch
BranchTrueFalseTotal
() = ${$content_ref;} =~ / \G ( $regex ) /msx or return 0 16 16
115 or return;
116 # get heredoc lines
117 0 pos ${$content_ref} = $pos + length $full_match;
118 0 $indent =~ tr{-}{ };
119 0 $indent .= q{ } x 2; # next indent level
120 0 $regex = qr{
121 ( [ ]* \n ) # empty line
122 | \Q$indent\E ( [^\n]* \n ) # text line
123 }xms;
124 0 my $heredoc = q{};
125 0 ▶ while ( ( $full_match, my ( $empty_line, $text_line ) ) = ${$content_ref} =~ m{ \G ( $regex ) }xms ) {
Branch: 1 branch
BranchTrueFalseTotal
if (($full_match, my($empty_line, $text_line)) = ${$content_ref;} =~ / \G ( $regex ) /msx) 0 0 0
126 0 ▶ $heredoc .= $empty_line || $text_line;
Condition0%0/3
$empty_line || $text_line
l!l&&r!l&&!r
000
MC/DC0%0/2
$empty_line || $text_line
$empty_line $text_line
Truth table0%0/3
A || B
A= $empty_lineB= $text_line
ABresult
1X1
011
000
127 0 pos ${$content_ref} += length $full_match;
128 }
129 0 chomp $heredoc;
130 # full match over all
131 $full_match = substr
132 0 ${$content_ref},
133 $pos,
134 0 ( pos ${$content_ref} ) - $pos;
135 # reset pos for alternatives
136 0 pos ${$content_ref} = $pos;
137
138 0 return $full_match, $heredoc;
139 },
140 2 'end',
141 ],
142 'or',
143 # content_loc: 'text ...'
144 # label_loc_ : "text ..."
145 # message__ : text ...
146 # value__ : text ...
147 # all combinations left after _ and right to : are possible
148 [
149 'begin',
150 qr{
151 ^ [ -]*
152 (?: content | label | message | value ) _ (?: _ | loc_b? | loc )
153 [ ]* [:]
154 }xms,
155 'and',
156 $text_rule,
157 'end',
158 ],
159 ];
160
161 # remove code after # on pos 1
162 4 ▶sub preprocess {
Subroutine preprocess: called CC=3 SCAR=13.0
Pod documented
163 4 my $self = shift;
164
165 4 my $content_ref = $self->content_ref;
166
167 4 ${$content_ref} =~ s{ \r? \n }{\n}xmsg;
168 4 ${$content_ref} =~ s{
169 # "text with #" # comment
170 (
171 ["]
172 [^\\"]* # normal text
173 (?: \\ . [^\\"]* )* # maybe followed by escaped char and normal text
174 ["]
175 ) [ ]* [#] [^\n]* ( \n | \z )
176 |
177 # 'text with #' # comment
178 (
179 [']
180 [^\\']* # normal text
181 (?: \\ . [^\\']* )* # maybe followed by escaped char and normal text
182 [']
183 ) [ ]* [#] [^\n]* ( \n | \z )
184 |
185 # simple comment line
186 [ ]* [#] [^\n]* ( \n | \z )
187 }{
188 0 ▶ $1 ? "$1$2"
Branch: 2 branches
BranchTrueFalseTotal
$1 ? : 0 0 0
$3 ? : 0 0 0
189 : $3 ? "$3$4"
190 : $5
191 }xmsge;
192
193 4 return;
194 }
195 ## use critic (ComplexRegexes)
196
197 16 ▶sub stack_item_mapping {
Subroutine stack_item_mapping: called CC=2 SCAR=7.0
Pod documented
198 16 my $self = shift;
199
200 16 my $match = $_->{match};
201 16 ▶ @{$match}
Branch: 1 branch
BranchTrueFalseTotal
@{$match;} or return 16 0 16
202 or return;
203
204 $self->add_message({
205 reference => ( sprintf '%s:%s', $self->filename, $_->{line_number} ),
206 domain => $self->domain,
207 16 msgid => shift @{$match},
208 category => $self->category,
209 });
210
211 16 return;
212 }
213
214 4 ▶sub extract {
Subroutine extract: called CC=2 SCAR=6.9
Pod documented
215 4 my $self = shift;
216
217 4 $self->start_rule( $self->_filtered_start_rule );
218 4 $self->rules($rules);
219 4 $self->preprocess;
220 4 $self->SUPER::extract;
221 4 for ( @{ $self->stack } ) {
222 16 $self->stack_item_mapping;
223 }
224
225 4 return $self;
226 }
227
228 2 __PACKAGE__->meta->make_immutable;
229
230 2 1;
231
232 __END__
« Extract/JavaScript.pm ↑ Summary Extract/HTML.pm »