line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package App::NDTools::NDProc::Module::Insert; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
71062
|
use strict; |
|
2
|
|
|
|
|
9
|
|
|
2
|
|
|
|
|
66
|
|
4
|
2
|
|
|
2
|
|
10
|
use warnings FATAL => 'all'; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
66
|
|
5
|
2
|
|
|
2
|
|
550
|
use parent 'App::NDTools::NDProc::Module'; |
|
2
|
|
|
|
|
328
|
|
|
2
|
|
|
|
|
10
|
|
6
|
|
|
|
|
|
|
|
7
|
2
|
|
|
2
|
|
101
|
use Log::Log4Cli; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
159
|
|
8
|
2
|
|
|
2
|
|
11
|
use Scalar::Util qw(looks_like_number); |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
101
|
|
9
|
2
|
|
|
2
|
|
11
|
use Struct::Path 0.80 qw(path); |
|
2
|
|
|
|
|
34
|
|
|
2
|
|
|
|
|
92
|
|
10
|
2
|
|
|
2
|
|
12
|
use Struct::Path::PerlStyle 0.80 qw(str2path); |
|
2
|
|
|
|
|
26
|
|
|
2
|
|
|
|
|
1429
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
our $VERSION = '0.13'; |
13
|
|
|
|
|
|
|
|
14
|
0
|
|
|
0
|
0
|
0
|
sub MODINFO { "Insert value into structure" } |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub arg_opts { |
17
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
return ( |
20
|
|
|
|
|
|
|
$self->SUPER::arg_opts(), |
21
|
|
|
|
|
|
|
'boolean=s' => sub { |
22
|
0
|
0
|
0
|
0
|
|
0
|
if ($_[1] eq '1' or $_[1] =~ /(T|t)rue/) { |
|
|
0
|
0
|
|
|
|
|
23
|
0
|
|
|
|
|
0
|
$self->{OPTS}->{value} = JSON::true; |
24
|
|
|
|
|
|
|
} elsif ($_[1] eq '0' or $_[1] =~ /(F|f)alse/) { |
25
|
0
|
|
|
|
|
0
|
$self->{OPTS}->{value} = JSON::false; |
26
|
|
|
|
|
|
|
} else { |
27
|
0
|
|
|
|
|
0
|
log_error { "Unsuitable value for --boolean" }; |
|
0
|
|
|
|
|
0
|
|
28
|
0
|
|
|
|
|
0
|
exit 1; |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
}, |
31
|
|
|
|
|
|
|
'file|f=s' => \$self->{OPTS}->{file}, |
32
|
|
|
|
|
|
|
'file-fmt=s' => \$self->{OPTS}->{'file-fmt'}, |
33
|
0
|
|
|
0
|
|
0
|
'null|undef' => sub { $self->{OPTS}->{value} = undef }, |
34
|
|
|
|
|
|
|
'number=s' => sub { |
35
|
0
|
0
|
|
0
|
|
0
|
if (looks_like_number($_[1])) { |
36
|
0
|
|
|
|
|
0
|
$self->{OPTS}->{value} = 0 + $_[1]; |
37
|
|
|
|
|
|
|
} else { |
38
|
0
|
|
|
|
|
0
|
log_error { "Unsuitable value for --number" }; |
|
0
|
|
|
|
|
0
|
|
39
|
0
|
|
|
|
|
0
|
exit 1; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
}, |
42
|
0
|
|
|
0
|
|
0
|
'string|value=s' => sub { $self->{OPTS}->{value} = $_[1] }, |
43
|
|
|
|
|
|
|
) |
44
|
0
|
|
|
|
|
0
|
} |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub check_rule { |
47
|
2
|
|
|
2
|
0
|
7
|
my ($self, $rule) = @_; |
48
|
2
|
|
|
|
|
4
|
my $out = $self; |
49
|
|
|
|
|
|
|
|
50
|
2
|
50
|
|
|
|
7
|
unless (exists $rule->{value}) { |
51
|
0
|
|
|
0
|
|
0
|
log_error { "Value to insert should be defined" }; |
|
0
|
|
|
|
|
0
|
|
52
|
0
|
|
|
|
|
0
|
$out = undef; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
2
|
|
|
|
|
7
|
return $out; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
sub configure { |
59
|
2
|
|
|
2
|
0
|
4
|
my $self = shift; |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
$self->{OPTS}->{value} = |
62
|
|
|
|
|
|
|
$self->load_struct($self->{OPTS}->{file}, $self->{OPTS}->{'file-fmt'}) |
63
|
2
|
50
|
|
|
|
8
|
if (defined $self->{OPTS}->{file}); |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub process_path { |
67
|
2
|
|
|
2
|
0
|
6
|
my ($self, $data, $path, $opts) = @_; |
68
|
|
|
|
|
|
|
|
69
|
2
|
|
|
|
|
4
|
my $spath = eval { str2path($path) }; |
|
2
|
|
|
|
|
6
|
|
70
|
2
|
50
|
|
|
|
3486
|
die_fatal "Failed to parse path ($@)", 4 if ($@); |
71
|
|
|
|
|
|
|
|
72
|
2
|
|
|
0
|
|
12
|
log_info { 'Updating path "' . $path . '"' }; |
|
0
|
|
|
|
|
0
|
|
73
|
2
|
|
|
|
|
17
|
eval { path(${$data}, $spath, assign => $opts->{value}, expand => 1) }; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
8
|
|
74
|
2
|
50
|
|
|
|
311
|
die_fatal "Failed to lookup path '$path' ($@)", 4 if ($@); |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
1; # End of App::NDTools::NDProc::Module::Insert |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
__END__ |