| 1 | package File::ConfigDir::Plack; | ||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||
| 3 | 2 | ▶ | use 5.008; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||
| 5 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 6 | 2 | ▶ | use warnings FATAL => 'all'; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 7 | 2 | ▶ | use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS); | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||
| 9 | 2 | ▶ | use Carp qw(croak); | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 10 | 2 | ▶ | use Cwd (); | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 11 | 2 | ▶ | use Exporter (); | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 12 | 2 | ▶ | use File::Basename (); | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 13 | 2 | ▶ | use File::Spec (); | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 14 | 2 | ▶ | use File::ConfigDir (); | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||
| 16 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||
| 18 | File::ConfigDir::Plack - Plack plugin for File::ConfigDir | ||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||
| 20 | =cut | ||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||
| 22 | 2 | $VERSION = '0.002'; | |||||||||||||||||||||||||||||||||||||
| 23 | 2 | @ISA = qw(Exporter); | |||||||||||||||||||||||||||||||||||||
| 24 | 2 | @EXPORT = (); | |||||||||||||||||||||||||||||||||||||
| 25 | 2 | @EXPORT_OK = ( qw(plack_app_dir plack_env_dir), ); | |||||||||||||||||||||||||||||||||||||
| 26 | 2 | %EXPORT_TAGS = ( | |||||||||||||||||||||||||||||||||||||
| 27 | ALL => [@EXPORT_OK], | ||||||||||||||||||||||||||||||||||||||
| 28 | ); | ||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||
| 30 | 2 | my $plack_app; | |||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||
| 32 | BEGIN | ||||||||||||||||||||||||||||||||||||||
| 33 | 2 | ▶ | { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||
| 34 | 2 | ▶ | defined $ENV{PLACK_ENV} and $plack_app = $0; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 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<File::ConfigDir> to find | ||||||||||||||||||||||||||||||||||||||
| 59 | configurations directories for L<Plack> environments. This requires | ||||||||||||||||||||||||||||||||||||||
| 60 | the environment variable C<PLACK_ENV> being set and the directory | ||||||||||||||||||||||||||||||||||||||
| 61 | C<environments> 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<Plack> application currently | ||||||||||||||||||||||||||||||||||||||
| 74 | executed. It doesn't work outside of a Plack application. | ||||||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||||||
| 76 | =cut | ||||||||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||||||
| 78 | 2 | 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 | 22 | ▶ | my $plack_app_dir = sub { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||
| 85 | 22 | my @dirs; | |||||||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||||||
| 87 | 22 | ▶ | if ( defined $plack_app ) | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 88 | { | ||||||||||||||||||||||||||||||||||||||
| 89 | 22 | my $app_dir = File::Basename::dirname($plack_app); | |||||||||||||||||||||||||||||||||||||
| 90 | 22 | foreach my $srch (@search_locations) | |||||||||||||||||||||||||||||||||||||
| 91 | { | ||||||||||||||||||||||||||||||||||||||
| 92 | 44 | ▶ | if ( -d File::Spec->catdir( $app_dir, $srch, "environments" ) ) | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 93 | { | ||||||||||||||||||||||||||||||||||||||
| 94 | 22 | $app_dir = Cwd::abs_path( File::Spec->catdir( $app_dir, $srch ) ); | |||||||||||||||||||||||||||||||||||||
| 95 | 22 | last; | |||||||||||||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||||||||||||
| 98 | 22 | push( @dirs, $app_dir ); | |||||||||||||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||||||
| 101 | 22 | return @dirs; | |||||||||||||||||||||||||||||||||||||
| 102 | 2 | }; | |||||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||||||
| 104 | sub plack_app_dir | ||||||||||||||||||||||||||||||||||||||
| 105 | 6 | ▶ | { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
plack_app_dir: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 106 | 6 | my @cfg_base = @_; | |||||||||||||||||||||||||||||||||||||
| 107 | 6 | ▶ | 0 == scalar(@cfg_base) | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 108 | or croak "plack_app_dir(), not plack_app_dir(" . join( ",", ("\$") x scalar(@cfg_base) ) . ")"; | ||||||||||||||||||||||||||||||||||||||
| 109 | 6 | return $plack_app_dir->(); | |||||||||||||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||||||||||
| 112 | =head2 plack_env_dir | ||||||||||||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||||||||||
| 114 | Returns the environment directory of a L<Plack> application. | ||||||||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||||||||
| 116 | =cut | ||||||||||||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||||||||||||
| 118 | 11 | ▶ | my $plack_env_dir = sub { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||||||||||||
| 119 | 11 | my @cfg_base = @_; | |||||||||||||||||||||||||||||||||||||
| 120 | 11 | my @dirs; | |||||||||||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||||||||||||
| 122 | defined $ENV{PLACK_ENV} | ||||||||||||||||||||||||||||||||||||||
| 123 | 11 | ▶ | and push( @dirs, map { File::Spec->catdir( $_, "environments", $ENV{PLACK_ENV}, @cfg_base ) } $plack_app_dir->() ); | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||||||||||||
| 125 | 11 | return @dirs; | |||||||||||||||||||||||||||||||||||||
| 126 | 2 | }; | |||||||||||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||||||||||||
| 128 | sub plack_env_dir | ||||||||||||||||||||||||||||||||||||||
| 129 | 6 | ▶ | { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
plack_env_dir: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 130 | 6 | my @cfg_base = @_; | |||||||||||||||||||||||||||||||||||||
| 131 | 6 | return $plack_env_dir->(@cfg_base); | |||||||||||||||||||||||||||||||||||||
| 132 | } | ||||||||||||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||||||||||||
| 134 | 2 | my $registered; | |||||||||||||||||||||||||||||||||||||
| 135 | 2 | ▶ | File::ConfigDir::_plug_dir_source( $plack_app_dir, ++$registered ) | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%2/4
$registered || File::ConfigDir::_plug_dir_source($plack_app_dir, ++$registered) && File::ConfigDir::_plug_dir_source($plack_env_dir)
File::ConfigDir::_plug_dir_source($plack_app_dir, ++$registered) and File::ConfigDir::_plug_dir_source($plack_env_dir)
MC/DC0%0/3
$registered || File::ConfigDir::_plug_dir_source($plack_app_dir, ++$registered) && File::ConfigDir::_plug_dir_source($plack_env_dir)
$registered
File::ConfigDir::_plug_dir_source($plack_app_dir, ++$registered)
File::ConfigDir::_plug_dir_source($plack_env_dir)
Truth table0%0/4
A || B and C
A= $registeredB= File::ConfigDir::_plug_dir_source($plack_app_dir, ++$registered)C= File::ConfigDir::_plug_dir_source($plack_env_dir)
| |||||||||||||||||||||||||||||||||||||||
| 136 | and File::ConfigDir::_plug_dir_source($plack_env_dir) | ||||||||||||||||||||||||||||||||||||||
| 137 | unless $registered; | ||||||||||||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||||||||||||
| 139 | =head1 AUTHOR | ||||||||||||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||||||||||||
| 141 | Jens Rehsack, C<< <rehsack at cpan.org> >> | ||||||||||||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||||||||||||
| 143 | =head1 BUGS | ||||||||||||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||||||||||||
| 145 | Please report any bugs or feature requests to | ||||||||||||||||||||||||||||||||||||||
| 146 | C<bug-file-configdir-plack at rt.cpan.org>, or through the web interface at | ||||||||||||||||||||||||||||||||||||||
| 147 | L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=File-ConfigDir-Plack>. | ||||||||||||||||||||||||||||||||||||||
| 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<http://rt.cpan.org/NoAuth/Bugs.html?Dist=File-ConfigDir-Plack> | ||||||||||||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||||||||||||
| 165 | =item * AnnoCPAN: Annotated CPAN documentation | ||||||||||||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||||||||||||
| 167 | L<http://annocpan.org/dist/File-ConfigDir-Plack> | ||||||||||||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||||||||||||
| 169 | =item * CPAN Ratings | ||||||||||||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||||||||||||
| 171 | L<http://cpanratings.perl.org/d/File-ConfigDir-Plack> | ||||||||||||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||||||||||||
| 173 | =item * Search CPAN | ||||||||||||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||||||||||||
| 175 | L<http://search.cpan.org/dist/File-ConfigDir-Plack/> | ||||||||||||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||||||||||||
| 177 | =back | ||||||||||||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||||||||||||
| 179 | =head1 ACKNOWLEDGEMENTS | ||||||||||||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||||||||||||
| 181 | Celogeek San inspired that module by including L<MooX::ConfigFromFile> | ||||||||||||||||||||||||||||||||||||||
| 182 | into L<Jedi>. | ||||||||||||||||||||||||||||||||||||||
| 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<http://dev.perl.org/licenses/> for more information. | ||||||||||||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||||||||||||
| 194 | =cut | ||||||||||||||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||||||||||||
| 196 | 2 | 1; # End of File::ConfigDir::Plack | |||||||||||||||||||||||||||||||||||||