Connector/Multi/YAML.pm

filter: Statementstmt 97.8% 45 / 46 Branchbran 87.5% 7 / 8 Conditioncond 33.3% 3 / 9 MC/DCmcdc 0.0% 0 / 5 Subroutinesub 100% 8 / 8 Podpod 0.0% 0 / 1 totaltotal 81.8% 63 / 77 CC 10 SCAR 15.6
CC
10
Cov
87%
makeRefs
8.2
_build_config
3.3
BEGIN
1.0
CRAP 4.8
« Connector/Proxy/DBI.pm ↑ Summary Connector/Tee.pm »
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
BranchTrueFalseTotal
unless (-e $file and -r $file) 0 2 2
Condition33%1/3
-e $file and -r $file
!ll&&!rl&&r
002
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
ABresult
0X0
100
111
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
BranchTrueFalseTotal
if (ref $config eq 'HASH') { } 18 26 44
elsif (ref $config eq 'ARRAY') { } 1 25 26
42 18 my $ret = {};
43 18 foreach my $key ( keys %{$config} ) {
44 44 ▶ if ( $key =~ m{ (?: \A @ (.*?) @ \z | \A @ (.*) | (.*?) @ \z ) }xms ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($key =~ / (?: \A @ (.*?) @ \z | \A @ (.*) | (.*?) @ \z ) /msx) { } 6 38 44
45 6 ▶ my $match = $1 || $2 || $3;
Condition33%2/6
$1 || $2 || $3
l!l&&r!l&&!r
060
$1 or $2
l!l&&r!l&&!r
006
MC/DC0%0/3
$1 || $2 || $3
$1 $2 $3
Truth table25%1/4
A or B || C
A= $1B= $2C= $3
ABCresult
1XX1
01X1
0011
0000
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__
« Connector/Proxy/DBI.pm ↑ Summary Connector/Tee.pm »