line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Devel::ebug::Wx::Service::Configuration; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
1026
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
42
|
|
4
|
1
|
|
|
1
|
|
6
|
use base qw(Devel::ebug::Wx::Service::Base); |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
93
|
|
5
|
1
|
|
|
1
|
|
7
|
use Devel::ebug::Wx::Plugin qw(:plugin); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
201
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
=head1 NAME |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
Devel::ebug::Wx::Service::Configuration - manage ebugger configuration |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
=head1 SYNOPSIS |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
my $cm = ...->get_service( 'configuration' ); |
14
|
|
|
|
|
|
|
my $cfg = $cm->get_config( 'service_name' ); |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
my $value_or_default = $cfg->get_value( 'value_name', $value_default ); |
17
|
|
|
|
|
|
|
$cfg->set_value( 'value_name', $value ); |
18
|
|
|
|
|
|
|
$cfg->delete_value( 'value_name' ); |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
=head1 DESCRIPTION |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
The C service manages the global configuration for all |
23
|
|
|
|
|
|
|
services. |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
=head1 METHODS |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
=cut |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
__PACKAGE__->mk_ro_accessors( qw(inifiles default_file) ); |
30
|
|
|
|
|
|
|
|
31
|
1
|
|
|
1
|
|
939
|
use File::UserConfig; |
|
1
|
|
|
|
|
35294
|
|
|
1
|
|
|
|
|
39
|
|
32
|
1
|
|
|
1
|
|
1744
|
use Config::IniFiles; |
|
1
|
|
|
|
|
67567
|
|
|
1
|
|
|
|
|
34
|
|
33
|
1
|
|
|
1
|
|
11
|
use File::Spec; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
34
|
|
34
|
|
|
|
|
|
|
|
35
|
1
|
|
|
1
|
0
|
1240
|
sub service_name : Service { 'configuration' } |
|
1
|
|
|
0
|
|
1382
|
|
|
1
|
|
|
|
|
7
|
|
|
0
|
|
|
|
|
0
|
|
36
|
0
|
|
|
0
|
0
|
|
sub initialized { 1 } |
37
|
0
|
|
|
0
|
0
|
|
sub finalized { 0 } |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
sub file_name { |
40
|
0
|
|
|
0
|
0
|
|
my( $class ) = @_; |
41
|
0
|
|
|
|
|
|
my $dir = File::UserConfig->new( dist => 'ebug_wx', |
42
|
|
|
|
|
|
|
sharedir => '.', |
43
|
|
|
|
|
|
|
)->configdir; |
44
|
|
|
|
|
|
|
|
45
|
0
|
|
|
|
|
|
return File::Spec->catfile( $dir, 'ebug_wx.ini' ); |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sub new { |
49
|
0
|
|
|
0
|
1
|
|
my( $class ) = @_; |
50
|
0
|
|
|
|
|
|
my $self = $class->SUPER::new( { inifiles => {} } ); |
51
|
|
|
|
|
|
|
|
52
|
0
|
|
|
|
|
|
$self->{default_file} = $class->file_name; |
53
|
0
|
|
|
|
|
|
_load_inifile( $self, $self->default_file ); |
54
|
|
|
|
|
|
|
|
55
|
0
|
|
|
|
|
|
return $self; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
sub _read_or_create { |
59
|
0
|
|
|
0
|
|
|
my( $file ) = @_; |
60
|
|
|
|
|
|
|
|
61
|
0
|
0
|
|
|
|
|
if( -f $file ) { |
62
|
0
|
|
|
|
|
|
return Config::IniFiles->new( -file => $file ); |
63
|
|
|
|
|
|
|
} else { |
64
|
0
|
|
|
|
|
|
my $inifile = Config::IniFiles->new; |
65
|
0
|
|
|
|
|
|
$inifile->SetFileName( $file ); |
66
|
|
|
|
|
|
|
|
67
|
0
|
|
|
|
|
|
return $inifile; |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
sub _load_inifile { |
72
|
0
|
|
|
0
|
|
|
my( $self, $file_name ) = @_; |
73
|
|
|
|
|
|
|
|
74
|
0
|
|
0
|
|
|
|
$self->inifiles->{$file_name} ||= _read_or_create( $file_name ); |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
=head2 get_config |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
my $cfg = $cm->get_config( 'service_name' ); |
80
|
|
|
|
|
|
|
my $cfg2 = $cm->get_config( 'service_name', 'myfile.ini' ); |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
my $value_or_default = $cfg->get_value( 'value_name', $value_default ); |
83
|
|
|
|
|
|
|
$cfg->set_value( 'value_name', $value ); |
84
|
|
|
|
|
|
|
$cfg->delete_value( 'value_name' ); |
85
|
|
|
|
|
|
|
$cfg->get_serialized_value( 'value_name', $default ); |
86
|
|
|
|
|
|
|
$cfg->set_serialized_value( 'value_name', $value ); |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
# force file rewrite |
89
|
|
|
|
|
|
|
$cm->flush( 'myfile.ini' ); |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
Returns an object that can be used to read/change/delete the value of |
92
|
|
|
|
|
|
|
the configuration keys for a given service. |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
=cut |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
sub get_config { |
97
|
0
|
|
|
0
|
1
|
|
my( $self, $section, $filename ) = @_; |
98
|
|
|
|
|
|
|
|
99
|
0
|
|
0
|
|
|
|
return Devel::ebug::Wx::Service::Configuration::My->new |
100
|
|
|
|
|
|
|
( _load_inifile( $self, $filename || $self->default_file ), $section ); |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
sub finalize { |
104
|
0
|
|
|
0
|
0
|
|
my( $self ) = @_; |
105
|
|
|
|
|
|
|
|
106
|
0
|
|
|
|
|
|
$_->RewriteConfig foreach values %{$self->inifiles}; |
|
0
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
sub flush { |
110
|
0
|
|
|
0
|
0
|
|
my( $self, $file ) = @_; |
111
|
|
|
|
|
|
|
|
112
|
0
|
0
|
|
|
|
|
$self->inifiles->{$file}->RewriteConfig if $self->inifiles->{$file}; |
113
|
|
|
|
|
|
|
} |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
package Devel::ebug::Wx::Service::Configuration::My; |
116
|
|
|
|
|
|
|
|
117
|
1
|
|
|
1
|
|
866
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
47
|
|
118
|
1
|
|
|
1
|
|
5
|
use base qw(Class::Accessor::Fast); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
112
|
|
119
|
1
|
|
|
1
|
|
883
|
use YAML qw(); |
|
1
|
|
|
|
|
7726
|
|
|
1
|
|
|
|
|
372
|
|
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
__PACKAGE__->mk_ro_accessors( qw(inifile section) ); |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
sub new { |
124
|
0
|
|
|
0
|
|
|
my( $class, $inifile, $section ) = @_; |
125
|
0
|
|
|
|
|
|
my $self = $class->SUPER::new |
126
|
|
|
|
|
|
|
( { inifile => $inifile, |
127
|
|
|
|
|
|
|
section => $section, |
128
|
|
|
|
|
|
|
} ); |
129
|
|
|
|
|
|
|
|
130
|
0
|
|
|
|
|
|
return $self; |
131
|
|
|
|
|
|
|
} |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
sub get_value { |
134
|
0
|
|
|
0
|
|
|
my( $self, $name, $default ) = @_; |
135
|
|
|
|
|
|
|
|
136
|
0
|
|
|
|
|
|
return $self->inifile->val( $self->section, $name, $default ); |
137
|
|
|
|
|
|
|
} |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
sub set_value { |
140
|
0
|
|
|
0
|
|
|
my( $self, $name, @values ) = @_; |
141
|
|
|
|
|
|
|
|
142
|
0
|
0
|
|
|
|
|
unless( $self->inifile->setval( $self->section, $name, @values ) ) { |
143
|
0
|
|
|
|
|
|
$self->inifile->newval( $self->section, $name, @values ); |
144
|
|
|
|
|
|
|
} |
145
|
|
|
|
|
|
|
|
146
|
0
|
|
|
|
|
|
return; |
147
|
|
|
|
|
|
|
} |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
sub set_serialized_value { |
150
|
0
|
|
|
0
|
|
|
my( $self, $name, $value ) = @_; |
151
|
|
|
|
|
|
|
|
152
|
0
|
|
|
|
|
|
$self->set_value( $name, YAML::Dump( $value ) ); |
153
|
|
|
|
|
|
|
} |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
sub get_serialized_value { |
156
|
0
|
|
|
0
|
|
|
my( $self, $name, $default ) = @_; |
157
|
|
|
|
|
|
|
|
158
|
0
|
|
|
|
|
|
my @values = $self->get_value( $name, undef ); |
159
|
0
|
0
|
|
|
|
|
return $default unless @values; |
160
|
0
|
|
|
|
|
|
my $undumped = eval { |
161
|
0
|
|
|
|
|
|
YAML::Load( join "\n", @values, '' ); |
162
|
|
|
|
|
|
|
}; |
163
|
|
|
|
|
|
|
|
164
|
0
|
0
|
|
|
|
|
return $@ ? $default : $undumped; |
165
|
|
|
|
|
|
|
} |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
sub delete_value { |
168
|
0
|
|
|
0
|
|
|
my( $self, $name ) = @_; |
169
|
|
|
|
|
|
|
|
170
|
0
|
|
|
|
|
|
$self->inifile->delval( $self->section, $name ); |
171
|
|
|
|
|
|
|
} |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
1; |