| 1 | package Connector::Multi::YAML; | ||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||
| 3 | 3 | ▶ | use strict; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 4 | 3 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 5 | 3 | ▶ | use English; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 6 | 3 | ▶ | use YAML; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 7 | 3 | ▶ | use Data::Dumper; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||
| 9 | 3 | ▶ | use Moose; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||
| 11 | 3 | extends 'Connector::Builtin::Memory'; | |||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||
| 13 | 3 | has '+LOCATION' => ( required => 1 ); | |||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||
| 15 | 2 | ▶ | sub _build_config { | ||||||||||||||||||||||||||||||||
|
Subroutine
_build_config: called CC=3 SCAR=12.0
| |||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||
| 17 | 2 | my $self = shift; | |||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||
| 19 | # File not exist or not readable | ||||||||||||||||||||||||||||||||||
| 20 | 2 | my $file = $self->LOCATION(); | |||||||||||||||||||||||||||||||||
| 21 | 2 | ▶ | if ( ! ( ( -e $file ) && ( -r $file ) ) ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
-e $file and -r $file
MC/DC0%0/2
-e $file and -r $file
-e $file
-r $file
Truth table33%1/3
A and B
A= -e $fileB= -r $file
| |||||||||||||||||||||||||||||||||||
| 22 | 0 | die 'configuration file '.$file.' not found '; | |||||||||||||||||||||||||||||||||
| 23 | } | ||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||
| 25 | 2 | my $yaml = YAML::LoadFile( $file ); | |||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||
| 27 | 2 | my $config = $self->makeRefs($yaml); | |||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||
| 29 | 2 | return $config; | |||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||
| 31 | } | ||||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||||
| 33 | # Traverse the tree read from the YAML file and replace the "@" keys by | ||||||||||||||||||||||||||||||||||
| 34 | # scalar references | ||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||
| 36 | 44 | ▶ | sub makeRefs { | ||||||||||||||||||||||||||||||||
|
Subroutine
makeRefs: called CC=8 SCAR=21.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||
| 38 | 44 | my $self = shift; | |||||||||||||||||||||||||||||||||
| 39 | 44 | my $config = shift; | |||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||
| 41 | 44 | ▶ | if ( ref($config) eq 'HASH' ) { | ||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||
| 42 | 18 | my $ret = {}; | |||||||||||||||||||||||||||||||||
| 43 | 18 | foreach my $key ( keys %{$config} ) { | |||||||||||||||||||||||||||||||||
| 44 | 44 | ▶ | if ( $key =~ m{ (?: \A @ (.*?) @ \z | \A @ (.*) | (.*?) @ \z ) }xms ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 45 | 6 | ▶ | my $match = $1 || $2 || $3; | ||||||||||||||||||||||||||||||||
|
Condition33%2/6
$1 || $2 || $3
$1 or $2
MC/DC0%0/3
$1 || $2 || $3
$1
$2
$3
Truth table25%1/4
A or B || C
A= $1B= $2C= $3
| |||||||||||||||||||||||||||||||||||
| 46 | # make it a ref to an anonymous scalar so we know it's a symlink | ||||||||||||||||||||||||||||||||||
| 47 | 6 | $ret->{$match} = \$config->{$key}; | |||||||||||||||||||||||||||||||||
| 48 | } else { | ||||||||||||||||||||||||||||||||||
| 49 | 38 | $ret->{$key} = $self->makeRefs( $config->{$key} ); | |||||||||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||||||||
| 52 | 18 | return $ret; | |||||||||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||||||||
| 54 | elsif ( ref($config) eq 'ARRAY' ) { | ||||||||||||||||||||||||||||||||||
| 55 | 1 | my $ret = []; | |||||||||||||||||||||||||||||||||
| 56 | 1 | my $i = 0; | |||||||||||||||||||||||||||||||||
| 57 | 1 | foreach my $entry ( @{$config} ) { | |||||||||||||||||||||||||||||||||
| 58 | 4 | $ret->[ $i++ ] = $self->makeRefs($entry); | |||||||||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||||||||
| 60 | 1 | return $ret; | |||||||||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||||||||
| 62 | else { | ||||||||||||||||||||||||||||||||||
| 63 | 25 | return $config; | |||||||||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||
| 67 | 3 | 1; | |||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||
| 69 | __DATA__ | ||||||||||||||||||||||||||||||||||