line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# $Id$ |
2
|
|
|
|
|
|
|
# $Source$ |
3
|
|
|
|
|
|
|
# $Author$ |
4
|
|
|
|
|
|
|
# $HeadURL$ |
5
|
|
|
|
|
|
|
# $Revision$ |
6
|
|
|
|
|
|
|
# $Date$ |
7
|
|
|
|
|
|
|
package Config::PlConfig; |
8
|
2
|
|
|
2
|
|
50580
|
use warnings; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
63
|
|
9
|
2
|
|
|
2
|
|
9
|
use strict; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
61
|
|
10
|
2
|
|
|
2
|
|
51
|
use 5.006001; |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
68
|
|
11
|
2
|
|
|
2
|
|
12
|
use Carp; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
221
|
|
12
|
2
|
|
|
2
|
|
1879
|
use version; our $VERSION = qv('0.1_02'); |
|
2
|
|
|
|
|
5697
|
|
|
2
|
|
|
|
|
13
|
|
13
|
|
|
|
|
|
|
{ |
14
|
|
|
|
|
|
|
|
15
|
2
|
|
|
2
|
|
2182
|
use Class::Dot qw(property isa_String isa_Data isa_Hash isa_Int isa_Object); |
|
2
|
|
|
|
|
10984
|
|
|
2
|
|
|
|
|
15
|
|
16
|
2
|
|
|
2
|
|
1807
|
use Config::PlConfig::Constants; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
65
|
|
17
|
2
|
|
|
2
|
|
1187
|
use Config::PlConfig::Host::Local; |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
72
|
|
18
|
2
|
|
|
2
|
|
1350
|
use Config::PlConfig::Host::Global; |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
63
|
|
19
|
2
|
|
|
2
|
|
1654
|
use Config::PlConfig::DotScheme; |
|
2
|
|
|
|
|
8
|
|
|
2
|
|
|
|
|
95
|
|
20
|
2
|
|
|
2
|
|
1853
|
use YAML::Syck qw(LoadFile DumpFile); |
|
2
|
|
|
|
|
11479
|
|
|
2
|
|
|
|
|
178
|
|
21
|
2
|
|
|
2
|
|
22
|
use Params::Util qw(_CODELIKE); |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
8620
|
|
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
my %HOST_TO_CLASS = ( |
24
|
|
|
|
|
|
|
'local' => 'Config::PlConfig::Host::Local', |
25
|
|
|
|
|
|
|
'global' => 'Config::PlConfig::Host::Global', |
26
|
|
|
|
|
|
|
); |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
property domain => isa_String('system.DEFAULT'); |
29
|
|
|
|
|
|
|
property host => isa_Data(); |
30
|
|
|
|
|
|
|
property options => isa_Hash(); |
31
|
|
|
|
|
|
|
property config => isa_Hash(); |
32
|
|
|
|
|
|
|
property autosave => isa_Int(0); |
33
|
|
|
|
|
|
|
property dotscheme => isa_Object; |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
my $GLOBAL_AUTOSAVE = 0; |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
my %EXPORT_TAGS = ( |
38
|
|
|
|
|
|
|
':autosave' => sub { |
39
|
|
|
|
|
|
|
$GLOBAL_AUTOSAVE = 1; |
40
|
|
|
|
|
|
|
}, |
41
|
|
|
|
|
|
|
); |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
sub import { |
44
|
2
|
|
|
2
|
|
20
|
shift; |
45
|
2
|
50
|
|
|
|
39
|
return if not scalar @_; |
46
|
0
|
|
|
|
|
0
|
my $caller = caller 0; |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
ARG: |
49
|
0
|
|
|
|
|
0
|
for my $arg (@_) { |
50
|
0
|
0
|
|
|
|
0
|
if (exists $EXPORT_TAGS{$arg}) { |
51
|
0
|
|
|
|
|
0
|
my $handler = $EXPORT_TAGS{$arg}; |
52
|
0
|
0
|
|
|
|
0
|
if (_CODELIKE($handler)) { |
53
|
0
|
|
|
|
|
0
|
$handler->($caller); |
54
|
|
|
|
|
|
|
} |
55
|
0
|
|
|
|
|
0
|
next ARG; |
56
|
|
|
|
|
|
|
} |
57
|
0
|
|
|
|
|
0
|
require Carp; |
58
|
0
|
|
|
|
|
0
|
my @msg = "No such export tag: $arg."; |
59
|
0
|
|
|
|
|
0
|
my $alt = ":$arg"; |
60
|
0
|
0
|
|
|
|
0
|
if ($EXPORT_TAGS{$alt}) { |
61
|
0
|
|
|
|
|
0
|
push @msg, "Did you mean $alt?"; |
62
|
|
|
|
|
|
|
}; |
63
|
0
|
|
|
|
|
0
|
my $msg = join q{ }, @msg; |
64
|
0
|
|
|
|
|
0
|
Carp::croak($msg); |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
0
|
|
|
|
|
0
|
return; |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
sub new { |
71
|
3
|
|
|
3
|
1
|
1589
|
my ($class, $options_ref) = @_; |
72
|
3
|
|
|
|
|
54
|
my $self = { }; |
73
|
3
|
|
|
|
|
9
|
bless $self, $class; |
74
|
|
|
|
|
|
|
|
75
|
3
|
|
|
|
|
22
|
my $DEFAULT_HOST = Config::PlConfig::Constants->get( |
76
|
|
|
|
|
|
|
'DEFAULT_HOST' |
77
|
|
|
|
|
|
|
); |
78
|
|
|
|
|
|
|
|
79
|
3
|
100
|
|
|
|
16
|
my $host_class = $options_ref->{host} |
80
|
|
|
|
|
|
|
? $HOST_TO_CLASS{ lc $options_ref->{host} } |
81
|
|
|
|
|
|
|
: $HOST_TO_CLASS{ lc $DEFAULT_HOST }; |
82
|
3
|
|
|
|
|
34
|
my $host = $host_class->new($options_ref); |
83
|
|
|
|
|
|
|
|
84
|
3
|
100
|
|
|
|
13
|
if ($options_ref->{domain}) { |
85
|
1
|
|
|
|
|
5
|
$self->set_domain( $options_ref->{domain} ); |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
|
88
|
3
|
|
|
|
|
35
|
my $dotscheme = Config::PlConfig::DotScheme->new({ |
89
|
|
|
|
|
|
|
plconfig => $self, |
90
|
|
|
|
|
|
|
dumper => $options_ref->{dumper}, |
91
|
|
|
|
|
|
|
}); |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
|
94
|
3
|
|
|
|
|
364
|
$self->set_host($host); |
95
|
3
|
|
|
|
|
24
|
$self->set_options($options_ref); |
96
|
3
|
|
|
|
|
20
|
$self->set_dotscheme($dotscheme); |
97
|
|
|
|
|
|
|
|
98
|
3
|
|
|
|
|
19
|
$self->load( ); |
99
|
|
|
|
|
|
|
|
100
|
3
|
|
|
|
|
10
|
return $self; |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
sub get { |
104
|
5
|
|
|
5
|
1
|
1601
|
my ($self, $key) = @_; |
105
|
5
|
|
|
|
|
17
|
my $config = $self->config; |
106
|
|
|
|
|
|
|
|
107
|
5
|
|
|
|
|
50
|
return $config->{$key}; |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
sub load { |
111
|
6
|
|
|
6
|
1
|
1473
|
my ($self) = @_; |
112
|
6
|
|
|
|
|
19
|
my $host = $self->host; |
113
|
6
|
|
|
|
|
49
|
my $domain = $self->domain; |
114
|
6
|
|
|
|
|
93
|
my $cfile = $host->file_for_domain($domain); |
115
|
|
|
|
|
|
|
|
116
|
6
|
100
|
|
|
|
114
|
if (! -f $cfile) { |
117
|
1
|
|
|
|
|
3
|
return; |
118
|
|
|
|
|
|
|
} |
119
|
|
|
|
|
|
|
|
120
|
5
|
|
|
|
|
18
|
my $config_ref = YAML::Syck::LoadFile($cfile); |
121
|
5
|
|
|
|
|
906
|
$self->set_config($config_ref); |
122
|
|
|
|
|
|
|
|
123
|
5
|
|
|
|
|
38
|
return $config_ref; |
124
|
|
|
|
|
|
|
} |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
sub save { |
127
|
2
|
|
|
2
|
1
|
311
|
my ($self, $opt_config) = @_; |
128
|
2
|
|
|
|
|
7
|
my $host = $self->host; |
129
|
2
|
|
|
|
|
17
|
my $domain = $self->domain; |
130
|
2
|
|
|
|
|
17
|
my $config = $self->config; |
131
|
2
|
|
|
|
|
18
|
my $cfile = $host->file_for_domain($domain); |
132
|
|
|
|
|
|
|
|
133
|
2
|
50
|
|
|
|
10
|
if ($opt_config) { |
134
|
2
|
|
|
|
|
6
|
$config = $opt_config; |
135
|
|
|
|
|
|
|
} |
136
|
|
|
|
|
|
|
|
137
|
2
|
|
|
|
|
8
|
return YAML::Syck::DumpFile($cfile, $config); |
138
|
|
|
|
|
|
|
} |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
sub DEMOLISH { |
141
|
0
|
|
|
0
|
0
|
|
my ($self) = @_; |
142
|
|
|
|
|
|
|
|
143
|
0
|
0
|
0
|
|
|
|
if ($GLOBAL_AUTOSAVE || $self->autosave) { |
144
|
0
|
|
|
|
|
|
$self->save( ); |
145
|
|
|
|
|
|
|
} |
146
|
|
|
|
|
|
|
|
147
|
0
|
|
|
|
|
|
return; |
148
|
|
|
|
|
|
|
} |
149
|
|
|
|
|
|
|
} |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
1; # Magic true value required at end of module |
152
|
|
|
|
|
|
|
__END__ |