line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package File::ConfigDir::Plack; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
45048
|
use 5.008; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
91
|
|
4
|
|
|
|
|
|
|
|
5
|
2
|
|
|
2
|
|
11
|
use strict; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
73
|
|
6
|
2
|
|
|
2
|
|
10
|
use warnings FATAL => 'all'; |
|
2
|
|
|
|
|
9
|
|
|
2
|
|
|
|
|
117
|
|
7
|
2
|
|
|
2
|
|
10
|
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS); |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
170
|
|
8
|
|
|
|
|
|
|
|
9
|
2
|
|
|
2
|
|
12
|
use Carp qw(croak); |
|
2
|
|
|
|
|
1
|
|
|
2
|
|
|
|
|
117
|
|
10
|
2
|
|
|
2
|
|
10
|
use Cwd (); |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
43
|
|
11
|
2
|
|
|
2
|
|
9
|
use Exporter (); |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
43
|
|
12
|
2
|
|
|
2
|
|
10
|
use File::Basename (); |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
32
|
|
13
|
2
|
|
|
2
|
|
9
|
use File::Spec (); |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
39
|
|
14
|
2
|
|
|
2
|
|
518
|
use File::ConfigDir (); |
|
2
|
|
|
|
|
9283
|
|
|
2
|
|
|
|
|
190
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
=head1 NAME |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
File::ConfigDir::Plack - Plack plugin for File::ConfigDir |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
=cut |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
$VERSION = '0.002'; |
23
|
|
|
|
|
|
|
@ISA = qw(Exporter); |
24
|
|
|
|
|
|
|
@EXPORT = (); |
25
|
|
|
|
|
|
|
@EXPORT_OK = ( qw(plack_app_dir plack_env_dir), ); |
26
|
|
|
|
|
|
|
%EXPORT_TAGS = ( |
27
|
|
|
|
|
|
|
ALL => [@EXPORT_OK], |
28
|
|
|
|
|
|
|
); |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
my $plack_app; |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
BEGIN |
33
|
|
|
|
|
|
|
{ |
34
|
2
|
100
|
|
2
|
|
960
|
defined $ENV{PLACK_ENV} and $plack_app = $0; |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
=head1 SYNOPSIS |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
use File::ConfigFir 'config_dirs'; |
40
|
|
|
|
|
|
|
use File::ConfigDir::Plack; |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
my @dirs = config_dirs(); |
43
|
|
|
|
|
|
|
my @foos = config_dirs('foo'); |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
Of course, in edge case you need to figure out the dedicated configuration |
46
|
|
|
|
|
|
|
locations: |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
use File::ConfigDir::Plack qw/plack_app_dir plack_env_dir/; |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
# remember - directory source functions always return lists, even |
51
|
|
|
|
|
|
|
# only one entry is in there |
52
|
|
|
|
|
|
|
my @plack_app_dir = plack_app_dir; |
53
|
|
|
|
|
|
|
my @plack_env_dir = plack_env_dir; |
54
|
|
|
|
|
|
|
my @plack_env_foo = plack_env_dir('foo'); |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
=head1 DESCRIPTION |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
File::ConfigDir::Plack works as plugin for L to find |
59
|
|
|
|
|
|
|
configurations directories for L environments. This requires |
60
|
|
|
|
|
|
|
the environment variable C being set and the directory |
61
|
|
|
|
|
|
|
C must exists in the directory of the running process image |
62
|
|
|
|
|
|
|
or up to 3 levels above. |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
=head1 EXPORT |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
This module doesn't export anything by default. You have to request any |
67
|
|
|
|
|
|
|
desired explicitly. |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
=head1 SUBROUTINES |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
=head2 plack_app_dir |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
Returns the configuration directory of a L application currently |
74
|
|
|
|
|
|
|
executed. It doesn't work outside of a Plack application. |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
=cut |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
my @search_locations = ( |
79
|
|
|
|
|
|
|
File::Spec->curdir, File::Spec->updir, |
80
|
|
|
|
|
|
|
File::Spec->catdir( File::Spec->updir, File::Spec->updir ), |
81
|
|
|
|
|
|
|
File::Spec->catdir( File::Spec->updir, File::Spec->updir, File::Spec->updir ), |
82
|
|
|
|
|
|
|
); |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
my $plack_app_dir = sub { |
85
|
|
|
|
|
|
|
my @dirs; |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
if ( defined $plack_app ) |
88
|
|
|
|
|
|
|
{ |
89
|
|
|
|
|
|
|
my $app_dir = File::Basename::dirname($plack_app); |
90
|
|
|
|
|
|
|
foreach my $srch (@search_locations) |
91
|
|
|
|
|
|
|
{ |
92
|
|
|
|
|
|
|
if ( -d File::Spec->catdir( $app_dir, $srch, "environments" ) ) |
93
|
|
|
|
|
|
|
{ |
94
|
|
|
|
|
|
|
$app_dir = Cwd::abs_path( File::Spec->catdir( $app_dir, $srch ) ); |
95
|
|
|
|
|
|
|
last; |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
push( @dirs, $app_dir ); |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
return @dirs; |
102
|
|
|
|
|
|
|
}; |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
sub plack_app_dir |
105
|
|
|
|
|
|
|
{ |
106
|
6
|
|
|
6
|
1
|
444
|
my @cfg_base = @_; |
107
|
6
|
50
|
|
|
|
15
|
0 == scalar(@cfg_base) |
108
|
|
|
|
|
|
|
or croak "plack_app_dir(), not plack_app_dir(" . join( ",", ("\$") x scalar(@cfg_base) ) . ")"; |
109
|
6
|
|
|
|
|
10
|
return $plack_app_dir->(); |
110
|
|
|
|
|
|
|
} |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=head2 plack_env_dir |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
Returns the environment directory of a L application. |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
=cut |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
my $plack_env_dir = sub { |
119
|
|
|
|
|
|
|
my @cfg_base = @_; |
120
|
|
|
|
|
|
|
my @dirs; |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
defined $ENV{PLACK_ENV} |
123
|
|
|
|
|
|
|
and push( @dirs, map { File::Spec->catdir( $_, "environments", $ENV{PLACK_ENV}, @cfg_base ) } $plack_app_dir->() ); |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
return @dirs; |
126
|
|
|
|
|
|
|
}; |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
sub plack_env_dir |
129
|
|
|
|
|
|
|
{ |
130
|
6
|
|
|
6
|
1
|
883
|
my @cfg_base = @_; |
131
|
6
|
|
|
|
|
25
|
return $plack_env_dir->(@cfg_base); |
132
|
|
|
|
|
|
|
} |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
my $registered; |
135
|
|
|
|
|
|
|
File::ConfigDir::_plug_dir_source( $plack_app_dir, ++$registered ) |
136
|
|
|
|
|
|
|
and File::ConfigDir::_plug_dir_source($plack_env_dir) |
137
|
|
|
|
|
|
|
unless $registered; |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
=head1 AUTHOR |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
Jens Rehsack, C<< >> |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
=head1 BUGS |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
Please report any bugs or feature requests to |
146
|
|
|
|
|
|
|
C, or through the web interface at |
147
|
|
|
|
|
|
|
L. |
148
|
|
|
|
|
|
|
I will be notified, and then you'll automatically be notified of progress |
149
|
|
|
|
|
|
|
on your bug as I make changes. |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
=head1 SUPPORT |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
You can find documentation for this module with the perldoc command. |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
perldoc File::ConfigDir::Plack |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
You can also look for information at: |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
=over 4 |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
=item * RT: CPAN's request tracker (report bugs here) |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
L |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
=item * AnnoCPAN: Annotated CPAN documentation |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
L |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
=item * CPAN Ratings |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
L |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
=item * Search CPAN |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
L |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
=back |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
=head1 ACKNOWLEDGEMENTS |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
Celogeek San inspired that module by including L |
182
|
|
|
|
|
|
|
into L. |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
=head1 LICENSE AND COPYRIGHT |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
Copyright 2013,2014 Jens Rehsack. |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it |
189
|
|
|
|
|
|
|
under the terms of either: the GNU General Public License as published |
190
|
|
|
|
|
|
|
by the Free Software Foundation; or the Artistic License. |
191
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
See L for more information. |
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
=cut |
195
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
1; # End of File::ConfigDir::Plack |