line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Cinnamon::Config; |
2
|
3
|
|
|
3
|
|
21
|
use strict; |
|
3
|
|
|
|
|
19
|
|
|
3
|
|
|
|
|
89
|
|
3
|
3
|
|
|
3
|
|
18
|
use warnings; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
86
|
|
4
|
|
|
|
|
|
|
|
5
|
3
|
|
|
3
|
|
942
|
use Cinnamon::Config::Loader; |
|
3
|
|
|
|
|
10
|
|
|
3
|
|
|
|
|
85
|
|
6
|
3
|
|
|
3
|
|
16
|
use Cinnamon::Logger; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
1723
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
my %CONFIG; |
9
|
|
|
|
|
|
|
my %ROLES; |
10
|
|
|
|
|
|
|
my %TASKS; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub reset () { |
13
|
13
|
|
|
13
|
0
|
35902
|
%CONFIG = (); |
14
|
13
|
|
|
|
|
43
|
%ROLES = (); |
15
|
13
|
|
|
|
|
61
|
%TASKS = (); |
16
|
|
|
|
|
|
|
} |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub set ($$) { |
19
|
32
|
|
|
32
|
0
|
74
|
my ($key, $value) = @_; |
20
|
|
|
|
|
|
|
|
21
|
32
|
|
|
|
|
87
|
$CONFIG{$key} = $value; |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub get ($@) { |
25
|
25
|
|
|
25
|
0
|
60
|
my ($key, @args) = @_; |
26
|
|
|
|
|
|
|
|
27
|
25
|
|
|
|
|
50
|
my $value = $CONFIG{$key}; |
28
|
|
|
|
|
|
|
|
29
|
25
|
50
|
|
|
|
61
|
$value = $value->(@args) if ref $value eq 'CODE'; |
30
|
25
|
|
|
|
|
96
|
$value; |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub set_role ($$$) { |
34
|
9
|
|
|
9
|
0
|
24
|
my ($role, $hosts, $params) = @_; |
35
|
|
|
|
|
|
|
|
36
|
9
|
|
|
|
|
37
|
$ROLES{$role} = [$hosts, $params]; |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
sub get_role (@) { |
40
|
8
|
|
33
|
8
|
0
|
39
|
my $role = ($_[0] || get('role')); |
41
|
|
|
|
|
|
|
|
42
|
8
|
50
|
|
|
|
28
|
my $role_def = $ROLES{$role} or return undef; |
43
|
|
|
|
|
|
|
|
44
|
8
|
|
|
|
|
22
|
my ($hosts, $params) = @$role_def; |
45
|
|
|
|
|
|
|
|
46
|
8
|
|
|
|
|
25
|
for my $key (keys %$params) { |
47
|
0
|
|
|
|
|
0
|
set $key => $params->{$key}; |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
8
|
50
|
|
|
|
24
|
$hosts = $hosts->() if ref $hosts eq 'CODE'; |
51
|
8
|
50
|
|
|
|
20
|
$hosts = [] unless defined $hosts; |
52
|
8
|
50
|
|
|
|
32
|
$hosts = ref $hosts eq 'ARRAY' ? $hosts : [$hosts]; |
53
|
|
|
|
|
|
|
|
54
|
8
|
|
|
|
|
23
|
return $hosts; |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
sub set_task ($$) { |
58
|
12
|
|
|
12
|
0
|
39
|
my ($task, $task_def) = @_; |
59
|
12
|
|
|
|
|
78
|
$TASKS{$task} = $task_def; |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
sub get_task (@) { |
63
|
8
|
|
|
8
|
0
|
16
|
my ($task) = @_; |
64
|
|
|
|
|
|
|
|
65
|
8
|
|
33
|
|
|
36
|
$task ||= get('task'); |
66
|
8
|
|
|
|
|
32
|
my @task_path = split(':', $task); |
67
|
|
|
|
|
|
|
|
68
|
8
|
|
|
|
|
17
|
my $value = \%TASKS; |
69
|
8
|
|
|
|
|
21
|
for (@task_path) { |
70
|
8
|
|
|
|
|
22
|
$value = $value->{$_}; |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
8
|
|
|
|
|
17
|
$value; |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
sub user () { |
77
|
0
|
|
|
0
|
0
|
0
|
get 'user' || do { |
78
|
|
|
|
|
|
|
my $user = qx{whoami}; |
79
|
|
|
|
|
|
|
chomp $user; |
80
|
|
|
|
|
|
|
$user; |
81
|
|
|
|
|
|
|
}; |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
sub load (@) { |
85
|
9
|
|
|
9
|
0
|
36
|
my ($role, $task, %opt) = @_; |
86
|
|
|
|
|
|
|
|
87
|
9
|
|
|
|
|
37
|
set role => $role; |
88
|
9
|
|
|
|
|
21
|
set task => $task; |
89
|
|
|
|
|
|
|
|
90
|
9
|
|
|
|
|
84
|
Cinnamon::Config::Loader->load(config => $opt{config}); |
91
|
|
|
|
|
|
|
|
92
|
9
|
|
|
|
|
20
|
for my $key (keys %{ $opt{override_settings} }) { |
|
9
|
|
|
|
|
72
|
|
93
|
2
|
|
|
|
|
6
|
set $key => $opt{override_settings}->{$key}; |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
sub info { |
98
|
1
|
|
|
1
|
0
|
4
|
my $self = shift; |
99
|
|
|
|
|
|
|
my %roles = map { |
100
|
1
|
|
|
|
|
4
|
my ($hosts, $params) = @{$ROLES{$_}}; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
4
|
|
101
|
1
|
50
|
|
|
|
7
|
$hosts = $hosts->() if ref $hosts eq 'CODE'; |
102
|
1
|
|
|
|
|
6
|
$_ => { hosts => $hosts, params => $params }; |
103
|
|
|
|
|
|
|
} keys %ROLES; |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
+{ |
106
|
1
|
|
|
|
|
10
|
roles => \%roles, |
107
|
|
|
|
|
|
|
tasks => \%TASKS, |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
} |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
!!1; |