blib/lib/App/NDTools/NDPatch.pm

filter: Statementstmt 97.9% 48 / 49 Branchbran 66.6% 4 / 6 Conditioncond 66.6% 2 / 3 MC/DCmcdc 50.0% 1 / 2 Subroutinesub 92.8% 13 / 14 Podpod 0.0% 0 / 7 totaltotal 83.9% 68 / 81 CC 5 SCAR 4.5
CC
5
Cov
93%
check_args
3.0
patch
2.0
exec
2.0
CRAP 1.6
« blib/lib/App/NDTools/NDProc/Module/JsonMergePatch.pm ↑ Summary blib/lib/App/NDTools/Util.pm »
1 package App::NDTools::NDPatch;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings FATAL => 'all';
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use parent 'App::NDTools::NDTool';
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 1 ▶use App::NDTools::Slurp qw(s_dump);
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use Log::Log4Cli;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use Struct::Diff 0.96 qw();
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 1 our $VERSION = '0.09';
12  
13 7 ▶sub arg_opts {
Subroutine arg_opts: called CC=1 SCAR=0.0
Pod undocumented
14 7 my $self = shift;
15  
16 return (
17 7 $self->SUPER::arg_opts(),
18 );
19 }
20  
21 5 ▶sub check_args {
Subroutine check_args: called CC=3 SCAR=11.0
Pod undocumented
22 5 my $self = shift;
23  
24 die_fatal "One or two arguments expected", 1
25 5 ▶ if (@{$self->{ARGV}} < 1 or @{$self->{ARGV}} > 2);
Branch: 1 branch
BranchTrueFalseTotal
if @{$self->{"ARGV"};} < 1 or @{$self->{"ARGV"};} > 2 1 4 5
Condition66%2/3
@{$self->{"ARGV"};} < 1 or @{$self->{"ARGV"};} > 2
l!l&&r!l&&!r
104
MC/DC50%1/2
@{$self->{"ARGV"};} < 1 or @{$self->{"ARGV"};} > 2
@{$self->{"ARGV"};} < 1 @{$self->{"ARGV"};} > 2
Truth table66%2/3
A or B
A= @{$self->{"ARGV"};} < 1B= @{$self->{"ARGV"};} > 2
ABresult
1X1
011
000
26  
27 4 return $self;
28 }
29  
30 7 ▶sub defaults {
Subroutine defaults: called CC=1 SCAR=0.0
Pod undocumented
31 7 my $self = shift;
32  
33 return {
34 7 %{$self->SUPER::defaults()},
35 };
36 }
37  
38 4 ▶sub dump {
Subroutine dump: called CC=1 SCAR=0.2
Pod undocumented
39 4 my ($self, $uri, $struct) = @_;
40  
41 0 ▶ log_debug { "Restoring structure to '$uri'" };
Subroutine __ANON__: not called CC=1 SCAR=1.2
42 s_dump($uri, $self->{OPTS}->{ofmt},
43 4 {pretty => $self->{OPTS}->{pretty}}, $struct);
44 }
45  
46 4 ▶sub exec {
Subroutine exec: called CC=2 SCAR=6.9
Pod undocumented
47 4 my $self = shift;
48  
49 4 my $uri = shift @{$self->{ARGV}};
50 4 my $struct = $self->load_struct($uri, $self->{OPTS}->{ifmt});
51 my $patch = $self->load_patch(
52 4 @{$self->{ARGV}} ? shift @{$self->{ARGV}} : \*STDIN,
53 $self->{OPTS}->{ifmt}
54 4 ▶ );
Branch: 1 branch
BranchTrueFalseTotal
@{$self->{'ARGV'};} ? : 4 0 4
55  
56 4 $self->patch($struct, $patch);
57 4 $self->dump($uri, $struct);
58  
59 4 die_info "All done", 0;
60 }
61  
62 4 ▶sub load_patch {
Subroutine load_patch: called CC=1 SCAR=0.0
Pod undocumented
63 4 shift->load_struct(@_);
64 }
65  
66 4 ▶sub patch {
Subroutine patch: called CC=2 SCAR=7.0
Pod undocumented
67 4 my ($self, $struct, $patch) = @_;
68  
69 4 eval { Struct::Diff::patch($struct, $patch) };
70 4 ▶ die_fatal "Failed to patch structure ($@)", 8 if ($@);
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 4 4
71 }
72  
73 1 1; # End of App::NDTools::NDPatch
« blib/lib/App/NDTools/NDProc/Module/JsonMergePatch.pm ↑ Summary blib/lib/App/NDTools/Util.pm »