| 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
Condition100%3/3
$_[1] eq 1 or $_[1] =~ /(T|t)rue/
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/
| |||||||||||||||||||||||||||||||||
| 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/
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/
| |||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||
| 78 | 4 | 1; # End of App::NDTools::NDProc::Module::Insert | |||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||
| 80 | __END__ | ||||||||||||||||||||||||||||||||