| 1 | package TaskPipe::InterpParam; | ||||||||||||||
| 2 | |||||||||||||||
| 3 | 38 | ▶ | use Moose; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 4 | 38 | ▶ | use Try::Tiny; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 5 | 38 | ▶ | use Module::Runtime 'require_module'; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 6 | 38 | ▶ | use TaskPipe::InterpParam::Parts; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 7 | 38 | ▶ | use Log::Log4perl; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 8 | 38 | ▶ | use Data::Dumper; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 9 | |||||||||||||||
| 10 | 38 | has input => (is => 'rw', isa => 'HashRef'); | |||||||||||||
| 11 | 38 | has input_history => (is => 'rw', isa => 'ArrayRef'); | |||||||||||||
| 12 | 38 | has param => (is => 'rw', isa => 'HashRef'); | |||||||||||||
| 13 | 38 | 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 | 38 | }); | |||||||||||||
| 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
| |||||||||||||||
| 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
| |||||||||||||||
| 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
| |||||||||||||||
| 85 | |||||||||||||||
| 86 | 0 | ▶ | $self->parts->param_key( $key ) if $key; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 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
| |||||||||||||||
| 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
| |||||||||||||||
| 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 | 38 | __PACKAGE__->meta->make_immutable; | |||||||||||||
| 143 | 38 | 1; | |||||||||||||
| 144 | |||||||||||||||