line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Connector::Multi::YAML; |
2
|
|
|
|
|
|
|
|
3
|
3
|
|
|
3
|
|
621872
|
use strict; |
|
3
|
|
|
|
|
38
|
|
|
3
|
|
|
|
|
89
|
|
4
|
3
|
|
|
3
|
|
17
|
use warnings; |
|
3
|
|
|
|
|
9
|
|
|
3
|
|
|
|
|
71
|
|
5
|
3
|
|
|
3
|
|
14
|
use English; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
36
|
|
6
|
3
|
|
|
3
|
|
2970
|
use YAML; |
|
3
|
|
|
|
|
22004
|
|
|
3
|
|
|
|
|
158
|
|
7
|
3
|
|
|
3
|
|
22
|
use Data::Dumper; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
151
|
|
8
|
|
|
|
|
|
|
|
9
|
3
|
|
|
3
|
|
1814
|
use Moose; |
|
3
|
|
|
|
|
1411562
|
|
|
3
|
|
|
|
|
21
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
extends 'Connector::Builtin::Memory'; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
has '+LOCATION' => ( required => 1 ); |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub _build_config { |
16
|
|
|
|
|
|
|
|
17
|
3
|
|
|
3
|
|
19
|
my $self = shift; |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
# File not exist or not readable |
20
|
3
|
|
|
|
|
95
|
my $file = $self->LOCATION(); |
21
|
3
|
50
|
33
|
|
|
194
|
if ( ! ( ( -e $file ) && ( -r $file ) ) ) { |
22
|
0
|
|
|
|
|
0
|
die 'configuration file '.$file.' not found '; |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
|
25
|
3
|
|
|
|
|
69
|
my $yaml = YAML::LoadFile( $file ); |
26
|
|
|
|
|
|
|
|
27
|
3
|
|
|
|
|
77116
|
my $config = $self->makeRefs($yaml); |
28
|
|
|
|
|
|
|
|
29
|
3
|
|
|
|
|
119
|
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
|
81
|
my $self = shift; |
39
|
56
|
|
|
|
|
76
|
my $config = shift; |
40
|
|
|
|
|
|
|
|
41
|
56
|
100
|
|
|
|
148
|
if ( ref($config) eq 'HASH' ) { |
|
|
100
|
|
|
|
|
|
42
|
26
|
|
|
|
|
48
|
my $ret = {}; |
43
|
26
|
|
|
|
|
34
|
foreach my $key ( keys %{$config} ) { |
|
26
|
|
|
|
|
88
|
|
44
|
60
|
100
|
|
|
|
239
|
if ( $key =~ m{ (?: \A @ (.*?) @ \z | \A @ (.*) | (.*?) @ \z ) }xms ) { |
45
|
11
|
|
33
|
|
|
76
|
my $match = $1 || $2 || $3; |
46
|
|
|
|
|
|
|
# make it a ref to an anonymous scalar so we know it's a symlink |
47
|
11
|
|
|
|
|
40
|
$ret->{$match} = \$config->{$key}; |
48
|
|
|
|
|
|
|
} else { |
49
|
49
|
|
|
|
|
125
|
$ret->{$key} = $self->makeRefs( $config->{$key} ); |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
} |
52
|
26
|
|
|
|
|
76
|
return $ret; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
elsif ( ref($config) eq 'ARRAY' ) { |
55
|
1
|
|
|
|
|
2
|
my $ret = []; |
56
|
1
|
|
|
|
|
2
|
my $i = 0; |
57
|
1
|
|
|
|
|
2
|
foreach my $entry ( @{$config} ) { |
|
1
|
|
|
|
|
3
|
|
58
|
4
|
|
|
|
|
10
|
$ret->[ $i++ ] = $self->makeRefs($entry); |
59
|
|
|
|
|
|
|
} |
60
|
1
|
|
|
|
|
4
|
return $ret; |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
else { |
63
|
29
|
|
|
|
|
83
|
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
|
|
|
|
|
|
|
|