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

filter: Statementstmt 87.9% 51 / 58 Branchbran 71.4% 10 / 14 Conditioncond 83.3% 5 / 6 MC/DCmcdc 50.0% 2 / 4 Subroutinesub 85.0% 17 / 20 Podpod 0.0% 0 / 5 totaltotal 79.4% 85 / 107 CC 10 SCAR 8.6
CC
10
Cov
85%
__ANON__
5.8
process_path
3.1
__ANON__
2.7
CRAP 2.4
« blib/lib/App/NDTools/NDProc/Module/Remove.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 4 ▶use Struct::Path::PerlStyle 0.80 qw(str2path);
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 4 our $VERSION = '0.13';
13  
14 1 ▶sub MODINFO { "Insert value into structure" }
Subroutine MODINFO: called CC=1 SCAR=0.0
Pod undocumented
15  
16 sub arg_opts {
17 21 ▶ my $self = shift;
Subroutine arg_opts: called CC=1 SCAR=0.4
Pod undocumented
18  
19 return (
20 $self->SUPER::arg_opts(),
21 'boolean=s' => sub {
22 6 ▶ if ($_[1] eq '1' or $_[1] =~ /(T|t)rue/) {
Subroutine __ANON__: called CC=5 SCAR=17.5
Branch: 2 branches
BranchTrueFalseTotal
if ($_[1] eq '1' or $_[1] =~ /(T|t)rue/) { } 3 3 6
elsif ($_[1] eq '0' or $_[1] =~ /(F|f)alse/) { } 3 0 3
Condition100%3/3
$_[1] eq 1 or $_[1] =~ /(T|t)rue/
l!l&&r!l&&!r
123
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
23 3 $self->{OPTS}->{value} = JSON::true;
24 ▶ } elsif ($_[1] eq '0' or $_[1] =~ /(F|f)alse/) {
Condition66%2/3
$_[1] eq 0 or $_[1] =~ /(F|f)alse/
l!l&&r!l&&!r
120
MC/DC0%0/2
$_[1] eq 0 or $_[1] =~ /(F|f)alse/
$_[1] eq 0 $_[1] =~ /(F|f)alse/
Truth table66%2/3
A or B
A= $_[1] eq 0B= $_[1] =~ /(F|f)alse/
ABresult
1X1
011
000
25 3 $self->{OPTS}->{value} = JSON::false;
26 } else {
27 0 ▶ log_error { "Unsuitable value for --boolean" };
Subroutine __ANON__: not called CC=1 SCAR=6.9
28 0 exit 1;
29 }
30 },
31 'file|f=s' => \$self->{OPTS}->{file},
32 'file-fmt=s' => \$self->{OPTS}->{'file-fmt'},
33 2 ▶ 'null|undef' => sub { $self->{OPTS}->{value} = undef },
Subroutine __ANON__: called CC=1 SCAR=0.0
34 'number=s' => sub {
35 5 ▶ if (looks_like_number($_[1])) {
Subroutine __ANON__: called CC=2 SCAR=10.1
Branch: 1 branch
BranchTrueFalseTotal
if (&looks_like_number($_[1])) { } 5 0 5
36 5 $self->{OPTS}->{value} = 0 + $_[1];
37 } else {
38 0 ▶ log_error { "Unsuitable value for --number" };
Subroutine __ANON__: not called CC=1 SCAR=6.9
39 0 exit 1;
40 }
41 },
42 4 ▶ 'string|value=s' => sub { $self->{OPTS}->{value} = $_[1] },
Subroutine __ANON__: called CC=1 SCAR=0.0
43 )
44 21 }
45  
46 sub check_rule {
47 23 ▶ my ($self, $rule) = @_;
Subroutine check_rule: called CC=2 SCAR=6.9
Pod undocumented
48 23 my $out = $self;
49  
50 23 ▶ unless (exists $rule->{value}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $rule->{"value"}) 1 22 23
51 1 ▶ log_error { "Value to insert should be defined" };
Subroutine __ANON__: called CC=1 SCAR=0.0
52 1 $out = undef;
53 }
54  
55 23 return $out;
56 }
57  
58 sub configure {
59 65 ▶ my $self = shift;
Subroutine configure: called CC=2 SCAR=6.9
Pod undocumented
60  
61 $self->{OPTS}->{value} =
62 $self->load_struct($self->{OPTS}->{file}, $self->{OPTS}->{'file-fmt'})
63 65 ▶ if (defined $self->{OPTS}->{file});
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"OPTS"}{"file"} 3 62 65
64 }
65  
66 sub process_path {
67 22 ▶ my ($self, $data, $path, $opts) = @_;
Subroutine process_path: called CC=3 SCAR=11.3
Pod undocumented
68  
69 22 my $spath = eval { str2path($path) };
70 22 ▶ die_fatal "Failed to parse path ($@)", 4 if ($@);
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 22 22
71  
72 22 ▶ log_info { 'Updating path "' . $path . '"' };
Subroutine __ANON__: not called CC=1 SCAR=1.2
73 22 eval { path(${$data}, $spath, assign => $opts->{value}, expand => 1) };
74 22 ▶ die_fatal "Failed to lookup path '$path' ($@)", 4 if ($@);
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 22 22
75 }
76  
77  
78 4 1; # End of App::NDTools::NDProc::Module::Insert
79  
80 __END__
« blib/lib/App/NDTools/NDProc/Module/Remove.pm ↑ Summary blib/lib/App/NDTools/INC.pm »