auto/share/dist/App-git-hub/lib/git-hub.d/json.pl untested

filter: Statementstmt 0.0% 0 / 26 Branchbran 0.0% 0 / 8 Conditioncond 0.0% 0 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 0.0% 0 / 2 Podpod 0.0% 0 / 1 totaltotal 0.0% 0 / 40 CC 3 SCAR 22.5
CC
3
Cov
0%
walk
12.0
BEGIN
2.0
CRAP 9.5
1 use strict;
2  
3 my $JSON;
4 for ( qw/JSON::MaybeXS JSON JSON::PP/ ) {
5 last if $JSON = eval "use $_; '$_'";
6 }
7  
8 $JSON or die <<'...';
9  
10 ERROR: No JSON Perl modules are installed.
11  
12 This Perl program is being used to speed up the 'git-hub' command. It requires
13 one of the 'JSON::MaybeXS', 'JSON' or 'JSON::PP' Perl modules, but it seems
14 that you have none of these installed.
15  
16 Please install the 'JSON::MaybeXS' module from CPAN, and try again.
17  
18 ...
19  
20 {
21 my $data = decode_json(do {local $/; <>});
22 die "Unknown JSON result" unless
23 ref($data) =~ /^(HASH|ARRAY)$/;
24 walk($data, '');
25 };
26  
27 sub walk {
28 my ($node, $path) = @_;
29 if (ref($node) eq 'HASH') {
30 for my $key (keys %$node) {
31 walk($node->{$key}, "$path/$key");
32 }
33 }
34 elsif (ref($node) eq 'ARRAY') {
35 for (my $i = 0; $i < @$node; $i++) {
36 walk($node->[$i], "$path/$i");
37 }
38 }
39 else {
40 my $value = encode_json([$node]);
41 print "$path\t", substr($value,1,-1), "\n";
42 }
43 }