line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# $Id$ |
2
|
|
|
|
|
|
|
# $Source$ |
3
|
|
|
|
|
|
|
# $Author$ |
4
|
|
|
|
|
|
|
# $HeadURL$ |
5
|
|
|
|
|
|
|
# $Revision$ |
6
|
|
|
|
|
|
|
# $Date$ |
7
|
|
|
|
|
|
|
package Config::PlConfig::DotScheme; |
8
|
|
|
|
|
|
|
|
9
|
2
|
|
|
2
|
|
12
|
use warnings; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
70
|
|
10
|
2
|
|
|
2
|
|
10
|
use strict; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
61
|
|
11
|
2
|
|
|
2
|
|
58
|
use 5.006001; |
|
2
|
|
|
|
|
7
|
|
|
2
|
|
|
|
|
65
|
|
12
|
2
|
|
|
2
|
|
10
|
use version; our $VERSION = qv('0.1_02'); |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
11
|
|
13
|
|
|
|
|
|
|
{ |
14
|
|
|
|
|
|
|
|
15
|
2
|
|
|
2
|
|
133
|
use Carp; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
143
|
|
16
|
2
|
|
|
2
|
|
11
|
use Class::Dot qw(-new property isa_String isa_Object); |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
20
|
|
17
|
2
|
|
|
2
|
|
2537
|
use Params::Util qw(_CODELIKE); |
|
2
|
|
|
|
|
13865
|
|
|
2
|
|
|
|
|
177
|
|
18
|
2
|
|
|
2
|
|
19
|
use English qw( -no_match_vars ); |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
17
|
|
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
property plconfig => isa_Object('Config::PlConfig'); |
21
|
|
|
|
|
|
|
property dumper => isa_String('JSON'); |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
my $GLOBAL_AUTOSAVE = 0; |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
my %DUMPER = ( |
26
|
|
|
|
|
|
|
'YAML' => sub { |
27
|
|
|
|
|
|
|
require YAML::Syck; |
28
|
|
|
|
|
|
|
return YAML::Syck::Dump(@_); |
29
|
|
|
|
|
|
|
}, |
30
|
|
|
|
|
|
|
'XML' => sub { |
31
|
|
|
|
|
|
|
require XML::Simple; |
32
|
|
|
|
|
|
|
return XML::Simple::XMLout(@_); |
33
|
|
|
|
|
|
|
}, |
34
|
|
|
|
|
|
|
'JSON' => sub { |
35
|
|
|
|
|
|
|
require JSON::Syck; |
36
|
|
|
|
|
|
|
return JSON::Syck::Dump(@_); |
37
|
|
|
|
|
|
|
}, |
38
|
|
|
|
|
|
|
); |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub write_key { |
41
|
0
|
|
|
0
|
0
|
|
my ( $self, $key, $setvalue ) = @_; |
42
|
0
|
|
|
|
|
|
my $plconfig = $self->plconfig; |
43
|
0
|
|
|
|
|
|
my $config = $plconfig->config; |
44
|
0
|
0
|
0
|
|
|
|
return if !$key || !$setvalue; |
45
|
|
|
|
|
|
|
|
46
|
0
|
|
|
|
|
|
my $statement = $self->dotscheme_to_perlvar($key); |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
# Try to check if the string evals, |
49
|
|
|
|
|
|
|
# if it does it's a valid perl statement, |
50
|
|
|
|
|
|
|
# everything else is quoted with power-quotes (') |
51
|
0
|
|
|
|
|
|
eval $setvalue; ## no critic |
52
|
0
|
0
|
|
|
|
|
if ($EVAL_ERROR) { |
53
|
0
|
|
|
|
|
|
$setvalue = qq{'$setvalue'}; |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
# try the statement with a temp variable first. |
57
|
|
|
|
|
|
|
# so we're sure it doesn't fuck up something. |
58
|
0
|
|
|
|
|
|
$self->eval_string(qq{ |
59
|
|
|
|
|
|
|
my \$tmpvar = $setvalue; |
60
|
|
|
|
|
|
|
}); |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
# then try the real operation |
63
|
0
|
|
|
|
|
|
$self->eval_string(qq{ |
64
|
|
|
|
|
|
|
$statement = $setvalue; |
65
|
|
|
|
|
|
|
}); |
66
|
|
|
|
|
|
|
|
67
|
0
|
|
|
|
|
|
$plconfig->save; |
68
|
|
|
|
|
|
|
|
69
|
0
|
|
|
|
|
|
return 1; |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
sub read_keys { |
73
|
0
|
|
|
0
|
0
|
|
my ($self, $key) = @_; |
74
|
0
|
|
|
|
|
|
my $plconfig = $self->plconfig; |
75
|
0
|
|
|
|
|
|
my $config = $plconfig->config; |
76
|
|
|
|
|
|
|
|
77
|
0
|
0
|
|
|
|
|
if ( defined $key ) { |
78
|
0
|
|
|
|
|
|
print "KEY HOOPA\n"; |
79
|
0
|
|
|
|
|
|
my $statement = $self->dotscheme_to_perlvar($key); |
80
|
0
|
|
|
|
|
|
my $value; |
81
|
0
|
|
|
|
|
|
eval qq{ \$value = $statement }; ## no critic |
82
|
0
|
|
|
|
|
|
print "-----\n", qq{ \$value = $statement }, "\n----\n"; |
83
|
|
|
|
|
|
|
|
84
|
0
|
|
|
|
|
|
return $self->dump_structure( { $key => $value } ); |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
0
|
|
|
|
|
|
return $self->dump_structure($config); |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
sub rename_key { |
92
|
0
|
|
|
0
|
0
|
|
my ( $self, $domain, $key_from, $key_to ) = @_; |
93
|
0
|
|
|
|
|
|
my $plconfig = $self->plconfig; |
94
|
0
|
|
|
|
|
|
my $config = $plconfig->config; |
95
|
0
|
0
|
0
|
|
|
|
return if !$key_from || !$key_to; |
96
|
|
|
|
|
|
|
|
97
|
0
|
|
|
|
|
|
my $from_stmt = $self->dotscheme_to_perlvar($key_from); |
98
|
0
|
|
|
|
|
|
my $to_stmt = $self->dotscheme_to_perlvar($key_to); |
99
|
|
|
|
|
|
|
|
100
|
0
|
|
|
|
|
|
$self->eval_string( |
101
|
|
|
|
|
|
|
qq{ my \$tmp = $from_stmt; $to_stmt = \$tmp; delete $from_stmt} |
102
|
|
|
|
|
|
|
); |
103
|
|
|
|
|
|
|
|
104
|
0
|
|
|
|
|
|
$plconfig->save; |
105
|
|
|
|
|
|
|
|
106
|
0
|
|
|
|
|
|
return 1; |
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
sub delete_key { |
110
|
0
|
|
|
0
|
0
|
|
my ( $self, $domain, $key ) = @_; |
111
|
0
|
|
|
|
|
|
my $plconfig = $self->plconfig; |
112
|
0
|
|
|
|
|
|
my $config = $plconfig->config; |
113
|
0
|
0
|
|
|
|
|
return if !$key; |
114
|
|
|
|
|
|
|
|
115
|
0
|
|
|
|
|
|
my $key_stmt = $self->dotscheme_to_perlvar($key); |
116
|
|
|
|
|
|
|
|
117
|
0
|
|
|
|
|
|
$self->eval_string(qq{ delete $key_stmt }); |
118
|
|
|
|
|
|
|
|
119
|
0
|
|
|
|
|
|
$plconfig->save; |
120
|
|
|
|
|
|
|
|
121
|
0
|
|
|
|
|
|
return 1; |
122
|
|
|
|
|
|
|
} |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
sub eval_string { |
125
|
0
|
|
|
0
|
0
|
|
my ($self, $perl_code) = @_; |
126
|
0
|
|
|
|
|
|
my $plconfig = $self->plconfig; |
127
|
0
|
|
|
|
|
|
my $config = $plconfig->config; |
128
|
0
|
|
|
|
|
|
eval $perl_code; ## no critic |
129
|
0
|
|
|
|
|
|
return $EVAL_ERROR; |
130
|
|
|
|
|
|
|
} |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
sub dump_structure { |
133
|
0
|
|
|
0
|
0
|
|
my ($self, $data_ref) = @_; |
134
|
0
|
|
|
|
|
|
my $curdumper = $self->dumper; |
135
|
|
|
|
|
|
|
|
136
|
0
|
|
|
|
|
|
return $DUMPER{$curdumper}->($data_ref); |
137
|
|
|
|
|
|
|
} |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
sub dotscheme_to_perlvar { |
140
|
0
|
|
|
0
|
0
|
|
my ( $self, $key ) = @_; |
141
|
|
|
|
|
|
|
|
142
|
0
|
|
|
|
|
|
my @keys = split m/\.|\-\>/xms, $key; |
143
|
0
|
|
|
|
|
|
my $statement = q{$} . 'config->'; |
144
|
0
|
|
|
|
|
|
$statement .= join q{}, map {"{'$_'}"} @keys; |
|
0
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
|
146
|
0
|
|
|
|
|
|
return $statement; |
147
|
|
|
|
|
|
|
} |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
} |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
1; # Magic true value required at end of module |
152
|
|
|
|
|
|
|
__END__ |