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

filter: Statementstmt 88.3% 76 / 86 Branchbran 85.7% 12 / 14 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 76.9% 20 / 26 Podpod 0.0% 0 / 12 totaltotal 78.2% 108 / 138 CC 10 SCAR 7.7
CC
10
Cov
88%
process
5.0
stash_preserved
4.0
parse_args
2.2
CRAP 2.1
« blib/lib/App/NDTools/INC.pm ↑ Summary blib/lib/App/NDTools.pm »
1 package App::NDTools::NDProc::Module;
2  
3 # base class for ndproc modules
4  
5 10 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 10 ▶use warnings FATAL => 'all';
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 10 ▶use App::NDTools::INC;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 10 ▶use App::NDTools::NDTool;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 10 ▶use Getopt::Long qw(GetOptionsFromArray :config bundling pass_through);
Subroutine BEGIN: called CC=1 SCAR=0.0
11 10 ▶use Log::Log4Cli;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 10 ▶use Storable qw(dclone);
Subroutine BEGIN: called CC=1 SCAR=0.0
13 10 ▶use Struct::Path 0.80 qw(path);
Subroutine BEGIN: called CC=1 SCAR=0.0
14 10 ▶use Struct::Path::PerlStyle 0.80 qw(str2path path2str);
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 0 ▶sub MODINFO { "n/a" }
Subroutine MODINFO: not called CC=1 SCAR=6.9
Pod undocumented
17  
18 sub arg_opts {
19 59 ▶ my $self = shift;
Subroutine arg_opts: called CC=1 SCAR=2.6
Pod undocumented
20  
21 return (
22 'blame!' => \$self->{OPTS}->{blame}, # just to set opt in rule
23 0 ▶ 'help|h' => sub { $self->usage(); exit 0 },
Subroutine __ANON__: not called CC=1 SCAR=6.9
24 'path=s@' => \$self->{OPTS}->{path},
25 'preserve=s@' => \$self->{OPTS}->{preserve},
26 0 ▶ 'version|V' => sub { print $self->VERSION . "\n"; exit 0 },
Subroutine __ANON__: not called CC=1 SCAR=6.9
27 )
28 59 }
29  
30 sub check_rule {
31 26 ▶ return $_[0];
Subroutine check_rule: called CC=1 SCAR=0.0
Pod undocumented
32 }
33  
34 sub configure {
35 74 ▶ return $_[0];
Subroutine configure: called CC=1 SCAR=0.0
Pod undocumented
36 }
37  
38 sub defaults {
39 return {
40 145 ▶ disabled => undef,
Subroutine defaults: called CC=1 SCAR=0.0
Pod undocumented
41 path => [],
42 };
43 }
44  
45 sub get_opts {
46 38 ▶ return $_[0]->{OPTS};
Subroutine get_opts: called CC=1 SCAR=0.0
Pod undocumented
47 }
48  
49 10 *load_struct = \&App::NDTools::NDTool::load_struct;
50  
51 sub new {
52 145 ▶ my $self = bless {}, shift;
Subroutine new: called CC=1 SCAR=0.0
Pod undocumented
53  
54 145 $self->{OPTS} = $self->defaults();
55 145 $self->configure;
56  
57 145 return $self;
58 }
59  
60 sub parse_args {
61 59 ▶ my ($self, $args) = @_;
Subroutine parse_args: called CC=2 SCAR=7.9
Pod undocumented
62  
63 59 ▶ unless (GetOptionsFromArray ($args, $self->arg_opts)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (&GetOptionsFromArray($args, $self->arg_opts)) 0 59 59
64 0 $self->usage;
65 0 die_fatal "Unsupported opt passed", 1;
66 }
67 59 $self->configure;
68  
69 58 return $self;
70 }
71  
72 sub process {
73 80 ▶ my ($self, $data, $opts, $source) = @_;
Subroutine process: called CC=5 SCAR=16.1
Pod undocumented
74  
75 80 ▶ $self->check_rule($opts) or die_fatal undef, 1;
Branch: 1 branch
BranchTrueFalseTotal
$self->check_rule($opts) or &die_fatal(undef, 1) 2 78 80
76  
77 $self->stash_preserved($data, $opts->{preserve})
78 78 ▶ if ($opts->{preserve});
Branch: 1 branch
BranchTrueFalseTotal
if $opts->{"preserve"} 5 73 78
79  
80 78 for my $path (@{$opts->{path}}) {
81 80 ▶ log_debug { "Processing path '$path'" };
Subroutine __ANON__: not called CC=1 SCAR=1.2
82 80 $self->process_path($data, $path, $opts, $source);
83 }
84  
85 $self->restore_preserved($data)
86 72 ▶ if ($opts->{preserve});
Branch: 1 branch
BranchTrueFalseTotal
if $opts->{"preserve"} 5 67 72
87  
88 72 return $self;
89 }
90  
91 sub restore_preserved {
92 5 ▶ my ($self, $data) = @_;
Subroutine restore_preserved: called CC=2 SCAR=6.9
Pod undocumented
93  
94 5 ▶ while (@{$self->{_preserved}}) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$self->{"_preserved"};}) 15 5 20
95 15 my ($path, $value) = splice @{$self->{_preserved}}, 0, 2;
96 15 ▶ log_debug { "Restoring preserved '" . path2str($path) . "'" };
Subroutine __ANON__: not called CC=1 SCAR=1.2
97 15 path(${$data}, $path, assign => $value, expand => 1);
98 }
99  
100 5 return $self;
101 }
102  
103 sub stash_preserved {
104 5 ▶ my ($self, $data, $paths) = @_;
Subroutine stash_preserved: called CC=4 SCAR=13.9
Pod undocumented
105  
106 5 for my $path (@{$paths}) {
107 5 ▶ log_debug { "Preserving '$path'" };
Subroutine __ANON__: not called CC=1 SCAR=1.2
108 5 my $spath = eval { str2path($path) };
109 5 ▶ die_fatal "Failed to parse path ($@)", 4 if ($@);
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 5 5
110 5 push @{$self->{_preserved}},
111 30 ▶ map { $_ = ref $_ ? dclone($_) : $_ } # immutable now
Branch: 1 branch
BranchTrueFalseTotal
ref $_ ? : 15 15 30
112 5 path(${$data}, $spath, deref => 1, paths => 1);
113 }
114  
115 5 return $self;
116 }
117  
118 sub usage {
119 4 ▶ require Pod::Find;
Subroutine usage: called CC=1 SCAR=0.0
Pod undocumented
120 4 require Pod::Usage;
121  
122 4 Pod::Usage::pod2usage(
123 -exitval => 'NOEXIT',
124 -input => Pod::Find::pod_where({-inc => 1}, ref(shift)),
125 -output => \*STDERR,
126 -sections => 'NAME|DESCRIPTION|OPTIONS',
127 -verbose => 99
128 );
129 }
130  
131 10 1; # End of App::NDTools::NDProc::Module
« blib/lib/App/NDTools/INC.pm ↑ Summary blib/lib/App/NDTools.pm »