File Coverage

lib/Workflow/Config/Perl.pm
Criterion Covered Total %
statement 65 67 97.0
branch 13 16 81.2
condition 3 6 50.0
subroutine 12 12 100.0
pod 1 1 100.0
total 94 102 92.1


line stmt bran cond sub pod time code
1              
2             use warnings;
3 3     3   1217 use strict;
  3         7  
  3         110  
4 3     3   13 use base qw( Workflow::Config );
  3         6  
  3         72  
5 3     3   13 use Log::Log4perl qw( get_logger );
  3         4  
  3         350  
6 3     3   18 use Workflow::Exception qw( configuration_error );
  3         6  
  3         23  
7 3     3   198 use Data::Dumper qw( Dumper );
  3         4  
  3         153  
8 3     3   17 use English qw( -no_match_vars );
  3         5  
  3         158  
9 3     3   16  
  3         5  
  3         17  
10             $Workflow::Config::Perl::VERSION = '1.61';
11              
12             my ( $self, $type, @items ) = @_;
13             my $log ||= get_logger();
14 26     26 1 10822  
15 26   33     100 $self->_check_config_type($type);
16              
17 26         1817 if ( !scalar @items ) {
18             return @items;
19 25 100       54 }
20 1         3  
21             my @config_items = Workflow::Config::_expand_refs(@items);
22             return () unless ( scalar @config_items );
23 24         42  
24 24 50       44 my @config = ();
25             foreach my $item (@config_items) {
26 24         28 my ( $file_name, $method );
27 24         33 if ( ref $item ) {
28 27         32 $method = '_translate_perl';
29 27 50       58 $file_name = '[scalar ref]';
30 0         0 }
31 0         0  
32             # $item is a filename...
33             else {
34             $method = '_translate_perl_file';
35             $file_name = $item;
36 27         36 }
37 27         28 $log->info("Will parse '$type' Perl config file '$file_name'");
38             my $this_config = $self->$method( $type, $item );
39 27         101  
40 27         7749 #warn "This config looks like:";
41             #warn Dumper (\$this_config);
42             $log->info("Parsed Perl '$file_name' ok");
43              
44 25         102 if ( exists $this_config->{'type'} ) {
45             $log->debug("Adding typed configuration for '$type'");
46 25 100 66     7265 push @config, $this_config;
    100          
47 10         88 } elsif ( $type eq 'persister'
48 10         2825 and ref $this_config->{$type} eq 'ARRAY' )
49             {
50              
51             # This special exception for persister is required because
52             # the config design for persisters was different from the
53             # other config types. It didn't have a top level 'persister'
54             # element. For backward compatibility, I'm adding this
55             # exception here.
56             $log->debug("Adding multiple configurations for '$type'");
57             push @config, @{ $this_config->{$type} };
58 1         6 } else {
59 1         277 $log->debug("Adding single configuration for '$type'");
  1         4  
60             push @config, $this_config;
61 14         55 }
62 14         3931 }
63             return @config;
64             }
65 22         88  
66             my ( $class, $type, $file ) = @_;
67             my $log = get_logger();
68              
69 27     27   56 local $INPUT_RECORD_SEPARATOR = undef;
70 27         70 open( CONF, '<', $file )
71             || configuration_error "Cannot read file '$file': $!";
72 27         792 my $config = <CONF>;
73 27 100       887 close(CONF) || configuration_error "Cannot close file '$file': $!";
74             my $data = $class->_translate_perl( $type, $config, $file );
75 26         5998 $log->debug( sub { "Translated '$type' '$file' into: ", Dumper($data) } );
76 26 50       313 return $data;
77 26         87 }
78 25     25   145  
  25         418  
79 25         11277 my ( $class, $type, $config, $file ) = @_;
80             my $log = get_logger();
81              
82             no strict 'vars';
83 26     26   76 my $data = eval $config;
84 26         73 if ($EVAL_ERROR) {
85             configuration_error "Cannot evaluate perl data structure ",
86 3     3   2220 "in '$file': $EVAL_ERROR";
  3         6  
  3         262  
87 26         3418 }
88 26 100       90 return $data;
89 1         7 }
90              
91             1;
92 25         44  
93              
94             =pod
95              
96             =head1 NAME
97              
98             Workflow::Config::Perl - Parse workflow configurations as Perl data structures
99              
100             =head1 VERSION
101              
102             This documentation describes version 1.61 of this package
103              
104             =head1 SYNOPSIS
105              
106             # either of these is acceptable
107             my $parser = Workflow::Config->new( 'perl' );
108             my $parser = Workflow::Config->new( 'pl' );
109              
110             my $conf = $parser->parse( 'condition',
111             'my_conditions.pl', 'your_conditions.perl' );
112              
113             =head1 DESCRIPTION
114              
115             Implementation of configuration parser for serialized Perl data
116             structures from files/data. See L<Workflow::Config> for C<parse()>
117             description.
118              
119             =head1 METHODS
120              
121             =head2 parse
122              
123             This method is required implemented by L<Workflow::Config>.
124              
125             It takes two arguments:
126              
127             =over
128              
129             =item * a string indicating the type of configuration. For a complete list of
130             types please refer to L<Workflow::Config>
131              
132             =item * a list of filenames containing at least a single file name
133              
134             =back
135              
136             The method returns a list of configuration parameters.
137              
138             =head1 SEE ALSO
139              
140             =over
141              
142             =item * L<Workflow::Config>
143              
144             =back
145              
146             =head1 COPYRIGHT
147              
148             Copyright (c) 2004-2022 Chris Winters. All rights reserved.
149              
150             This library is free software; you can redistribute it and/or modify
151             it under the same terms as Perl itself.
152              
153             Please see the F<LICENSE>
154              
155             =head1 AUTHORS
156              
157             Please see L<Workflow>
158              
159             =cut