| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Connector::Multi::YAML; |
|
2
|
|
|
|
|
|
|
|
|
3
|
3
|
|
|
3
|
|
519338
|
use strict; |
|
|
3
|
|
|
|
|
30
|
|
|
|
3
|
|
|
|
|
78
|
|
|
4
|
3
|
|
|
3
|
|
14
|
use warnings; |
|
|
3
|
|
|
|
|
5
|
|
|
|
3
|
|
|
|
|
64
|
|
|
5
|
3
|
|
|
3
|
|
24
|
use English; |
|
|
3
|
|
|
|
|
6
|
|
|
|
3
|
|
|
|
|
22
|
|
|
6
|
3
|
|
|
3
|
|
2387
|
use YAML; |
|
|
3
|
|
|
|
|
21897
|
|
|
|
3
|
|
|
|
|
152
|
|
|
7
|
3
|
|
|
3
|
|
25
|
use Data::Dumper; |
|
|
3
|
|
|
|
|
6
|
|
|
|
3
|
|
|
|
|
118
|
|
|
8
|
|
|
|
|
|
|
|
|
9
|
3
|
|
|
3
|
|
1758
|
use Moose; |
|
|
3
|
|
|
|
|
1192736
|
|
|
|
3
|
|
|
|
|
15
|
|
|
10
|
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
extends 'Connector::Builtin::Memory'; |
|
12
|
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
has '+LOCATION' => ( required => 1 ); |
|
14
|
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub _build_config { |
|
16
|
|
|
|
|
|
|
|
|
17
|
3
|
|
|
3
|
|
6
|
my $self = shift; |
|
18
|
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
# File not exist or not readable |
|
20
|
3
|
|
|
|
|
78
|
my $file = $self->LOCATION(); |
|
21
|
3
|
50
|
33
|
|
|
137
|
if ( ! ( ( -e $file ) && ( -r $file ) ) ) { |
|
22
|
0
|
|
|
|
|
0
|
die 'configuration file '.$file.' not found '; |
|
23
|
|
|
|
|
|
|
} |
|
24
|
|
|
|
|
|
|
|
|
25
|
3
|
|
|
|
|
50
|
my $yaml = YAML::LoadFile( $file ); |
|
26
|
|
|
|
|
|
|
|
|
27
|
3
|
|
|
|
|
66736
|
my $config = $self->makeRefs($yaml); |
|
28
|
|
|
|
|
|
|
|
|
29
|
3
|
|
|
|
|
98
|
return $config; |
|
30
|
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
} |
|
32
|
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
# Traverse the tree read from the YAML file and replace the "@" keys by |
|
34
|
|
|
|
|
|
|
# scalar references |
|
35
|
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub makeRefs { |
|
37
|
|
|
|
|
|
|
|
|
38
|
56
|
|
|
56
|
0
|
61
|
my $self = shift; |
|
39
|
56
|
|
|
|
|
68
|
my $config = shift; |
|
40
|
|
|
|
|
|
|
|
|
41
|
56
|
100
|
|
|
|
98
|
if ( ref($config) eq 'HASH' ) { |
|
|
|
100
|
|
|
|
|
|
|
42
|
26
|
|
|
|
|
37
|
my $ret = {}; |
|
43
|
26
|
|
|
|
|
30
|
foreach my $key ( keys %{$config} ) { |
|
|
26
|
|
|
|
|
63
|
|
|
44
|
60
|
100
|
|
|
|
194
|
if ( $key =~ m{ (?: \A @ (.*?) @ \z | \A @ (.*) | (.*?) @ \z ) }xms ) { |
|
45
|
11
|
|
33
|
|
|
59
|
my $match = $1 || $2 || $3; |
|
46
|
|
|
|
|
|
|
# make it a ref to an anonymous scalar so we know it's a symlink |
|
47
|
11
|
|
|
|
|
33
|
$ret->{$match} = \$config->{$key}; |
|
48
|
|
|
|
|
|
|
} else { |
|
49
|
49
|
|
|
|
|
100
|
$ret->{$key} = $self->makeRefs( $config->{$key} ); |
|
50
|
|
|
|
|
|
|
} |
|
51
|
|
|
|
|
|
|
} |
|
52
|
26
|
|
|
|
|
62
|
return $ret; |
|
53
|
|
|
|
|
|
|
} |
|
54
|
|
|
|
|
|
|
elsif ( ref($config) eq 'ARRAY' ) { |
|
55
|
1
|
|
|
|
|
3
|
my $ret = []; |
|
56
|
1
|
|
|
|
|
2
|
my $i = 0; |
|
57
|
1
|
|
|
|
|
2
|
foreach my $entry ( @{$config} ) { |
|
|
1
|
|
|
|
|
2
|
|
|
58
|
4
|
|
|
|
|
8
|
$ret->[ $i++ ] = $self->makeRefs($entry); |
|
59
|
|
|
|
|
|
|
} |
|
60
|
1
|
|
|
|
|
4
|
return $ret; |
|
61
|
|
|
|
|
|
|
} |
|
62
|
|
|
|
|
|
|
else { |
|
63
|
29
|
|
|
|
|
75
|
return $config; |
|
64
|
|
|
|
|
|
|
} |
|
65
|
|
|
|
|
|
|
} |
|
66
|
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
1; |
|
68
|
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
__DATA__ |
|
70
|
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
=head1 Name |
|
73
|
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
Connector::Multi::YAML |
|
75
|
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
=head1 Description |
|
77
|
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
This is a glue connector to create the required reference syntax for |
|
79
|
|
|
|
|
|
|
Connector::Multi based on a backend configuration handled by YAML. |
|
80
|
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
LOCATION is passed over as file to load by YAML. |
|
82
|
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
Internally, the constructor walks down the whole tree and translates |
|
84
|
|
|
|
|
|
|
all keys starting or ending with the "@" character into references as |
|
85
|
|
|
|
|
|
|
understood by Connector::Multi. |
|
86
|
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=head1 CONFIGURATION |
|
88
|
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
There is no special configuration besides the mandatory LOCATION property. |
|
90
|
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=head1 Example |
|
92
|
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
my $backend = Connector::Multi::YAML->new({ |
|
94
|
|
|
|
|
|
|
LOCATION = /etc/myconfig.yaml |
|
95
|
|
|
|
|
|
|
}) |
|
96
|
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
my $multi = Connector::Multi->new({ |
|
98
|
|
|
|
|
|
|
BASECONNECTOR => $backend |
|
99
|
|
|
|
|
|
|
}) |
|
100
|
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
|