blib/lib/App/NDTools/NDProc/Module/Insert.pm

filter: Statementstmt 98.3% 59 / 60 Branchbran 100% 16 / 16 Conditioncond 100% 6 / 6 MC/DCmcdc 100% 4 / 4 Subroutinesub 94.7% 18 / 19 Podpod 0.0% 0 / 5 totaltotal 93.6% 103 / 110 CC 11 SCAR 8.1
CC
11
Cov
99%
__ANON__
5.0
check_rule
3.0
configure
3.0
CRAP 2.2
« blib/lib/App/NDTools/NDProc/Module/Pipe.pm ↑ Summary blib/lib/App/NDTools/INC.pm »
1 package App::NDTools::NDProc::Module::Insert;
2  
3 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 4 ▶use warnings FATAL => 'all';
Subroutine BEGIN: called CC=1 SCAR=0.0
5 4 ▶use parent 'App::NDTools::NDProc::Module';
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 4 ▶use Log::Log4Cli;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 4 ▶use Scalar::Util qw(looks_like_number);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 4 ▶use Struct::Path 0.80 qw(path);
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 4 ▶use App::NDTools::Util qw(chomp_evaled_error);
Subroutine BEGIN: called CC=1 SCAR=0.0
12 4 ▶use App::NDTools::Slurp qw(s_decode);
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 4 our $VERSION = '0.20';
15  
16 1 ▶sub MODINFO { "Insert value into structure" }
Subroutine MODINFO: called CC=1 SCAR=0.0
Pod undocumented
17  
18 35 ▶sub arg_opts {
Subroutine arg_opts: called CC=1 SCAR=0.0
Pod undocumented
19 35 my $self = shift;
20  
21 return (
22 $self->SUPER::arg_opts(),
23 10 ▶ 'boolean=s' => sub {
Subroutine __ANON__: called CC=5 SCAR=16.1
24 10 ▶ if ($_[1] eq '1' or $_[1] =~ /^(T|t)rue$/) {
Branch: 2 branches
BranchTrueFalseTotal
if ($_[1] eq '1' or $_[1] =~ /^(T|t)rue$/) { } 3 7 10
elsif ($_[1] eq '0' or $_[1] =~ /^(F|f)alse$/) { } 3 4 7
Condition100%3/3
$_[1] eq 1 or $_[1] =~ /^(T|t)rue$/
l!l&&r!l&&!r
127
MC/DC100%2/2
$_[1] eq 1 or $_[1] =~ /^(T|t)rue$/
$_[1] eq 1 $_[1] =~ /^(T|t)rue$/
Truth table100%3/3
A or B
A= $_[1] eq 1B= $_[1] =~ /^(T|t)rue$/
ABresult
1X1
011
000
25 3 $self->{OPTS}->{value} = JSON::true;
26 ▶ } elsif ($_[1] eq '0' or $_[1] =~ /^(F|f)alse$/) {
Condition100%3/3
$_[1] eq 0 or $_[1] =~ /^(F|f)alse$/
l!l&&r!l&&!r
124
MC/DC100%2/2
$_[1] eq 0 or $_[1] =~ /^(F|f)alse$/
$_[1] eq 0 $_[1] =~ /^(F|f)alse$/
Truth table100%3/3
A or B
A= $_[1] eq 0B= $_[1] =~ /^(F|f)alse$/
ABresult
1X1
011
000
27 3 $self->{OPTS}->{value} = JSON::false;
28 } else {
29 4 $self->{ARG_ERROR} = "Unsuitable value for --boolean";
30 4 die "!FINISH";
31 }
32 },
33 'file|f=s' => \$self->{OPTS}->{file},
34 'file-fmt=s' => \$self->{OPTS}->{'file-fmt'},
35 2 ▶ 'null|undef' => sub { $self->{OPTS}->{value} = undef },
Subroutine __ANON__: called CC=1 SCAR=0.0
36 6 ▶ 'number=s' => sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
37 6 ▶ if (looks_like_number($_[1])) {
Branch: 1 branch
BranchTrueFalseTotal
if (&looks_like_number($_[1])) { } 5 1 6
38 5 $self->{OPTS}->{value} = 0 + $_[1];
39 } else {
40 1 $self->{ARG_ERROR} = "Unsuitable value for --number";
41 1 die "!FINISH";
42 }
43 },
44 8 ▶ 'string|value=s' => sub { $self->{OPTS}->{value} = $_[1] },
Subroutine __ANON__: called CC=1 SCAR=0.0
45 'structure=s' => \$self->{OPTS}->{structure},
46 )
47 35 }
48  
49 26 ▶sub check_rule {
Subroutine check_rule: called CC=3 SCAR=11.0
Pod undocumented
50 26 my ($self, $rule) = @_;
51 26 my $out = $self;
52  
53 26 ▶ unless (exists $rule->{value}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $rule->{"value"}) 1 25 26
54 1 ▶ log_error { "Value to insert should be defined" };
Subroutine __ANON__: called CC=1 SCAR=0.0
55 1 $out = undef;
56 }
57  
58 26 ▶ push @{$rule->{path}}, '' unless (@{$rule->{path}});
Branch: 1 branch
BranchTrueFalseTotal
unless @{$rule->{"path"};} 1 25 26
59  
60 26 return $out;
61 }
62  
63 87 ▶sub configure {
Subroutine configure: called CC=3 SCAR=11.0
Pod undocumented
64 87 my $self = shift;
65  
66 $self->{OPTS}->{value} =
67 s_decode(delete $self->{OPTS}->{structure}, 'JSON')
68 87 ▶ if (defined $self->{OPTS}->{structure});
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"OPTS"}{"structure"} 2 85 87
69  
70 $self->{OPTS}->{value} =
71 $self->load_struct($self->{OPTS}->{file}, $self->{OPTS}->{'file-fmt'})
72 86 ▶ if (defined $self->{OPTS}->{file});
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"OPTS"}{"file"} 3 83 86
73 }
74  
75 26 ▶sub process_path {
Subroutine process_path: called CC=2 SCAR=7.0
Pod undocumented
76 26 my ($self, $data, $path, $spath, $opts) = @_;
77  
78 0 ▶ log_info { 'Updating path "' . $path . '"' };
Subroutine __ANON__: not called CC=1 SCAR=1.2
79 26 eval { path(${$data}, $spath, assign => $opts->{value}, expand => 1) };
80 26 ▶ die_fatal "Failed to lookup path '$path' (" .
Branch: 1 branch
BranchTrueFalseTotal
if $@ 1 25 26
81 chomp_evaled_error($@) . ")", 4 if ($@);
82 }
83  
84  
85 4 1; # End of App::NDTools::NDProc::Module::Insert
86  
87 __END__
« blib/lib/App/NDTools/NDProc/Module/Pipe.pm ↑ Summary blib/lib/App/NDTools/INC.pm »