blib/lib/App/NDTools/NDTool.pm

filter: Statementstmt 98.9% 95 / 96 Branchbran 90.9% 20 / 22 Conditioncond 100% 3 / 3 MC/DCmcdc 100% 2 / 2 Subroutinesub 95.2% 20 / 21 Podpod 0.0% 0 / 9 totaltotal 91.5% 140 / 153 CC 16 SCAR 13.1
CC
16
Cov
98%
grep
8.0
new
6.0
__ANON__
3.7
CRAP 3.7
« blib/lib/App/NDTools/NDQuery.pm ↑ Summary blib/lib/App/NDTools/NDProc/Module.pm »
1 package App::NDTools::NDTool;
2  
3 22 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 22 ▶use warnings FATAL => 'all';
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 22 ▶use App::NDTools::INC;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 22 ▶use App::NDTools::Slurp qw(s_dump s_load);
Subroutine BEGIN: called CC=1 SCAR=0.0
8 22 ▶use Encode::Locale;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 22 ▶use Encode qw(decode);
Subroutine BEGIN: called CC=1 SCAR=0.0
10 22 ▶use Getopt::Long qw(GetOptionsFromArray :config bundling noignore_case);
Subroutine BEGIN: called CC=1 SCAR=0.0
11 22 ▶use Log::Log4Cli;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 22 ▶use Struct::Path 0.80 qw(path);
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 22 our $VERSION = '0.34';
15  
16 257 ▶sub arg_opts {
Subroutine arg_opts: called CC=1 SCAR=0.0
Pod undocumented
17 257 my $self = shift;
18  
19 return (
20 'dump-opts' => \$self->{OPTS}->{'dump-opts'},
21 4 ▶ 'help|h' => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
22 4 $self->{OPTS}->{help} = 1;
23 4 die "!FINISH";
24 },
25 'ifmt=s' => \$self->{OPTS}->{ifmt},
26 'ofmt=s' => \$self->{OPTS}->{ofmt},
27 'pretty!' => \$self->{OPTS}->{pretty},
28 'verbose|v:+' => \$Log::Log4Cli::LEVEL,
29 4 ▶ 'version|V' => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
30 4 $self->{OPTS}->{version} = 1;
31 4 die "!FINISH";
32 },
33 257 );
34 }
35  
36 99 ▶sub check_args {
Subroutine check_args: called CC=3 SCAR=11.0
Pod undocumented
37 99 my $self = shift;
38  
39 die_fatal 'At least one argument expected', 1
40 99 ▶ unless (@_ or $self->{OPTS}->{'dump-opts'});
Branch: 1 branch
BranchTrueFalseTotal
unless @_ or $self->{"OPTS"}{"dump-opts"} 1 98 99
Condition100%3/3
@_ or $self->{"OPTS"}{"dump-opts"}
l!l&&r!l&&!r
9711
MC/DC100%2/2
@_ or $self->{"OPTS"}{"dump-opts"}
@_ $self->{"OPTS"}{"dump-opts"}
Truth table100%3/3
A or B
A= @_B= $self->{"OPTS"}{"dump-opts"}
ABresult
1X1
011
000
41  
42 98 return $self;
43 }
44  
45 134 ▶sub configure {
Subroutine configure: called CC=1 SCAR=0.0
Pod undocumented
46 134 my $self = shift;
47  
48 134 return $self->check_args(@{$self->{ARGV}});
49 }
50  
51 142 ▶sub defaults {
Subroutine defaults: called CC=1 SCAR=0.0
Pod undocumented
52 return {
53 142 'ofmt' => 'JSON',
54 'pretty' => 1,
55 'verbose' => $Log::Log4Cli::LEVEL,
56 };
57 }
58  
59 1 ▶sub dump_opts {
Subroutine dump_opts: called CC=1 SCAR=0.0
Pod undocumented
60 1 my $self = shift;
61  
62 1 delete $self->{OPTS}->{'dump-opts'};
63 1 s_dump(\*STDOUT, undef, undef, $self->{OPTS});
64 }
65  
66 15 ▶sub grep {
Subroutine grep: called CC=8 SCAR=20.8
Pod undocumented
67 15 my ($self, $spaths, @structs) = @_;
68 15 my @out;
69  
70 15 for my $struct (@structs) {
71 15 my (%map_idx, $path, $ref, $grepped);
72  
73 15 for (@{$spaths}) {
74 19 my @found = eval { path($struct, $_, deref => 1, paths => 1) };
75  
76 19 ▶ while (($path, $ref) = splice @found, 0, 2) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = splice(@found, 0, 2)) 34 19 53
77 # remap array's indexes
78 34 my $map_key = "";
79 34 my $map_path = [];
80  
81 34 for my $step (@{$path}) {
82 104 ▶ if (ref $step eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $step eq 'ARRAY') { } 52 52 104
83 52 $map_key .= "[]";
84 52 ▶ unless (exists $map_idx{$map_key}->{$step->[0]}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $map_idx{$map_key}{$step->[0]}) 37 15 52
85 $map_idx{$map_key}->{$step->[0]} =
86 37 keys %{$map_idx{$map_key}};
87 }
88  
89 52 push @{$map_path}, [$map_idx{$map_key}->{$step->[0]}];
90 } else { # HASH
91 52 $map_key .= "{$step->{K}->[0]}";
92 52 push @{$map_path}, $step;
93 }
94 }
95  
96 34 path($grepped, $map_path, assign => $ref, expand => 1);
97 }
98 }
99  
100 15 ▶ push @out, $grepped if (defined $grepped);
Branch: 1 branch
BranchTrueFalseTotal
if defined $grepped 13 2 15
101 }
102  
103 15 return @out;
104 }
105  
106 356 ▶sub load_struct {
Subroutine load_struct: called CC=1 SCAR=1.2
Pod undocumented
107 356 my ($self, $uri, $fmt) = @_;
108  
109 0 ▶ log_trace { ref $uri ? "Reading from STDIN" : "Loading '$uri'" };
Subroutine __ANON__: not called CC=2 SCAR=13.0
Branch: 1 branch
BranchTrueFalseTotal
ref $uri ? : 0 0 0
110 356 s_load($uri, $fmt);
111 }
112  
113 256 ▶sub new {
Subroutine new: called CC=6 SCAR=17.9
Pod undocumented
114 256 my $self = bless {}, shift;
115  
116 256 $self->{OPTS} = $self->defaults();
117 $self->{ARGV} =
118 256 ▶ [ map { decode(locale => "$_", Encode::FB_CROAK) } @_ ? @_ : @ARGV ];
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 251 5 256
119  
120 256 $self->{TTY} = -t STDOUT;
121  
122 256 ▶ unless (GetOptionsFromArray ($self->{ARGV}, $self->arg_opts)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (&GetOptionsFromArray($self->{"ARGV"}, $self->arg_opts)) 1 255 256
123 1 $self->usage;
124 1 die_fatal "Unsupported opts used", 1;
125 }
126  
127 255 ▶ if ($self->{OPTS}->{help}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"OPTS"}{"help"}) 4 251 255
128 4 $self->usage;
129 4 die_info, 0;
130 }
131  
132 251 ▶ if ($self->{OPTS}->{version}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"OPTS"}{"version"}) 4 247 251
133 4 print $self->VERSION . "\n";
134 4 die_info, 0;
135 }
136  
137 247 $self->configure();
138  
139 241 ▶ if ($self->{OPTS}->{'dump-opts'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"OPTS"}{"dump-opts"}) 1 240 241
140 1 $self->dump_opts();
141 1 die_info, 0;
142 }
143  
144 240 return $self;
145 }
146  
147 6 ▶sub usage {
Subroutine usage: called CC=1 SCAR=0.0
Pod undocumented
148 6 require Pod::Usage;
149 6 Pod::Usage::pod2usage(
150 -exitval => 'NOEXIT',
151 -output => \*STDERR,
152 -sections => 'SYNOPSIS|OPTIONS|EXAMPLES',
153 -verbose => 99
154 );
155 }
156  
157 22 1; # End of App::NDTools::NDTool
« blib/lib/App/NDTools/NDQuery.pm ↑ Summary blib/lib/App/NDTools/NDProc/Module.pm »