line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
2
|
|
|
2
|
|
215225
|
use strict; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
61
|
|
2
|
2
|
|
|
2
|
|
12
|
use warnings; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
105
|
|
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
package Gentoo::Overlay::Group::INI; |
5
|
|
|
|
|
|
|
BEGIN { |
6
|
2
|
|
|
2
|
|
71
|
$Gentoo::Overlay::Group::INI::AUTHORITY = 'cpan:KENTNL'; |
7
|
|
|
|
|
|
|
} |
8
|
|
|
|
|
|
|
{ |
9
|
|
|
|
|
|
|
$Gentoo::Overlay::Group::INI::VERSION = '0.2.2'; |
10
|
|
|
|
|
|
|
} |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
# ABSTRACT: Load a list of overlays defined in a configuration file. |
13
|
|
|
|
|
|
|
|
14
|
2
|
|
|
2
|
|
1233
|
use Moose; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
use Path::Tiny; |
16
|
|
|
|
|
|
|
use File::HomeDir; |
17
|
|
|
|
|
|
|
use Gentoo::Overlay::Exceptions qw( :all ); |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
our $CFG_PATHS; |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub _cf_paths { |
25
|
|
|
|
|
|
|
return $CFG_PATHS if defined $CFG_PATHS; |
26
|
|
|
|
|
|
|
return ( $CFG_PATHS = _init_cf_paths() ); |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
## no critic (RegularExpressions) |
31
|
|
|
|
|
|
|
sub _init_cf_paths { |
32
|
|
|
|
|
|
|
my $cfg_paths = [ |
33
|
|
|
|
|
|
|
Path::Tiny::path( File::HomeDir->my_dist_config( 'Gentoo-Overlay-Group-INI', { create => 1 } ) ), |
34
|
|
|
|
|
|
|
Path::Tiny::path( File::HomeDir->my_dist_data( 'Gentoo-Overlay-Group-INI', { create => 1 } ) ), |
35
|
|
|
|
|
|
|
Path::Tiny::path('/etc/Gentoo-Overlay-Group-INI'), |
36
|
|
|
|
|
|
|
]; |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
return $cfg_paths if not exists $ENV{GENTOO_OVERLAY_GROUP_INI_PATH}; |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
$cfg_paths = []; |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
for my $path ( split /:/, $ENV{GENTOO_OVERLAY_GROUP_INI_PATH} ) { |
43
|
|
|
|
|
|
|
if ( $path =~ /^~\// ) { |
44
|
|
|
|
|
|
|
$path =~ s{^~/}{}; |
45
|
|
|
|
|
|
|
push @{$cfg_paths}, Path::Tiny::path( File::HomeDir->my_home )->child($path); |
46
|
|
|
|
|
|
|
next; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
push @{$cfg_paths}, Path::Tiny::path($path); |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
return $cfg_paths; |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
## use critic |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub _enumerate_file_list { |
56
|
|
|
|
|
|
|
return map { ( $_->child('config.ini'), $_->child('Gentoo-Overlay-Group-INI.ini') ) } @{ _cf_paths() }; |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
sub _first_config_file { |
61
|
|
|
|
|
|
|
for my $file (_enumerate_file_list) { |
62
|
|
|
|
|
|
|
return $file if -e -f $file; |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
return exception( |
65
|
|
|
|
|
|
|
ident => 'no config', |
66
|
|
|
|
|
|
|
message => qq{No config file could be found in any of the configured paths:\n%{paths}s\n}, |
67
|
|
|
|
|
|
|
payload => { paths => ( join q{}, map { " $_\n" } _enumerate_file_list ), } |
68
|
|
|
|
|
|
|
); |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
sub load { |
73
|
|
|
|
|
|
|
my ($self) = @_; |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
my $seq = $self->_parse(); |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
return $seq->section_named('Overlays')->construct->overlay_group; |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
sub load_named { |
83
|
|
|
|
|
|
|
my ( $self, $name, $config ) = @_; |
84
|
|
|
|
|
|
|
$config //= {}; |
85
|
|
|
|
|
|
|
my $seq = $self->_parse(); |
86
|
|
|
|
|
|
|
my $section = $seq->section_named($name); |
87
|
|
|
|
|
|
|
return unless defined $section; |
88
|
|
|
|
|
|
|
if ( not defined $config->{'-inflate'} or $config->{'-inflate'} ) { |
89
|
|
|
|
|
|
|
return $section->construct; |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
return $section; |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
sub load_all_does { |
96
|
|
|
|
|
|
|
my ( $self, $role, $config ) = @_; |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
$config //= {}; |
99
|
|
|
|
|
|
|
my $real_role = String::RewritePrefix->rewrite( |
100
|
|
|
|
|
|
|
{ |
101
|
|
|
|
|
|
|
q{::} => q{Gentoo::Overlay::Group::INI::Section::}, |
102
|
|
|
|
|
|
|
q{} => q{}, |
103
|
|
|
|
|
|
|
}, |
104
|
|
|
|
|
|
|
$role, |
105
|
|
|
|
|
|
|
); |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
my $seq = $self->_parse(); |
108
|
|
|
|
|
|
|
my (@items) = grep { $_->package->does($real_role) } $seq->sections; |
109
|
|
|
|
|
|
|
if ( not defined $config->{'-inflate'} or $config->{'-inflate'} ) { |
110
|
|
|
|
|
|
|
return map { $_->construct } @items; |
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
return @items; |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
} |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
sub load_all_isa { |
118
|
|
|
|
|
|
|
my ( $self, $class, $config ) = @_; |
119
|
|
|
|
|
|
|
require String::RewritePrefix; |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
my $real_class = String::RewritePrefix->rewrite( |
122
|
|
|
|
|
|
|
{ |
123
|
|
|
|
|
|
|
q{::} => q{Gentoo::Overlay::Group::INI::Section::}, |
124
|
|
|
|
|
|
|
q{} => q{}, |
125
|
|
|
|
|
|
|
}, |
126
|
|
|
|
|
|
|
$class, |
127
|
|
|
|
|
|
|
); |
128
|
|
|
|
|
|
|
$config //= {}; |
129
|
|
|
|
|
|
|
my $seq = $self->_parse(); |
130
|
|
|
|
|
|
|
my (@items) = grep { $_->package->isa($real_class) } $seq->sections; |
131
|
|
|
|
|
|
|
if ( not defined $config->{'-inflate'} or $config->{'-inflate'} ) { |
132
|
|
|
|
|
|
|
return map { $_->construct } @items; |
133
|
|
|
|
|
|
|
} |
134
|
|
|
|
|
|
|
return @items; |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
} |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
sub _parse { |
140
|
|
|
|
|
|
|
require Config::MVP::Reader; |
141
|
|
|
|
|
|
|
require Config::MVP::Reader::INI; |
142
|
|
|
|
|
|
|
require Gentoo::Overlay::Group::INI::Assembler; |
143
|
|
|
|
|
|
|
require Gentoo::Overlay::Group::INI::Section; |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
my $reader = Config::MVP::Reader::INI->new(); |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
my $asm = Gentoo::Overlay::Group::INI::Assembler->new( section_class => 'Gentoo::Overlay::Group::INI::Section', ); |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
my $cnf = _first_config_file(); |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
return $reader->read_config( $cnf, { assembler => $asm } ); |
152
|
|
|
|
|
|
|
} |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
155
|
|
|
|
|
|
|
no Moose; |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
1; |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
__END__ |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
=pod |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
=encoding utf-8 |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
=head1 NAME |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
Gentoo::Overlay::Group::INI - Load a list of overlays defined in a configuration file. |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
=head1 VERSION |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
version 0.2.2 |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
=head1 SYNOPSIS |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
Generates a L<< C<Gentoo::Overlay::B<Group>> object|Gentoo::Overlay::Group >> using a configuration file from your environment. |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
require Gentoo::Overlay::Group::INI; |
178
|
|
|
|
|
|
|
my $group = Gentoo::Overlay::Group::INI->load(); |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
Currently, the following paths are checked: |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
~/.config/Perl/Gentoo-Overlay-Group-INI/config.ini # 'my_dist_config' dir |
183
|
|
|
|
|
|
|
~/.config/Perl/Gentoo-Overlay-Group-INI/Gentoo-Overlay-Group-INI.ini |
184
|
|
|
|
|
|
|
~/.local/share/Perl/dist/Gentoo-Overlay-Group-INI/config.ini # 'my_dist_data' dir |
185
|
|
|
|
|
|
|
~/.local/share/Perl/dist/Gentoo-Overlay-Group-INI/Gentoo-Overlay-Group-INI.ini |
186
|
|
|
|
|
|
|
/etc/Gentoo-Overlay-Group-INI/config.ini |
187
|
|
|
|
|
|
|
/etc/Gentoo-Overlay-Group-INI/Gentoo-Overlay-Group-INI.ini |
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
If you have set C<GENTOO_OVERLAY_GROUP_INI_PATH>, it will be split by C<B<:>> and each part scanned: |
190
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
$ENV{GENTOO_OVERLAY_GROUP_INI_PATH} = "/a:/b" |
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
/a/config.ini |
194
|
|
|
|
|
|
|
/a/Gentoo-Overlay-Group-INI.ini |
195
|
|
|
|
|
|
|
/b/config.ini |
196
|
|
|
|
|
|
|
/b/Gentoo-Overlay-Group-INI.ini |
197
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
If any of the path parts start with C<~/> , those parts will be expanded to your "Home" directory. |
199
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
Format of the INI files is as follows: |
201
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
[Overlays] |
203
|
|
|
|
|
|
|
directory = /usr/portage |
204
|
|
|
|
|
|
|
directory = /usr/local/portage |
205
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
=head1 CLASS METHODS |
207
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
=head2 load |
209
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
Returns a working Overlay::Group object. |
211
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
my $group = Gentoo::Overlay::Group::INI->load(); |
213
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
=head2 load_named |
215
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
Return an inflated arbitrary section: |
217
|
|
|
|
|
|
|
|
218
|
|
|
|
|
|
|
# A "self-named" overlay section |
219
|
|
|
|
|
|
|
my $section = Gentoo::Overlay::Group::INI->load_named('Overlay'); |
220
|
|
|
|
|
|
|
# A 'custom named overlay section, ie: |
221
|
|
|
|
|
|
|
# [ Overlay / foo ] |
222
|
|
|
|
|
|
|
my $section = Gentoo::Overlay::Group::INI->load_named('foo'); |
223
|
|
|
|
|
|
|
|
224
|
|
|
|
|
|
|
=head2 load_all_does |
225
|
|
|
|
|
|
|
|
226
|
|
|
|
|
|
|
Return all sections in a config file that C<do> the given role. |
227
|
|
|
|
|
|
|
|
228
|
|
|
|
|
|
|
my ( @sections ) = Gentoo::Overlay::Group::INI->load_all_does('Some::Role'); |
229
|
|
|
|
|
|
|
|
230
|
|
|
|
|
|
|
=head2 load_all_isa |
231
|
|
|
|
|
|
|
|
232
|
|
|
|
|
|
|
Return all sections in a config file that inherit the given class. |
233
|
|
|
|
|
|
|
|
234
|
|
|
|
|
|
|
my ( @sections ) = Gentoo::Overlay::Group::INI->load_all_isa('Gentoo::Overlay::Group::Section::Overlay'); |
235
|
|
|
|
|
|
|
|
236
|
|
|
|
|
|
|
=head1 PACKAGE VARIABLES |
237
|
|
|
|
|
|
|
|
238
|
|
|
|
|
|
|
=head2 $CFG_PATHS |
239
|
|
|
|
|
|
|
|
240
|
|
|
|
|
|
|
An array ref of Path::Tiny objects to scan for config files. |
241
|
|
|
|
|
|
|
|
242
|
|
|
|
|
|
|
=head1 PRIVATE FUNCTIONS |
243
|
|
|
|
|
|
|
|
244
|
|
|
|
|
|
|
=head2 _cf_paths |
245
|
|
|
|
|
|
|
|
246
|
|
|
|
|
|
|
Fetch C<$CFG_PATHS>, and initialize $CFG_PATHS if it isn't initialized. |
247
|
|
|
|
|
|
|
|
248
|
|
|
|
|
|
|
my $path_list = _cf_paths(); |
249
|
|
|
|
|
|
|
|
250
|
|
|
|
|
|
|
=head2 _init_cf_paths |
251
|
|
|
|
|
|
|
|
252
|
|
|
|
|
|
|
Return the hard-coded array ref of paths to use, or parses C<$ENV{GENTOO_OVERLAY_GROUP_INI_PATH}>. |
253
|
|
|
|
|
|
|
|
254
|
|
|
|
|
|
|
my $path_list = _init_cf_paths(); |
255
|
|
|
|
|
|
|
|
256
|
|
|
|
|
|
|
=head2 _enumerate_file_list |
257
|
|
|
|
|
|
|
|
258
|
|
|
|
|
|
|
Returns a list of file paths to check, in the order they should be checked. |
259
|
|
|
|
|
|
|
|
260
|
|
|
|
|
|
|
my @list = _enumerate_file_list(); |
261
|
|
|
|
|
|
|
|
262
|
|
|
|
|
|
|
=head2 _first_config_file |
263
|
|
|
|
|
|
|
|
264
|
|
|
|
|
|
|
Returns the path to the first file that exists. |
265
|
|
|
|
|
|
|
|
266
|
|
|
|
|
|
|
my $first = _first_config_file(); |
267
|
|
|
|
|
|
|
|
268
|
|
|
|
|
|
|
=head1 PRIVATE METHODS |
269
|
|
|
|
|
|
|
|
270
|
|
|
|
|
|
|
=head2 _parse |
271
|
|
|
|
|
|
|
|
272
|
|
|
|
|
|
|
=head1 AUTHOR |
273
|
|
|
|
|
|
|
|
274
|
|
|
|
|
|
|
Kent Fredric <kentnl@cpan.org> |
275
|
|
|
|
|
|
|
|
276
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
277
|
|
|
|
|
|
|
|
278
|
|
|
|
|
|
|
This software is copyright (c) 2013 by Kent Fredric <kentnl@cpan.org>. |
279
|
|
|
|
|
|
|
|
280
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
281
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
282
|
|
|
|
|
|
|
|
283
|
|
|
|
|
|
|
=cut |