line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Clustericious::Config::Helpers; |
2
|
|
|
|
|
|
|
|
3
|
15
|
|
|
15
|
|
94
|
use strict; |
|
15
|
|
|
|
|
34
|
|
|
15
|
|
|
|
|
566
|
|
4
|
15
|
|
|
15
|
|
89
|
use warnings; |
|
15
|
|
|
|
|
31
|
|
|
15
|
|
|
|
|
470
|
|
5
|
15
|
|
|
15
|
|
160
|
use v5.10; |
|
15
|
|
|
|
|
58
|
|
|
15
|
|
|
|
|
753
|
|
6
|
15
|
|
|
15
|
|
22447
|
use Hash::Merge qw/merge/; |
|
15
|
|
|
|
|
44459
|
|
|
15
|
|
|
|
|
1100
|
|
7
|
15
|
|
|
15
|
|
1317
|
use Data::Dumper; |
|
15
|
|
|
|
|
12319
|
|
|
15
|
|
|
|
|
973
|
|
8
|
15
|
|
|
15
|
|
105
|
use Carp qw( croak ); |
|
15
|
|
|
|
|
32
|
|
|
15
|
|
|
|
|
697
|
|
9
|
15
|
|
|
15
|
|
77
|
use base qw( Exporter ); |
|
15
|
|
|
|
|
32
|
|
|
15
|
|
|
|
|
1162
|
|
10
|
15
|
|
|
15
|
|
1348
|
use JSON::XS qw( encode_json ); |
|
15
|
|
|
|
|
7528
|
|
|
15
|
|
|
|
|
10056
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
# ABSTRACT: Helpers for clustericious config files. |
13
|
|
|
|
|
|
|
our $VERSION = '0.28'; # VERSION |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
our @mergeStack; |
17
|
|
|
|
|
|
|
our @EXPORT = qw( extends_config get_password home file dir hostname hostname_full json ); |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub extends_config { |
21
|
3
|
|
|
3
|
1
|
2252
|
my $filename = shift; |
22
|
3
|
|
|
|
|
8
|
my @args = @_; |
23
|
3
|
|
|
|
|
36
|
push @mergeStack, Clustericious::Config->new($filename, \@args); |
24
|
3
|
|
|
|
|
10
|
return ''; |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
# |
28
|
|
|
|
|
|
|
# |
29
|
|
|
|
|
|
|
# do_merges: |
30
|
|
|
|
|
|
|
# |
31
|
|
|
|
|
|
|
# Called after reading all config files, to process extends_config |
32
|
|
|
|
|
|
|
# directives. |
33
|
|
|
|
|
|
|
# |
34
|
|
|
|
|
|
|
sub _do_merges { |
35
|
24
|
|
|
24
|
|
43
|
my $class = shift; |
36
|
24
|
|
|
|
|
48
|
my $conf_data = shift; # Last one; Has highest precedence. |
37
|
|
|
|
|
|
|
|
38
|
24
|
100
|
|
|
|
123
|
return $conf_data unless @mergeStack; |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
# Nested extends_config's form a tree which we traverse depth first. |
41
|
3
|
|
|
|
|
18
|
Hash::Merge::set_behavior( 'RIGHT_PRECEDENT' ); |
42
|
3
|
|
|
|
|
73
|
my %so_far = %{ shift @mergeStack }; |
|
3
|
|
|
|
|
31
|
|
43
|
3
|
|
|
|
|
28
|
while (my $c = shift @mergeStack) { |
44
|
0
|
|
|
|
|
0
|
my %h = %$c; |
45
|
0
|
|
|
|
|
0
|
%so_far = %{ merge( \%so_far, \%h ) }; |
|
0
|
|
|
|
|
0
|
|
46
|
|
|
|
|
|
|
} |
47
|
3
|
|
|
|
|
7
|
%$conf_data = %{ merge( \%so_far, $conf_data ) }; |
|
3
|
|
|
|
|
14
|
|
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
sub get_password { |
52
|
0
|
|
|
0
|
1
|
0
|
return Clustericious::Config::Password->sentinel; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
sub home (;$) |
57
|
|
|
|
|
|
|
{ |
58
|
4
|
|
|
4
|
1
|
21
|
require File::HomeDir; |
59
|
4
|
100
|
|
|
|
45
|
$_[0] ? File::HomeDir->users_home($_[0]) : File::HomeDir->my_home; |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
sub file |
64
|
|
|
|
|
|
|
{ |
65
|
1
|
|
|
1
|
1
|
24
|
eval { require Path::Class::File }; |
|
1
|
|
|
|
|
6
|
|
66
|
1
|
50
|
|
|
|
7
|
croak "file helper requires Path::Class" if $@; |
67
|
1
|
|
|
|
|
9
|
Path::Class::File->new(@_); |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
sub dir |
72
|
|
|
|
|
|
|
{ |
73
|
1
|
|
|
1
|
1
|
38
|
require Path::Class::Dir; |
74
|
1
|
50
|
|
|
|
3
|
croak "dir helper requires Path::Class" if $@; |
75
|
1
|
|
|
|
|
12
|
Path::Class::Dir->new(@_); |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
sub hostname |
80
|
|
|
|
|
|
|
{ |
81
|
1
|
|
|
1
|
1
|
2
|
state $hostname; |
82
|
|
|
|
|
|
|
|
83
|
1
|
50
|
|
|
|
5
|
unless(defined $hostname) |
84
|
|
|
|
|
|
|
{ |
85
|
1
|
|
|
|
|
6
|
require Sys::Hostname; |
86
|
1
|
|
|
|
|
9
|
$hostname = Sys::Hostname::hostname(); |
87
|
1
|
|
|
|
|
9
|
$hostname =~ s/\..*$//; |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
1
|
|
|
|
|
3
|
$hostname; |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
sub hostname_full |
95
|
|
|
|
|
|
|
{ |
96
|
1
|
|
|
1
|
1
|
5
|
require Sys::Hostname; |
97
|
1
|
|
|
|
|
3
|
Sys::Hostname::hostname(); |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
sub json ($) |
102
|
|
|
|
|
|
|
{ |
103
|
1
|
|
|
1
|
1
|
25
|
encode_json($_[0]); |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
1; |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
__END__ |