blib/lib/App/jl.pm

filter: Statementstmt 100% 200 / 200 Branchbran 90.6% 87 / 96 Conditioncond 83.0% 44 / 53 MC/DCmcdc 70.0% 21 / 30 Subroutinesub 100% 33 / 33 Podpod 100% 3 / 3 totaltotal 93.4% 388 / 415 CC 68 SCAR 15.6
CC
68
Cov
95%
_convert_timestamp
9.2
_run_line
8.0
_recursive_post_process
7.0
CRAP 4.7
↑ Summary script/jl »
1 package App::jl;
2 9 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 9 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 9 ▶use JSON qw//;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 9 ▶use Sub::Data::Recursive;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 9 ▶use B;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 9 ▶use Getopt::Long qw/GetOptionsFromArray/;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 9 our $VERSION = '0.20';
10  
11 9 my $MAX_RECURSIVE_CALL = 255;
12  
13 9 my $MAYBE_UNIXTIME = join '|', (
14 'create',
15 'update',
16 'expire',
17 '.._(?:at|on)',
18 '.ed$',
19 'date',
20 'time',
21 'since',
22 'when',
23 );
24  
25 9 my $LOG_LEVEL_STRINGS = join '|', (
26 'debug',
27 'trace',
28 'info',
29 'notice',
30 'warn',
31 'error',
32 'crit(?:ical)?',
33 'fatal',
34 'emerg(?:ency)?',
35 );
36  
37 9 my $L_BRACKET = '[ \\( \\{ \\< ]';
38 9 my $R_BRACKET = '[ \\) \\} \\> ]';
39  
40 9 my $UNIXTIMESTAMP_KEY = '';
41  
42 9 my $GMTIME;
43  
44 9 my $INVOKER = 'Sub::Data::Recursive';
45  
46 36 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod documented
47 36 my $class = shift;
48 36 my @argv = @_;
49  
50 36 my $opt = $class->_parse_opt(@argv);
51  
52 my $self = bless {
53 _opt => $opt,
54 32 _json => JSON->new->utf8->pretty(!$opt->{no_pretty})->canonical(1),
55 __current_orig_line => undef,
56 }, $class;
57  
58 32 $self->_lazyload_modules;
59  
60 32 return $self;
61 }
62  
63 321 ▶sub opt {
Subroutine opt: called CC=1 SCAR=0.0
Pod documented
64 321 my ($self, $key) = @_;
65  
66 321 return $self->{_opt}{$key};
67 }
68  
69 4 ▶sub run {
Subroutine run: called CC=4 SCAR=13.9
Pod documented
70 4 my ($self) = @_;
71  
72 4 local $| = !!$self->opt('unbuffered');
73  
74 4 ▶ my $out = !!$self->opt('stderr') ? *STDERR : *STDOUT;
Branch: 1 branch
BranchTrueFalseTotal
!!$self->opt('stderr') ? : 1 3 4
75  
76 4 ▶ while ($self->{__current_orig_line} = <STDIN>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($self->{"__current_orig_line"} = readline STDIN)) 4 4 8
77 4 ▶ if (my $line = $self->_run_line) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $line = $self->_run_line) 3 1 4
78 3 print $out $line;
79 }
80 4 $self->{__current_orig_line} = undef;
81 }
82 }
83  
84 32 ▶sub _run_line {
Subroutine _run_line: called CC=8 SCAR=20.8
85 32 my ($self) = @_;
86  
87 32 ▶ if ($self->{__current_orig_line} =~ m!^[\s\t\r\n]+$!) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"__current_orig_line"} =~ /^[\s\t\r\n]+$/) 1 31 32
88 1 return;
89 }
90  
91 31 ▶ if ($self->{__current_orig_line} !~ m!^\s*[\[\{]!) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"__current_orig_line"} =~ /^\s*[\[\{]/) 2 29 31
92 2 ▶ return $self->opt('sweep') ? undef : $self->{__current_orig_line};
Branch: 1 branch
BranchTrueFalseTotal
$self->opt('sweep') ? : 1 1 2
93 }
94  
95 29 ▶ if (my $rs = $self->opt('grep')) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $rs = $self->opt("grep")) 4 25 29
96 4 ▶ if (!$self->_match_grep($rs)) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->_match_grep($rs)) 1 3 4
97 1 return; # no match
98 }
99 }
100  
101 28 ▶ if (my $rs = $self->opt('ignore')) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $rs = $self->opt("ignore")) 3 25 28
102 3 ▶ if ($self->_match_grep($rs)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_match_grep($rs)) 3 0 3
103 3 return; # ignore if even one match
104 }
105 }
106  
107 25 return $self->_process;
108 }
109  
110 7 ▶sub _match_grep {
Subroutine _match_grep: called CC=3 SCAR=11.0
111 7 my ($self, $rs) = @_;
112  
113 7 for my $r (@{$rs}) {
114 7 ▶ return 1 if $self->{__current_orig_line} =~ m!$r!;
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"__current_orig_line"} =~ /$r/ 6 1 7
115 }
116 }
117  
118 32 ▶sub _lazyload_modules {
Subroutine _lazyload_modules: called CC=4 SCAR=13.9
119 32 my ($self) = @_;
120  
121 32 ▶ if ($self->opt('xxxx') || $self->opt('timestamp_key')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->opt("xxxx") or $self->opt("timestamp_key")) 10 22 32
Condition66%2/3
$self->opt("xxxx") or $self->opt("timestamp_key")
l!l&&r!l&&!r
10022
MC/DC50%1/2
$self->opt("xxxx") or $self->opt("timestamp_key")
$self->opt("xxxx") $self->opt("timestamp_key")
Truth table66%2/3
A or B
A= $self->opt("xxxx")B= $self->opt("timestamp_key")
ABresult
1X1
011
000
122 10 require 'POSIX.pm'; ## no critic
123 10 POSIX->import;
124 }
125  
126 32 ▶ if ($self->opt('yaml')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->opt("yaml")) 1 31 32
127 1 require 'YAML/Syck.pm'; ## no critic
128 1 YAML::Syck->import;
129 1 $YAML::Syck::SortKeys = 1;
130 }
131 }
132  
133 25 ▶sub _process {
Subroutine _process: called CC=2 SCAR=6.9
134 25 my ($self) = @_;
135  
136 25 my $decoded = eval {
137 25 $self->{_json}->decode($self->{__current_orig_line});
138 };
139 25 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) { } 1 24 25
140 1 return $self->{__current_orig_line};
141 }
142 else {
143 24 $self->_recursive_process($decoded);
144 24 return $self->_encode($decoded);
145 }
146 }
147  
148 24 ▶sub _encode {
Subroutine _encode: called CC=2 SCAR=6.9
149 24 my ($self, $decoded) = @_;
150  
151 24 ▶ if ($self->opt('yaml')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->opt('yaml')) { } 1 23 24
152 1 return YAML::Syck::Dump($decoded);
153 }
154 else {
155 23 return $self->{_json}->encode($decoded);
156 }
157 }
158  
159 24 ▶sub _recursive_process {
Subroutine _recursive_process: called CC=1 SCAR=0.0
160 24 my ($self, $decoded) = @_;
161  
162 24 $self->_recursive_pre_process($decoded);
163  
164 24 $self->{_recursive_call} = $MAX_RECURSIVE_CALL;
165 24 $self->_recursive_decode_json($decoded);
166  
167 24 $self->_recursive_post_process($decoded);
168 }
169  
170 24 ▶sub _recursive_pre_process {
Subroutine _recursive_pre_process: called CC=2 SCAR=6.9
171 24 my ($self, $decoded) = @_;
172  
173 24 $INVOKER->invoke(\&_trim => $decoded);
174  
175 24 ▶ $self->_invoker(\&_split_lf => $decoded) if $self->opt('x');
Branch: 1 branch
BranchTrueFalseTotal
if $self->opt("x") 14 10 24
176 }
177  
178 24 ▶sub _recursive_post_process {
Subroutine _recursive_post_process: called CC=7 SCAR=19.5
179 24 my ($self, $decoded) = @_;
180  
181 24 ▶ if ($self->opt('x')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->opt("x")) 14 10 24
182 14 $self->_invoker(\&_split_lf => $decoded);
183 }
184  
185 24 ▶ if ($self->opt('xx')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->opt("xx")) 14 10 24
186 14 $self->_invoker(\&_split_comma => $decoded);
187 }
188  
189 24 ▶ if ($self->opt('xxx')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->opt("xxx")) 12 12 24
190 12 $self->_invoker(\&_split_label => $decoded);
191 }
192  
193 24 ▶ if ($self->opt('xxxx') || $self->opt('timestamp_key')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->opt("xxxx") or $self->opt("timestamp_key")) 10 14 24
Condition66%2/3
$self->opt("xxxx") or $self->opt("timestamp_key")
l!l&&r!l&&!r
10014
MC/DC50%1/2
$self->opt("xxxx") or $self->opt("timestamp_key")
$self->opt("xxxx") $self->opt("timestamp_key")
Truth table66%2/3
A or B
A= $self->opt("xxxx")B= $self->opt("timestamp_key")
ABresult
1X1
011
000
194 10 ▶ if ($self->opt('xxxxx')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->opt('xxxxx')) { } 7 3 10
195 7 $INVOKER->invoke(\&_forcely_convert_timestamp => $decoded);
196 }
197 else {
198 3 $self->_invoker(\&_convert_timestamp => $decoded);
199 }
200 }
201  
202 24 $INVOKER->invoke(\&_trim => $decoded);
203 }
204  
205 9 my $LAST_VALUE;
206  
207 57 ▶sub _invoker {
Subroutine _invoker: called CC=1 SCAR=0.0
208 57 my ($self, $code_ref, $hash) = @_;
209  
210 57 $LAST_VALUE = '';
211 57 $INVOKER->massive_invoke($code_ref => $hash);
212 }
213  
214 309 ▶sub _skippable_value {
Subroutine _skippable_value: called CC=4 SCAR=13.9
215 309 my ($context, $last_value) = @_;
216  
217 309 ▶ return $context && $context eq 'HASH'
Condition88%8/9
$context && $context eq 'HASH' && $last_value && $last_value =~ /user[\-\_\s]*agent/i
!ll&&!rl&&r
9418827
$context and $context eq "HASH" and $last_value
!ll&&!rl&&r
4054215
$context and $context eq "HASH"
!ll&&!rl&&r
040269
MC/DC75%3/4
$context && $context eq 'HASH' && $last_value && $last_value =~ /user[\-\_\s]*agent/i
$context $context eq "HASH" $last_value $last_value =~ /user[\-\_\s]*agent/i
Truth table80%4/5
A and B and C && D
A= $contextB= $context eq "HASH"C= $last_valueD= $last_value =~ /user[\-\_\s]*agent/i
ABCDresult
0XXX0
10XX0
110X0
11100
11111
218 && $last_value && $last_value =~ m!user[\-\_\s]*agent!i;
219 }
220  
221 135 ▶sub _split_lf {
Subroutine _split_lf: called CC=4 SCAR=13.9
222 135 my $line = $_[0];
223 135 my $context = $_[1];
224  
225 135 ▶ if (_skippable_value($context, $LAST_VALUE)) {
Branch: 1 branch
BranchTrueFalseTotal
if (_skippable_value($context, $LAST_VALUE)) 14 121 135
226 14 $LAST_VALUE = $line;
227 14 return $line;
228 }
229  
230 121 $LAST_VALUE = $line;
231  
232 121 ▶ if ($line =~ m![\t\r\n]!) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /[\t\r\n]/) 8 113 121
233 8 chomp $line;
234 8 my @elements = split /[\t\r\n]+/, $line;
235 8 ▶ $_[0] = \@elements if scalar @elements > 1;
Branch: 1 branch
BranchTrueFalseTotal
if scalar @elements > 1 8 0 8
236 }
237 }
238  
239 88 ▶sub _split_comma {
Subroutine _split_comma: called CC=5 SCAR=16.2
240 88 my $line = $_[0];
241 88 my $context = $_[1];
242  
243 88 ▶ if (_skippable_value($context, $LAST_VALUE)) {
Branch: 1 branch
BranchTrueFalseTotal
if (_skippable_value($context, $LAST_VALUE)) 7 81 88
244 7 $LAST_VALUE = $line;
245 7 return $line;
246 }
247  
248 81 $LAST_VALUE = $line;
249  
250 81 ▶ return $line if $line !~ m!, ! || $line =~ m!\\!;
Branch: 1 branch
BranchTrueFalseTotal
if not $line =~ /, / or $line =~ /\\/ 79 2 81
Condition66%2/3
not $line =~ /, / or $line =~ /\\/
l!l&&r!l&&!r
7902
MC/DC50%1/2
not $line =~ /, / or $line =~ /\\/
not $line =~ /, / $line =~ /\\/
Truth table66%2/3
not(A) or B
A= not $line =~ /, /B= $line =~ /\\/
ABresult
1X1
011
000
251  
252 2 chomp $line;
253  
254 2 my @elements = split /,\s+/, $line;
255  
256 2 ▶ $_[0] = \@elements if scalar @elements > 1;
Branch: 1 branch
BranchTrueFalseTotal
if scalar @elements > 1 2 0 2
257 }
258  
259 86 ▶sub _split_label {
Subroutine _split_label: called CC=4 SCAR=13.9
260 86 my $line = $_[0];
261 86 my $context = $_[1];
262  
263 86 ▶ if (_skippable_value($context, $LAST_VALUE)) {
Branch: 1 branch
BranchTrueFalseTotal
if (_skippable_value($context, $LAST_VALUE)) 6 80 86
264 6 $LAST_VALUE = $line;
265 6 return $line;
266 }
267  
268 80 $LAST_VALUE = $line;
269  
270 80 ▶ return $line if $line =~ m!\\!;
Branch: 1 branch
BranchTrueFalseTotal
if $line =~ /\\/ 0 80 80
271  
272 80 chomp $line;
273  
274 # remove spaces between braces
275 80 $line =~ s!( $R_BRACKET ) [\s\t]+ ( $R_BRACKET )!$1$2!xg;
276  
277 # replace square brackets label
278 80 $line =~ s!( \[ [\s\t]* .+ [\s\t]* \] )!$1\n!ixg;
279  
280 # replace log level labels
281 80 $line =~ s!( $L_BRACKET ) [\s\t]* ( $LOG_LEVEL_STRINGS ) [\s\t]* ( $R_BRACKET )!$1$2$3\n!ixg;
282  
283 80 my @elements = split /\n/, $line;
284  
285 80 ▶ $_[0] = \@elements if scalar @elements > 1;
Branch: 1 branch
BranchTrueFalseTotal
if scalar @elements > 1 3 77 80
286 }
287  
288 37 ▶sub _convert_timestamp {
Subroutine _convert_timestamp: called CC=9 SCAR=22.2
289 37 my $line = $_[0];
290 37 my $context = $_[1];
291  
292 37 ▶ return $line if !$context || $context ne 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
if not $context or $context ne "HASH" 11 26 37
Condition66%2/3
not $context or $context ne "HASH"
l!l&&r!l&&!r
01126
MC/DC50%1/2
not $context or $context ne "HASH"
not $context $context ne "HASH"
Truth table66%2/3
not(A) or B
A= not $contextB= $context ne "HASH"
ABresult
1X1
011
000
293  
294 26 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if ($UNIXTIMESTAMP_KEY and $LAST_VALUE eq $UNIXTIMESTAMP_KEY and $line =~ /(\d+(\.\d+)?)/ or $LAST_VALUE =~ /(?:$MAYBE_UNIXTIME)/i and $line =~ /(\d+(\.\d+)?)/) 9 17 26
Condition83%10/12
$UNIXTIMESTAMP_KEY and $LAST_VALUE eq $UNIXTIMESTAMP_KEY and $line =~ /(\d+(\.\d+)?)/ or $LAST_VALUE =~ /(?:$MAYBE_UNIXTIME)/i and $line =~ /(\d+(\.\d+)?)/
l!l&&r!l&&!r
1817
$UNIXTIMESTAMP_KEY and $LAST_VALUE eq $UNIXTIMESTAMP_KEY and $line =~ /(\d+(\.\d+)?)/
!ll&&!rl&&r
2501
$UNIXTIMESTAMP_KEY and $LAST_VALUE eq $UNIXTIMESTAMP_KEY
!ll&&!rl&&r
11141
$LAST_VALUE =~ /(?:$MAYBE_UNIXTIME)/i and $line =~ /(\d+(\.\d+)?)/
!ll&&!rl&&r
1708
MC/DC60%3/5
$UNIXTIMESTAMP_KEY and $LAST_VALUE eq $UNIXTIMESTAMP_KEY and $line =~ /(\d+(\.\d+)?)/ or $LAST_VALUE =~ /(?:$MAYBE_UNIXTIME)/i and $line =~ /(\d+(\.\d+)?)/
$UNIXTIMESTAMP_KEY $LAST_VALUE eq $UNIXTIMESTAMP_KEY $line =~ /(\d+(\.\d+)?)/ $LAST_VALUE =~ /(?:$MAYBE_UNIXTIME)/i $line =~ /(\d+(\.\d+)?)/
Truth table50%5/10
A and B and C or D and E
A= $UNIXTIMESTAMP_KEYB= $LAST_VALUE eq $UNIXTIMESTAMP_KEYC= $line =~ /(\d+(\.\d+)?)/D= $LAST_VALUE =~ /(?:$MAYBE_UNIXTIME)/iE= $line =~ /(\d+(\.\d+)?)/
ABCDEresult
111XX1
0XX111
10X111
110111
0XX0X0
0XX100
10X0X0
10X100
1100X0
110100
295 ($UNIXTIMESTAMP_KEY && $LAST_VALUE eq $UNIXTIMESTAMP_KEY && $line =~ m!(\d+(\.\d+)?)!)
296 || ($LAST_VALUE =~ m!(?:$MAYBE_UNIXTIME)!i && $line =~ m!(\d+(\.\d+)?)!)
297 ) {
298 9 ▶ if (my $date = _ts2date($1, $2)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $date = _ts2date($1, $2)) 9 0 9
299 9 $_[0] = $date;
300 }
301 }
302  
303 26 $LAST_VALUE = $line;
304 }
305  
306 46 ▶sub _forcely_convert_timestamp {
Subroutine _forcely_convert_timestamp: called CC=3 SCAR=11.0
307 46 my $line = $_[0];
308  
309 46 ▶ if ($line =~ m!(\d+(\.\d+)?)!) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /(\d+(\.\d+)?)/) 7 39 46
310 7 ▶ if (my $date = _ts2date($1, $2)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $date = _ts2date($1, $2)) 3 4 7
311 3 $_[0] = $date;
312 }
313 }
314 }
315  
316 16 ▶sub _ts2date {
Subroutine _ts2date: called CC=6 SCAR=17.9
317 16 my $unix_timestamp = shift;
318 16 ▶ my $msec = shift || '';
Condition100%2/2
shift() || ''
l!l
313
MC/DC100%1/1
shift() || ''
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
319  
320 # 946684800 = 2000-01-01T00:00:00Z
321 16 ▶ if ($unix_timestamp >= 946684800 && $unix_timestamp <= ((2**32 - 1) * 1000)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($unix_timestamp >= 946684800 and $unix_timestamp <= '4294967295000') 12 4 16
Condition100%3/3
$unix_timestamp >= 946684800 and $unix_timestamp <= '4294967295000'
!ll&&!rl&&r
3112
MC/DC100%2/2
$unix_timestamp >= 946684800 and $unix_timestamp <= '4294967295000'
$unix_timestamp >= 946684800 $unix_timestamp <= '4294967295000'
Truth table100%3/3
A and B
A= $unix_timestamp >= 946684800B= $unix_timestamp <= '4294967295000'
ABresult
0X0
100
111
322 12 ▶ if ($unix_timestamp > 2**32 -1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($unix_timestamp > 4294967295) 3 9 12
323 3 ($msec) = ($unix_timestamp =~ m!(\d\d\d)$!);
324 3 $msec = ".$msec";
325 3 $unix_timestamp = int($unix_timestamp / 1000);
326 }
327 12 ▶ my @t = $GMTIME ? gmtime($unix_timestamp) : localtime($unix_timestamp);
Branch: 1 branch
BranchTrueFalseTotal
$GMTIME ? : 1 11 12
328 12 return POSIX::strftime('%Y-%m-%d %H:%M:%S', @t) . $msec;
329 }
330 }
331  
332 219 ▶sub _trim {
Subroutine _trim: called CC=4 SCAR=13.9
333 219 my $line = $_[0];
334  
335 219 my $trim = 0;
336  
337 219 ▶ if ($line =~ m!^[\s\t\r\n]+!) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /^[\s\t\r\n]+/) 3 216 219
338 3 $line =~ s!^[\s\t\r\n]+!!;
339 3 $trim = 1;
340 }
341  
342 219 ▶ if ($line =~ m![\s\t\r\n]+$!) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /[\s\t\r\n]+$/) 9 210 219
343 9 $line =~ s![\s\t\r\n]+$!!;
344 9 $trim = 1;
345 }
346  
347 219 ▶ if ($trim) {
Branch: 1 branch
BranchTrueFalseTotal
if ($trim) 11 208 219
348 11 $_[0] = $line;
349 }
350 }
351  
352 63 ▶sub _recursive_decode_json {
Subroutine _recursive_decode_json: called CC=1 SCAR=0.0
353 63 my ($self, $hash) = @_;
354  
355 174 ▶ Sub::Data::Recursive->invoke(sub {
Subroutine __ANON__: called CC=5 SCAR=16.2
356 174 ▶ if ($self->{_recursive_call} > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"_recursive_call"} > 0) 174 0 174
357 174 my $orig = $_[0];
358 174 ▶ return if $orig =~ m!^\[\d+\]$!;
Branch: 1 branch
BranchTrueFalseTotal
if $orig =~ /^\[\d+\]$/ 0 174 174
359 174 ▶ if (!_is_number($_[0])) {
Branch: 1 branch
BranchTrueFalseTotal
if (not _is_number($_[0])) 149 25 174
360 149 my $decoded = eval {
361 149 $self->{_json}->decode($orig);
362 };
363 149 ▶ if (!$@) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $@) 39 110 149
364 39 $_[0] = $decoded;
365 39 $self->{_recursive_call}--;
366 39 $self->_recursive_decode_json($_[0]); # recursive calling
367 }
368 }
369 }
370 63 } => $hash);
371 }
372  
373 # copied from Data::Recursive::Encode
374 174 ▶sub _is_number {
Subroutine _is_number: called CC=4 SCAR=14.0
375 174 my $value = shift;
376 174 ▶ return 0 unless defined $value;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value 0 174 174
377  
378 174 my $b_obj = B::svref_2object(\$value);
379 174 my $flags = $b_obj->FLAGS;
380 174 ▶ return $flags & ( B::SVp_IOK | B::SVp_NOK ) && !( $flags & B::SVp_POK ) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$flags & 12288 && !($flags & 16384) ? : 25 149 174
Condition66%2/3
$flags & 12288 and not $flags & 16384
!ll&&!rl&&r
149025
MC/DC50%1/2
$flags & 12288 and not $flags & 16384
$flags & 12288 not $flags & 16384
Truth table66%2/3
A and not(B)
A= $flags & 12288B= not $flags & 16384
ABresult
0X0
100
111
381 }
382  
383 39 ▶sub _parse_opt {
Subroutine _parse_opt: called CC=6 SCAR=17.9
384 39 my ($class, @argv) = @_;
385  
386 39 my $opt = {};
387  
388 GetOptionsFromArray(
389 \@argv,
390 'no-pretty' => \$opt->{no_pretty},
391 'x' => \$opt->{x},
392 'xx' => \$opt->{xx},
393 'xxx' => \$opt->{xxx},
394 'xxxx' => \$opt->{xxxx},
395 'X|xxxxx' => \$opt->{xxxxx},
396 'timestamp-key=s' => \$opt->{timestamp_key},
397 'gmtime' => \$opt->{gmtime},
398 'g|grep=s@' => \$opt->{grep},
399 'ignore=s@' => \$opt->{ignore},
400 'yaml|yml' => \$opt->{yaml},
401 'unbuffered' => \$opt->{unbuffered},
402 'stderr' => \$opt->{stderr},
403 'sweep' => \$opt->{sweep},
404 2 ▶ 'h|help' => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
405 2 $class->_show_usage(1);
406 },
407 2 ▶ 'v|version' => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
408 2 print "$0 $VERSION\n";
409 2 exit 1;
410 },
411 39 ▶ ) or $class->_show_usage(2);
Branch: 1 branch
BranchTrueFalseTotal
&GetOptionsFromArray(\@argv, "no-pretty", \$opt->{"no_pretty"}, "x", \$opt->{"x"}, "xx", \$opt->{"xx"}, "xxx", \$opt->{"xxx"}, "xxxx", \$opt->{"xxxx"}, "X|xxxxx", \$opt->{"xxxxx"}, "timestamp-key=s", \$opt->{"timestamp_key"}, "gmtime", \$opt->{"gmtime"}, "g|grep=s\@", \$opt->{"grep"}, "ignore=s\@", \$opt->{"ignore"}, "yaml|yml", \$opt->{"yaml"}, "unbuffered", \$opt->{"unbuffered"}, "stderr", \$opt->{"stderr"}, "sweep", \$opt->{"sweep"}, "h|help", sub { $class->_show_usage(1); } , "v|version", sub { print "$0 $VERSION\n"; exit 1; } ) or $class->_show_usage(2) 35 0 35
412  
413 35 ▶ $opt->{xxxx} ||= $opt->{xxxxx};
Condition100%3/3
$opt->{"xxxx"} ||= $opt->{"xxxxx"}
l!l&&r!l&&!r
3824
MC/DC100%2/2
$opt->{"xxxx"} ||= $opt->{"xxxxx"}
$opt->{"xxxx"} $opt->{"xxxxx"}
Truth table100%3/3
A ||= B
A= $opt->{"xxxx"}B= $opt->{"xxxxx"}
ABresult
1X1
011
000
414 35 ▶ $opt->{xxx} ||= $opt->{xxxx};
Condition100%3/3
$opt->{"xxx"} ||= $opt->{"xxxx"}
l!l&&r!l&&!r
21122
MC/DC100%2/2
$opt->{"xxx"} ||= $opt->{"xxxx"}
$opt->{"xxx"} $opt->{"xxxx"}
Truth table100%3/3
A ||= B
A= $opt->{"xxx"}B= $opt->{"xxxx"}
ABresult
1X1
011
000
415 35 ▶ $opt->{xx} ||= $opt->{xxx};
Condition100%3/3
$opt->{"xx"} ||= $opt->{"xxx"}
l!l&&r!l&&!r
21320
MC/DC100%2/2
$opt->{"xx"} ||= $opt->{"xxx"}
$opt->{"xx"} $opt->{"xxx"}
Truth table100%3/3
A ||= B
A= $opt->{"xx"}B= $opt->{"xxx"}
ABresult
1X1
011
000
416 35 ▶ $opt->{x} ||= $opt->{xx};
Condition66%2/3
$opt->{"x"} ||= $opt->{"xx"}
l!l&&r!l&&!r
01520
MC/DC50%1/2
$opt->{"x"} ||= $opt->{"xx"}
$opt->{"x"} $opt->{"xx"}
Truth table66%2/3
A ||= B
A= $opt->{"x"}B= $opt->{"xx"}
ABresult
1X1
011
000
417  
418 35 $UNIXTIMESTAMP_KEY = $opt->{timestamp_key};
419  
420 35 $GMTIME = $opt->{gmtime};
421  
422 35 return $opt;
423 }
424  
425 3 ▶sub _show_usage {
Subroutine _show_usage: called CC=1 SCAR=0.0
426 3 my ($class, $exitval) = @_;
427  
428 3 require Pod::Usage;
429 3 Pod::Usage::pod2usage(-exitval => $exitval);
430 }
431  
432 9 1;
433  
434 __END__
↑ Summary script/jl »