Workflow/Config.pm

filter: Statementstmt 96.7% 59 / 61 Branchbran 81.2% 13 / 16 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 100% 13 / 13 Podpod 100% 5 / 5 totaltotal 91.0% 91 / 100 CC 12 SCAR 12.4
CC
12
Cov
91%
parse_all_files
6.0
_expand_refs
5.9
parse
2.1
CRAP 3.5
« Workflow/Base.pm ↑ Summary Workflow/Config/XML.pm »
1 package Workflow::Config;
2  
3 33 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 33 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 33 ▶use v5.14.0;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 33 ▶use parent qw( Class::Factory );
Subroutine BEGIN: called CC=1 SCAR=0.0
7 33 ▶use Data::Dumper qw( Dumper );
Subroutine BEGIN: called CC=1 SCAR=0.0
8 33 ▶use Workflow::Exception qw( configuration_error );
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 33 $Workflow::Config::VERSION = '2.12';
11  
12 # Map the valid type to the top-level XML tag or data
13 # structure to look for.
14 33 my %VALID_TYPES = (
15 action => 'actions',
16 condition => 'conditions',
17 observer => 'observers',
18 persister => 'persister',
19 validator => 'validators',
20 workflow => 'workflow',
21 );
22  
23 256 ▶sub is_valid_config_type {
Subroutine is_valid_config_type: called CC=1 SCAR=0.0
Pod documented
24 256 my ( $class, $type ) = @_;
25 256 return $VALID_TYPES{$type};
26 }
27  
28 2 ▶sub get_valid_config_types {
Subroutine get_valid_config_types: called CC=1 SCAR=0.0
Pod documented
29 2 my @keys = sort keys %VALID_TYPES;
30  
31 2 return @keys;
32 }
33  
34 129 ▶sub get_config_type_tag {
Subroutine get_config_type_tag: called CC=1 SCAR=0.0
Pod documented
35 129 my ( $class, $type ) = @_;
36 129 return $VALID_TYPES{$type};
37 }
38  
39 # Class method that allows you to pass in any type of items in
40 # @items. So you can do:
41 #
42 # Workflow::Config->parse_all_files( 'condition', 'my_condition.xml', 'your_condition.perl' );
43  
44 177 ▶sub parse_all_files {
Subroutine parse_all_files: called CC=6 SCAR=17.9
Pod documented
45 177 my ( $class, $type, @files ) = @_;
46  
47 177 ▶ return () unless ( scalar @files );
Branch: 1 branch
BranchTrueFalseTotal
unless scalar @files 1 176 177
48  
49 176 my %parsers = ();
50 176 my %parse_types = map { $_ => 1 } $class->get_registered_types;
51  
52 176 my @configurations = ();
53  
54 176 foreach my $file (@files) {
55 177 ▶ next unless ($file);
Branch: 1 branch
BranchTrueFalseTotal
unless $file 55 122 177
56 122 my ($file_type) = $file =~ /\.(\w+)$/;
57 122 ▶ unless ( $parse_types{$file_type} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($parse_types{$file_type}) 1 121 122
58 1 configuration_error
59 "Cannot parse configuration file '$file' of workflow ",
60 "type '$type'. The file has unknown configuration type ",
61 "'$file_type'; known configuration types are: ", "'",
62 join( ', ', keys %parse_types ), "'";
63 }
64 121 ▶ unless ( $parsers{$file_type} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($parsers{$file_type}) 120 1 121
65 120 $parsers{$file_type} = $class->new($file_type);
66 }
67 121 push @configurations, $parsers{$file_type}->parse( $type, $file );
68 }
69 175 return @configurations;
70 }
71  
72 1 ▶sub parse {
Subroutine parse: called CC=2 SCAR=7.6
Pod documented
73 1 my ( $self, $type, @items ) = @_;
74 1 ▶ my $class = ref($self) || $self;
Condition33%1/3
ref $self || $self
l!l&&r!l&&!r
010
MC/DC0%0/2
ref $self || $self
ref $self $self
Truth table33%1/3
A || B
A= ref $selfB= $self
ABresult
1X1
011
000
75 1 configuration_error "Class $class must implement 'parse()'";
76 }
77  
78 146 ▶sub _check_config_type {
Subroutine _check_config_type: called CC=2 SCAR=6.9
79 146 my ( $class, $type ) = @_;
80 146 ▶ unless ( $class->is_valid_config_type($type) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($class->is_valid_config_type($type)) 1 145 146
81 1 configuration_error "When parsing a configuration file the ",
82 "configuration type (first argument) must be ", "one of: ",
83 join ', ', $class->get_valid_config_types;
84 }
85 }
86  
87 144 ▶sub _expand_refs {
Subroutine _expand_refs: called CC=5 SCAR=17.8
88 144 my (@items) = @_;
89 144 my @all = ();
90  
91 144 ▶ if ( !scalar @items ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (scalar @items) 0 144 144
92 0 return @all;
93 }
94  
95 144 foreach my $item (@items) {
96 157 ▶ next unless ($item);
Branch: 1 branch
BranchTrueFalseTotal
unless $item 0 157 157
97 0 ▶ push @all, ( ref $item eq 'ARRAY' ) ? @{$item} : $item;
Branch: 1 branch
BranchTrueFalseTotal
ref $item eq 'ARRAY' ? : 0 157 157
98 }
99 144 return @all;
100 }
101  
102 33 __PACKAGE__->register_factory_type( perl => 'Workflow::Config::Perl' );
103 33 __PACKAGE__->register_factory_type( pl => 'Workflow::Config::Perl' );
104 33 __PACKAGE__->register_factory_type( xml => 'Workflow::Config::XML' );
105 33 __PACKAGE__->register_factory_type( yaml => 'Workflow::Config::YAML' );
106 33 __PACKAGE__->register_factory_type( yml => 'Workflow::Config::YAML' );
107  
108 33 1;
109  
110 __END__
« Workflow/Base.pm ↑ Summary Workflow/Config/XML.pm »