TaskPipe/InterpParam.pm

filter: Statementstmt 39.3% 26 / 66 Branchbran 0.0% 0 / 14 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 50.0% 7 / 14 Podpod 0.0% 0 / 5 totaltotal 33.3% 33 / 99 CC 10 SCAR 23.7
CC
10
Cov
32%
interp_string
30.0
interp_kv
12.0
interp_hash
12.0
CRAP 10.7
« TaskPipe/Tool/Options.pm ↑ Summary TaskPipe/OpenProxyManager.pm »
1 package TaskPipe::InterpParam;
2  
3 40 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 40 ▶use Try::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 40 ▶use Module::Runtime 'require_module';
Subroutine BEGIN: called CC=1 SCAR=0.0
6 40 ▶use TaskPipe::InterpParam::Parts;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 40 ▶use Log::Log4perl;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 40 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 40 has input => (is => 'rw', isa => 'HashRef');
11 40 has input_history => (is => 'rw', isa => 'ArrayRef');
12 40 has param => (is => 'rw', isa => 'HashRef');
13 40 has param_history => (is => 'rw', isa => 'ArrayRef');
14 has parts => (is => 'rw', isa => 'TaskPipe::InterpParam::Parts', default => sub{
15 1 ▶ TaskPipe::InterpParam::Parts->new;
Subroutine __ANON__: called CC=1 SCAR=0.0
16 40 });
17  
18  
19 sub interp{
20 0 ▶ my $self = shift;
Subroutine interp: not called CC=1 SCAR=6.9
Pod undocumented
21  
22 0 my @ih = ( $self->input, @{$self->input_history} );
23  
24 0 return +$self->interp_hash( $self->param );
25 }
26  
27  
28  
29 sub interp_kv{
30 0 ▶ my ($self,$key,$val) = @_;
Subroutine interp_kv: not called CC=3 SCAR=24.8
Pod undocumented
31  
32 0 my $interp;
33 0 ▶ if ( ref $val eq ref {} ){
Branch: 2 branches
BranchTrueFalseTotal
if (ref $val eq ref {}) { } 0 0 0
elsif (ref $val eq ref []) { } 0 0 0
34 0 $interp = $self->interp_hash( $val );
35 } elsif ( ref $val eq ref [] ){
36 0 $interp = $self->interp_array( $val );
37 } else {
38 0 $interp = $self->interp_string( $key, $val );
39 }
40 0 return $interp;
41 }
42  
43  
44
45  
46 sub interp_hash{
47 0 ▶ my ($self,$h) = @_;
Subroutine interp_hash: not called CC=3 SCAR=24.8
Pod undocumented
48  
49 0 my $interp = {};
50 0 foreach my $key (keys %$h){
51  
52 0 $key =~ s/^\s+//;
53 0 ▶ next if $key =~ /^_/;
Branch: 1 branch
BranchTrueFalseTotal
if $key =~ /^_/ 0 0 0
54 0 $key =~ s/\s+$//;
55
56 0 my $val = $h->{$key};
57  
58 0 $interp->{$key} = $self->interp_kv($key,$val);
59  
60 }
61  
62 0 return $interp;
63 }
64  
65  
66 sub interp_array{
67 0 ▶ my ($self,$arr) = @_;
Subroutine interp_array: not called CC=2 SCAR=17.9
Pod undocumented
68  
69 0 my $interp = [];
70 0 foreach my $val ( @$arr ){
71 0 push @$interp,+$self->interp_kv(undef,$val);
72 }
73 0 return $interp;
74 }
75  
76  
77  
78 sub interp_string{
79 0 ▶ my ($self,$key,$val) = @_;
Subroutine interp_string: not called CC=5 SCAR=34.0
Pod undocumented
80  
81 0 $val =~ s/^\s*//;
82 0 $val =~ s/\s*$//;
83  
84 0 ▶ return $val unless $val =~ m{^\$};
Branch: 1 branch
BranchTrueFalseTotal
unless $val =~ /^\$/ 0 0 0
85  
86 0 ▶ $self->parts->param_key( $key ) if $key;
Branch: 1 branch
BranchTrueFalseTotal
if $key 0 0 0
87 0 $self->parts->param_val( $val );
88 0 $self->parts->load;
89  
90 0 ▶ confess "Error in param set ".Dumper( $self->param ).": Could not determine a label key from '$val'" unless $self->parts->label_key;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->parts->label_key 0 0 0
91  
92 0 my $mh_module = __PACKAGE__.'::MatchHandler_'.$self->parts->label_key;
93  
94 try {
95  
96 0 ▶ require_module( $mh_module );
Subroutine __ANON__: not called CC=1 SCAR=6.9
97  
98 } catch {
99  
100 0 ▶ confess "Error in param set ".Dumper( $self->param ).": Failed to find a match handler for label '".$self->parts->label_key."': module $mh_module missing or broken. Error reported was: $_";
Subroutine __ANON__: not called CC=1 SCAR=6.9
101  
102 0 };
103  
104 0 my $mh = $mh_module->new(
105 input => $self->input,
106 input_history => $self->input_history,
107 param => $self->param,
108 param_history => $self->param_history,
109 parts => $self->parts
110 );
111  
112 0 ▶ confess "Error in param set ".Dumper( $self->param ).': Invalid format for variable $'.$self->parts->label_key unless $mh->format_valid;
Branch: 1 branch
BranchTrueFalseTotal
unless $mh->format_valid 0 0 0
113  
114 0 return $mh->interp;
115 }
116  
117  
118  
119 =head1 NAME
120  
121 TaskPipe::InterpParam - Parameter value interpolator for TaskPipe
122  
123 =head1 DESCRIPTION
124  
125 It is not recommended to use this module directly. See the general manpages for TaskPipe
126  
127 =head1 AUTHOR
128  
129 Tom Gracey <tomgracey@gmail.com>
130  
131 =head1 COPYRIGHT AND LICENSE
132  
133 Copyright (c) Tom Gracey 2018
134  
135 TaskPipe is free software, licensed under
136  
137 The GNU Public License Version 3
138  
139 =cut
140  
141  
142 40 __PACKAGE__->meta->make_immutable;
143 40 1;
144  
« TaskPipe/Tool/Options.pm ↑ Summary TaskPipe/OpenProxyManager.pm »