line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package File::ConfigDir::Plack; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
69616
|
use 5.006; |
|
2
|
|
|
|
|
8
|
|
|
2
|
|
|
|
|
99
|
|
4
|
|
|
|
|
|
|
|
5
|
2
|
|
|
2
|
|
13
|
use strict; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
60
|
|
6
|
2
|
|
|
2
|
|
9
|
use warnings FATAL => 'all'; |
|
2
|
|
|
|
|
12
|
|
|
2
|
|
|
|
|
90
|
|
7
|
2
|
|
|
2
|
|
9
|
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS); |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
145
|
|
8
|
|
|
|
|
|
|
|
9
|
2
|
|
|
2
|
|
10
|
use Carp qw(croak); |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
90
|
|
10
|
2
|
|
|
2
|
|
8
|
use Cwd (); |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
37
|
|
11
|
2
|
|
|
2
|
|
8
|
use Exporter (); |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
41
|
|
12
|
2
|
|
|
2
|
|
11
|
use File::Basename (); |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
25
|
|
13
|
2
|
|
|
2
|
|
8
|
use File::Spec (); |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
33
|
|
14
|
2
|
|
|
2
|
|
1144
|
use File::ConfigDir (); |
|
2
|
|
|
|
|
26393
|
|
|
2
|
|
|
|
|
165
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
=head1 NAME |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
File::ConfigDir::Plack - Plack plugin for File::ConfigDir |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
=cut |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
$VERSION = '0.001'; |
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
|
|
1006
|
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, |
80
|
|
|
|
|
|
|
File::Spec->updir, |
81
|
|
|
|
|
|
|
File::Spec->catdir( File::Spec->updir, File::Spec->updir ), |
82
|
|
|
|
|
|
|
File::Spec->catdir( |
83
|
|
|
|
|
|
|
File::Spec->updir, File::Spec->updir, |
84
|
|
|
|
|
|
|
File::Spec->updir |
85
|
|
|
|
|
|
|
), |
86
|
|
|
|
|
|
|
); |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
my $plack_app_dir = sub { |
89
|
|
|
|
|
|
|
my @dirs; |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
if ( defined $plack_app ) |
92
|
|
|
|
|
|
|
{ |
93
|
|
|
|
|
|
|
my $app_dir = File::Basename::dirname($plack_app); |
94
|
|
|
|
|
|
|
foreach my $srch (@search_locations) |
95
|
|
|
|
|
|
|
{ |
96
|
|
|
|
|
|
|
if ( -d File::Spec->catdir( $app_dir, $srch, "environments" ) ) |
97
|
|
|
|
|
|
|
{ |
98
|
|
|
|
|
|
|
$app_dir = Cwd::abs_path( File::Spec->catdir( $app_dir, $srch ) ); |
99
|
|
|
|
|
|
|
last; |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
push( @dirs, $app_dir ); |
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
return @dirs; |
106
|
|
|
|
|
|
|
}; |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
sub plack_app_dir |
109
|
|
|
|
|
|
|
{ |
110
|
6
|
|
|
6
|
1
|
2294
|
my @cfg_base = @_; |
111
|
6
|
50
|
|
|
|
17
|
0 == scalar(@cfg_base) |
112
|
|
|
|
|
|
|
or croak "plack_app_dir(), not plack_app_dir(" |
113
|
|
|
|
|
|
|
. join( ",", ("\$") x scalar(@cfg_base) ) . ")"; |
114
|
6
|
|
|
|
|
15
|
return $plack_app_dir->(); |
115
|
|
|
|
|
|
|
} |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
=head2 plack_env_dir |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
Returns the environment directory of a L application. |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
=cut |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
my $plack_env_dir = sub { |
124
|
|
|
|
|
|
|
my @cfg_base = @_; |
125
|
|
|
|
|
|
|
my @dirs; |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
defined $ENV{PLACK_ENV} |
128
|
|
|
|
|
|
|
and push( @dirs, |
129
|
|
|
|
|
|
|
map { File::Spec->catdir( $_, "environments", $ENV{PLACK_ENV}, @cfg_base ) } |
130
|
|
|
|
|
|
|
$plack_app_dir->() ); |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
return @dirs; |
133
|
|
|
|
|
|
|
}; |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
sub plack_env_dir |
136
|
|
|
|
|
|
|
{ |
137
|
6
|
|
|
6
|
1
|
1821
|
my @cfg_base = @_; |
138
|
6
|
|
|
|
|
30
|
return $plack_env_dir->(@cfg_base); |
139
|
|
|
|
|
|
|
} |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
my $registered; |
142
|
|
|
|
|
|
|
File::ConfigDir::_plug_dir_source( $plack_app_dir, ++$registered ) |
143
|
|
|
|
|
|
|
and File::ConfigDir::_plug_dir_source($plack_env_dir) |
144
|
|
|
|
|
|
|
unless $registered; |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
=head1 AUTHOR |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
Jens Rehsack, C<< >> |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
=head1 BUGS |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
Please report any bugs or feature requests to |
153
|
|
|
|
|
|
|
C, or through the web interface at |
154
|
|
|
|
|
|
|
L. |
155
|
|
|
|
|
|
|
I will be notified, and then you'll automatically be notified of progress |
156
|
|
|
|
|
|
|
on your bug as I make changes. |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
=head1 SUPPORT |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
You can find documentation for this module with the perldoc command. |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
perldoc File::ConfigDir::Plack |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
You can also look for information at: |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
=over 4 |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
=item * RT: CPAN's request tracker (report bugs here) |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
L |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
=item * AnnoCPAN: Annotated CPAN documentation |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
L |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
=item * CPAN Ratings |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
L |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
=item * Search CPAN |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
L |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
=back |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
=head1 ACKNOWLEDGEMENTS |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
Celogeek San inspired that module by including L |
189
|
|
|
|
|
|
|
into L. |
190
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
=head1 LICENSE AND COPYRIGHT |
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
Copyright 2013 Jens Rehsack. |
194
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it |
196
|
|
|
|
|
|
|
under the terms of either: the GNU General Public License as published |
197
|
|
|
|
|
|
|
by the Free Software Foundation; or the Artistic License. |
198
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
See L for more information. |
200
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
=cut |
202
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
1; # End of File::ConfigDir::Plack |