Workflow/Config/Perl.pm

filter: Statementstmt 91.1% 72 / 79 Branchbran 72.2% 13 / 18 Conditioncond 66.6% 2 / 3 MC/DCmcdc 50.0% 1 / 2 Subroutinesub 85.7% 12 / 14 Podpod 100% 1 / 1 totaltotal 86.3% 101 / 117 CC 12 SCAR 13.3
CC
12
Cov
87%
parse
8.1
_translate_perl
3.2
_translate_perl_file
3.0
CRAP 3.8
« Workflow/Config/YAML.pm ↑ Summary Workflow/Base.pm »
1 package Workflow::Config::Perl;
2  
3 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 4 ▶use v5.14.0;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 4 ▶use parent qw( Workflow::Config );
Subroutine BEGIN: called CC=1 SCAR=0.0
7 4 ▶use Log::Any qw( $log );
Subroutine BEGIN: called CC=1 SCAR=0.0
8 4 ▶use Workflow::Exception qw( configuration_error );
Subroutine BEGIN: called CC=1 SCAR=0.0
9 4 ▶use Data::Dumper qw( Dumper );
Subroutine BEGIN: called CC=1 SCAR=0.0
10 4 ▶use English qw( -no_match_vars );
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 4 $Workflow::Config::Perl::VERSION = '2.12';
13  
14 27 ▶sub parse {
Subroutine parse: called CC=8 SCAR=21.0
Pod documented
15 27 my ( $self, $type, @items ) = @_;
16  
17 27 $self->_check_config_type($type);
18  
19 26 ▶ if ( !scalar @items ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (scalar @items) 1 25 26
20 1 return @items;
21 }
22  
23 25 my @config_items = Workflow::Config::_expand_refs(@items);
24 25 ▶ return () unless ( scalar @config_items );
Branch: 1 branch
BranchTrueFalseTotal
unless scalar @config_items 0 25 25
25  
26 25 my @config = ();
27 25 foreach my $item (@config_items) {
28 28 my ( $file_name, $method );
29 28 ▶ if ( ref $item ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $item) { } 0 28 28
30 0 $method = '_translate_perl';
31 0 $file_name = '[scalar ref]';
32 }
33  
34 # $item is a filename...
35 else {
36 28 $method = '_translate_perl_file';
37 28 $file_name = $item;
38 }
39 28 $log->info("Will parse '$type' Perl config file '$file_name'");
40 28 my $this_config = $self->$method( $type, $item );
41  
42 #warn "This config looks like:";
43 #warn Dumper (\$this_config);
44 26 $log->info("Parsed Perl '$file_name' ok");
45  
46 26 ▶ if ( exists $this_config->{'type'} ) {
Branch: 2 branches
BranchTrueFalseTotal
if (exists $this_config->{'type'}) { } 10 16 26
elsif ($type eq 'persister' and ref $this_config->{$type} eq 'ARRAY') { } 1 15 16
47 10 $log->debug("Adding typed configuration for '$type'");
48 10 push @config, $this_config;
49 ▶ } elsif ( $type eq 'persister'
Condition66%2/3
$type eq "persister" and ref $this_config->{$type} eq "ARRAY"
!ll&&!rl&&r
1501
MC/DC50%1/2
$type eq "persister" and ref $this_config->{$type} eq "ARRAY"
$type eq "persister" ref $this_config->{$type} eq "ARRAY"
Truth table66%2/3
A and B
A= $type eq "persister"B= ref $this_config->{$type} eq "ARRAY"
ABresult
0X0
100
111
50 and ref $this_config->{$type} eq 'ARRAY' )
51 {
52  
53 # This special exception for persister is required because
54 # the config design for persisters was different from the
55 # other config types. It didn't have a top level 'persister'
56 # element. For backward compatibility, I'm adding this
57 # exception here.
58 1 $log->debug("Adding multiple configurations for '$type'");
59 1 push @config, @{ $this_config->{$type} };
60 } else {
61 15 $log->debug("Adding single configuration for '$type'");
62 15 push @config, $this_config;
63 }
64 }
65 23 return @config;
66 }
67  
68 28 ▶sub _translate_perl_file {
Subroutine _translate_perl_file: called CC=3 SCAR=11.1
69 28 my ( $class, $type, $file ) = @_;
70  
71 28 local $INPUT_RECORD_SEPARATOR = undef;
72 28 ▶ open( CONF, '<', $file )
Branch: 1 branch
BranchTrueFalseTotal
open CONF, "<", $file or configuration_error("Cannot read file '${file}': $!") 26 2 28
73 || configuration_error "Cannot read file '$file': $!";
74 26 my $config = <CONF>;
75 26 ▶ close(CONF) || configuration_error "Cannot close file '$file': $!";
Branch: 1 branch
BranchTrueFalseTotal
close CONF or configuration_error("Cannot close file '${file}': $!") 26 0 26
76 26 my $data = $class->_translate_perl( $type, $config, $file );
77 0 ▶ $log->debug( sub { "Translated '$type' '$file' into: ", Dumper($data) } );
Subroutine __ANON__: not called CC=1 SCAR=1.2
78 26 return $data;
79 }
80  
81 26 ▶sub _translate_perl {
Subroutine _translate_perl: called CC=3 SCAR=11.5
82 26 my ( $class, $type, $config, $file ) = @_;
83  
84 4 ▶ no strict 'vars';
Subroutine BEGIN: called CC=1 SCAR=0.0
85 26 my $data;
86 my $error;
87 26 my $warnings = '';
88 26 my $success = do {
89 26 local $@;
90  
91 0 ▶ local $SIG{__WARN__} = sub { $warnings .= $_[0] };
Subroutine __ANON__: not called CC=1 SCAR=1.2
92 26 my $rv = eval "\$data = do { $config }; 1;";
93 26 $error = $EVAL_ERROR;
94 26 $rv;
95 };
96 26 ▶ if ($warnings) {
Branch: 1 branch
BranchTrueFalseTotal
if ($warnings) 0 26 26
97 0 $warnings =~ s/\r?\n/\\n/g; # don't log line-endings
98 0 $log->warn( 'Config evaluation warned: ', $warnings );
99 }
100 26 ▶ if (not $success) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($success) 0 26 26
101 0 configuration_error "Cannot evaluate perl data structure ",
102 "in '$file': $error";
103 }
104 26 return $data;
105 }
106  
107 4 1;
108  
109 __END__
« Workflow/Config/YAML.pm ↑ Summary Workflow/Base.pm »