| 1 | package Workflow::Config::YAML; | ||||||||||||||||||||
| 2 | |||||||||||||||||||||
| 3 | 2 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 4 | 2 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 5 | 2 | ▶ | use v5.14.0; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 6 | 2 | ▶ | use parent qw( Workflow::Config ); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 7 | 2 | ▶ | use Log::Any qw( $log ); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 8 | 2 | ▶ | use Workflow::Exception qw( configuration_error ); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 9 | 2 | ▶ | use Carp qw(croak); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 10 | 2 | ▶ | use Syntax::Keyword::Try; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 11 | |||||||||||||||||||||
| 12 | 2 | $Workflow::Config::YAML::VERSION = '2.12'; | |||||||||||||||||||
| 13 | |||||||||||||||||||||
| 14 | 2 | my $YAML_REQUIRED = 0; | |||||||||||||||||||
| 15 | |||||||||||||||||||||
| 16 | 1 | ▶ | sub parse { | ||||||||||||||||||
|
Subroutine
parse: called CC=7 SCAR=20.6
Pod
documented
| |||||||||||||||||||||
| 17 | 1 | my ( $self, $type, @items ) = @_; | |||||||||||||||||||
| 18 | |||||||||||||||||||||
| 19 | 1 | $self->_check_config_type($type); | |||||||||||||||||||
| 20 | 1 | my @config_items = Workflow::Config::_expand_refs(@items); | |||||||||||||||||||
| 21 | 1 | ▶ | return () unless ( scalar @config_items ); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 22 | |||||||||||||||||||||
| 23 | 1 | my @config = (); | |||||||||||||||||||
| 24 | 1 | foreach my $item (@config_items) { | |||||||||||||||||||
| 25 | 4 | ▶ | my $file_name = ( ref $item ) ? '[scalar ref]' : $item; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 26 | 4 | $log->info("Will parse '$type' YAML config file '$file_name'"); | |||||||||||||||||||
| 27 | 4 | my $this_config = do { | |||||||||||||||||||
| 28 | try { | ||||||||||||||||||||
| 29 | 4 | $self->_translate_yaml( $type, $item ); | |||||||||||||||||||
| 30 | } | ||||||||||||||||||||
| 31 | 4 | catch ($error) { | |||||||||||||||||||
| 32 | 0 | croak $log->error("Processing $file_name: ", $error); | |||||||||||||||||||
| 33 | } | ||||||||||||||||||||
| 34 | }; | ||||||||||||||||||||
| 35 | 4 | $log->info("Parsed YAML '$file_name' ok"); | |||||||||||||||||||
| 36 | 4 | my $key = $self->get_config_type_tag($type); | |||||||||||||||||||
| 37 | 4 | ▶ | if ( exists $this_config->{'type'} ) { | ||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||
| 38 | 1 | push @config, $this_config; | |||||||||||||||||||
| 39 | } | ||||||||||||||||||||
| 40 | ▶ | elsif ( $type eq 'persister' | |||||||||||||||||||
|
Condition33%1/3
$type eq "persister" and ref $this_config->{"persister"} eq "ARRAY"
MC/DC0%0/2
$type eq "persister" and ref $this_config->{"persister"} eq "ARRAY"
$type eq "persister"
ref $this_config->{"persister"} eq "ARRAY"
Truth table33%1/3
A and B
A= $type eq "persister"B= ref $this_config->{"persister"} eq "ARRAY"
| |||||||||||||||||||||
| 41 | and ref $this_config->{'persister'} eq 'ARRAY' ) { | ||||||||||||||||||||
| 42 | 0 | push @config, @{ $this_config->{'persister'} }; | |||||||||||||||||||
| 43 | } | ||||||||||||||||||||
| 44 | else { | ||||||||||||||||||||
| 45 | 3 | push @config, $this_config; | |||||||||||||||||||
| 46 | } | ||||||||||||||||||||
| 47 | } | ||||||||||||||||||||
| 48 | 1 | return @config; | |||||||||||||||||||
| 49 | } | ||||||||||||||||||||
| 50 | |||||||||||||||||||||
| 51 | 4 | ▶ | sub _translate_yaml { | ||||||||||||||||||
|
Subroutine
_translate_yaml: called CC=3 SCAR=11.1
| |||||||||||||||||||||
| 52 | 4 | my ( $self, $type, $item ) = @_; | |||||||||||||||||||
| 53 | |||||||||||||||||||||
| 54 | 4 | ▶ | unless ( $YAML_REQUIRED ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 55 | 1 | require YAML; | |||||||||||||||||||
| 56 | 1 | YAML->import( qw( Load LoadFile ) ); | |||||||||||||||||||
| 57 | 1 | $YAML_REQUIRED++; | |||||||||||||||||||
| 58 | } | ||||||||||||||||||||
| 59 | |||||||||||||||||||||
| 60 | 4 | ▶ | if ( ref $item ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 61 | 0 | return Load( $$item ); | |||||||||||||||||||
| 62 | } | ||||||||||||||||||||
| 63 | else { | ||||||||||||||||||||
| 64 | 4 | return LoadFile( $item ); | |||||||||||||||||||
| 65 | } | ||||||||||||||||||||
| 66 | } | ||||||||||||||||||||
| 67 | |||||||||||||||||||||
| 68 | 2 | 1; | |||||||||||||||||||
| 69 | |||||||||||||||||||||
| 70 | |||||||||||||||||||||
| 71 | __END__ | ||||||||||||||||||||