line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package MooX::File::ConfigDir; |
2
|
|
|
|
|
|
|
|
3
|
3
|
|
|
3
|
|
87768
|
use strict; |
|
3
|
|
|
|
|
8
|
|
|
3
|
|
|
|
|
106
|
|
4
|
3
|
|
|
3
|
|
16
|
use warnings; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
133
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = "0.008"; |
7
|
|
|
|
|
|
|
|
8
|
3
|
|
|
3
|
|
17
|
use Carp qw/croak/; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
149
|
|
9
|
3
|
|
|
3
|
|
18
|
use Scalar::Util qw(blessed); |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
154
|
|
10
|
3
|
|
|
3
|
|
1570
|
use File::ConfigDir (); |
|
3
|
|
|
|
|
78781
|
|
|
3
|
|
|
|
|
91
|
|
11
|
|
|
|
|
|
|
|
12
|
3
|
|
|
3
|
|
524
|
use Moo::Role; |
|
3
|
|
|
|
|
17436
|
|
|
3
|
|
|
|
|
24
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
has 'config_identifier' => ( |
15
|
|
|
|
|
|
|
is => 'lazy', |
16
|
|
|
|
|
|
|
); |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
1
|
|
|
sub _build_config_identifier { } |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub _fetch_file_config_dir |
21
|
|
|
|
|
|
|
{ |
22
|
35
|
|
|
35
|
|
78
|
my ($self, $attr, $params) = @_; |
23
|
35
|
100
|
66
|
|
|
366
|
croak "either \$self or \$params must be valid" unless blessed $self or "HASH" eq ref $params; |
24
|
|
|
|
|
|
|
my $app_name = |
25
|
|
|
|
|
|
|
blessed($self) ? $self->config_identifier |
26
|
|
|
|
|
|
|
: defined $params->{config_identifier} ? $params->{config_identifier} |
27
|
34
|
0
|
|
|
|
634
|
: $self->_build_config_identifier($params); |
|
|
50
|
|
|
|
|
|
28
|
34
|
100
|
|
|
|
313
|
my @app_names = $app_name ? ($app_name) : (); |
29
|
34
|
|
|
|
|
157
|
my $sub = File::ConfigDir->can($attr); |
30
|
34
|
|
|
|
|
57
|
my @dirs = &{$sub}(@app_names); |
|
34
|
|
|
|
|
105
|
|
31
|
34
|
|
|
|
|
2881
|
return \@dirs; |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
has singleapp_cfg_dir => ( |
35
|
|
|
|
|
|
|
is => 'ro', |
36
|
|
|
|
|
|
|
lazy => 1, |
37
|
|
|
|
|
|
|
clearer => 1, |
38
|
3
|
|
|
3
|
|
2075
|
builder => sub { [File::ConfigDir::singleapp_cfg_dir] }, |
39
|
|
|
|
|
|
|
); |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
my @file_config_dir_attrs = ( |
42
|
|
|
|
|
|
|
qw(system_cfg_dir xdg_config_dirs desktop_cfg_dir), |
43
|
|
|
|
|
|
|
qw(core_cfg_dir site_cfg_dir vendor_cfg_dir vendorapp_cfg_dir), |
44
|
|
|
|
|
|
|
qw(local_cfg_dir locallib_cfg_dir here_cfg_dir user_cfg_dir), |
45
|
|
|
|
|
|
|
qw(xdg_config_home config_dirs) |
46
|
|
|
|
|
|
|
); |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
foreach my $attr (@file_config_dir_attrs) |
49
|
|
|
|
|
|
|
{ |
50
|
|
|
|
|
|
|
has $attr => ( |
51
|
|
|
|
|
|
|
is => 'ro', |
52
|
|
|
|
|
|
|
lazy => 1, |
53
|
|
|
|
|
|
|
clearer => 1, |
54
|
35
|
|
|
35
|
|
58765
|
builder => sub { my $self = shift; $self->_fetch_file_config_dir($attr, @_) }, |
|
35
|
|
|
35
|
|
111
|
|
|
|
|
|
35
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
|
35
|
|
|
|
55
|
|
|
|
|
|
|
); |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
=head1 NAME |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
MooX::File::ConfigDir - Moo eXtension for File::ConfigDir |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
=begin html |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
=end html |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
=head1 SYNOPSIS |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
my App; |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
use Moo; |
74
|
|
|
|
|
|
|
with MooX::File::ConfigDir; |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
1; |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
package main; |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
my $app = App->new(); |
81
|
|
|
|
|
|
|
$app->config_identifier('MyProject'); |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
my @cfgdirs = @{ $app->config_dirs }; |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
# install support |
86
|
|
|
|
|
|
|
my $site_cfg_dir = $app->site_cfg_dir->[0]; |
87
|
|
|
|
|
|
|
my $vendor_cfg_dir = $app->site_cfg_dir->[0]; |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
=head1 DESCRIPTION |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
This module is a helper for easily find configuration file locations. |
93
|
|
|
|
|
|
|
Whether to use this information for find a suitable place for installing |
94
|
|
|
|
|
|
|
them or looking around for finding any piece of settings, heavily depends |
95
|
|
|
|
|
|
|
on the requirements. |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
=head1 ATTRIBUTES |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
=head2 config_identifier |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
Allows to deal with a global unique identifier passed to the functions of |
102
|
|
|
|
|
|
|
L. Using it encapsulates configuration files from the |
103
|
|
|
|
|
|
|
other ones (e.g. C vs. C). |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
C can be initialized by specifying it as parameter |
106
|
|
|
|
|
|
|
during object construction or via inheriting default builder |
107
|
|
|
|
|
|
|
(C<_build_config_identifier>). |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
=head2 system_cfg_dir |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
Provides the configuration directory where configuration files of the |
112
|
|
|
|
|
|
|
operating system resides. For details see L. |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
=head2 desktop_cfg_dir |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
Provides the configuration directory where configuration files of the |
117
|
|
|
|
|
|
|
desktop applications resides. For details see L. |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
=head2 xdg_config_dirs |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
Alias for desktop_cfg_dir to support |
122
|
|
|
|
|
|
|
L |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
=head2 core_cfg_dir |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
Provides the configuration directory of the Perl5 core location. |
127
|
|
|
|
|
|
|
For details see L. |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
=head2 site_cfg_dir |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
Provides the configuration directory of the Perl5 sitelib location. |
132
|
|
|
|
|
|
|
For details see L. |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
=head2 vendor_cfg_dir |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
Provides the configuration directory of the Perl5 vendorlib location. |
137
|
|
|
|
|
|
|
For details see L. |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
=head2 singleapp_cfg_dir |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
Provides the configuration directory of C<$0> if it's installed as |
142
|
|
|
|
|
|
|
a separate package - either a program bundle (TSM, Oracle DB) or |
143
|
|
|
|
|
|
|
an independent package combination (e.g. via L |
144
|
|
|
|
|
|
|
For details see L. |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
=head2 vendorapp_cfg_dir |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
Provides the configuration directory of C<$0> if it's installed as |
149
|
|
|
|
|
|
|
a separate package via a vendor installation as e.g. L |
150
|
|
|
|
|
|
|
or L. |
151
|
|
|
|
|
|
|
For details see L. |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
=head2 local_cfg_dir |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
Returns the configuration directory for distribution independent, 3rd |
156
|
|
|
|
|
|
|
party applications. For details see L. |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
=head2 locallib_cfg_dir |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
Provides the configuration directory of the Perl5 L environment |
161
|
|
|
|
|
|
|
location. For details see L. |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
=head2 here_cfg_dir |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
Provides the path for the C directory below the current working directory. |
166
|
|
|
|
|
|
|
For details see L. |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
=head2 user_cfg_dir |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
Provides the users home folder using L. |
171
|
|
|
|
|
|
|
For details see L. |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
=head2 xdg_config_home |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
Returns the user configuration directory for desktop applications. |
176
|
|
|
|
|
|
|
For details see L. |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
=head2 config_dirs |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
Tries to get all available configuration directories as described above. |
181
|
|
|
|
|
|
|
Returns those who exists and are readable. |
182
|
|
|
|
|
|
|
For details see L. |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
=head1 AUTHOR |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
Jens Rehsack, C<< >> |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
=head1 BUGS |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
Please report any bugs or feature requests to |
191
|
|
|
|
|
|
|
C, or through the web interface at |
192
|
|
|
|
|
|
|
L. |
193
|
|
|
|
|
|
|
I will be notified, and then you'll automatically be notified of progress |
194
|
|
|
|
|
|
|
on your bug as I make changes. |
195
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
=head1 SUPPORT |
197
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
You can find documentation for this module with the perldoc command. |
199
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
perldoc MooX::File::ConfigDir |
201
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
You can also look for information at: |
203
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
=over 4 |
205
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
=item * RT: CPAN's request tracker |
207
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
L |
209
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
=item * AnnoCPAN: Annotated CPAN documentation |
211
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
L |
213
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
=item * CPAN Ratings |
215
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
L |
217
|
|
|
|
|
|
|
|
218
|
|
|
|
|
|
|
=item * Search CPAN |
219
|
|
|
|
|
|
|
|
220
|
|
|
|
|
|
|
L |
221
|
|
|
|
|
|
|
|
222
|
|
|
|
|
|
|
=back |
223
|
|
|
|
|
|
|
|
224
|
|
|
|
|
|
|
=head1 LICENSE AND COPYRIGHT |
225
|
|
|
|
|
|
|
|
226
|
|
|
|
|
|
|
Copyright 2013-2020 Jens Rehsack. |
227
|
|
|
|
|
|
|
|
228
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it |
229
|
|
|
|
|
|
|
under the terms of either: the GNU General Public License as published |
230
|
|
|
|
|
|
|
by the Free Software Foundation; or the Artistic License. |
231
|
|
|
|
|
|
|
|
232
|
|
|
|
|
|
|
See http://dev.perl.org/licenses/ for more information. |
233
|
|
|
|
|
|
|
|
234
|
|
|
|
|
|
|
=cut |
235
|
|
|
|
|
|
|
|
236
|
|
|
|
|
|
|
1; |