| 1 | package Config::Micro; | ||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||
| 3 | 3 | ▶ | use strict; | ||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||
| 4 | 3 | ▶ | use warnings FATAL => 'all'; | ||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||
| 5 | 3 | ▶ | use File::Spec; | ||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||
| 6 | 3 | ▶ | use File::Basename 'dirname'; | ||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||
| 8 | =head1 NAME | ||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||
| 10 | Config::Micro - micro config loader | ||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||
| 12 | =head1 VERSION | ||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||
| 14 | Version 0.02 | ||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||
| 16 | =cut | ||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||
| 18 | 3 | our $VERSION = '0.02'; | |||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||
| 21 | =head1 SYNOPSIS | ||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||
| 23 | package Your::App::Class; | ||||||||||||||||||||||||
| 24 | use Config::Micro; | ||||||||||||||||||||||||
| 25 | use File::Spec; | ||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||
| 27 | my $conf_dir = File::Spec->catdir(qw/.. etc/); | ||||||||||||||||||||||||
| 28 | my $conf_file = Config::Micro->file( env => 'development', dir => $conf_dir ); | ||||||||||||||||||||||||
| 29 | my $config = require( $conf_file ); | ||||||||||||||||||||||||
| 30 | ... | ||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||
| 32 | =head1 SUBROUTINES/METHODS | ||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||
| 34 | =head2 file | ||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||
| 36 | Return a path of config file that matches for application environment. | ||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||
| 38 | You may specify following options. | ||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||
| 40 | =over 4 | ||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||
| 42 | =item env | ||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||
| 44 | Specifier for deploy environment. | ||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||
| 46 | Default is $ENV{PLACK_ENV} || 'development' . | ||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||
| 48 | =item dir | ||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||
| 50 | Specifier for dir of config file. | ||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||
| 52 | Default is '../etc' . | ||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||
| 54 | =back | ||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||
| 56 | =cut | ||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||
| 58 | 5 | ▶ | sub file { | ||||||||||||||||||||||
|
Subroutine
file: called CC=5 SCAR=16.2
Pod
documented
| |||||||||||||||||||||||||
| 59 | 5 | my ($class, %opts) = @_; | |||||||||||||||||||||||
| 60 | 5 | ▶ | $opts{env} ||= $ENV{PLACK_ENV} || 'development'; | ||||||||||||||||||||||
|
Condition80%4/5
$opts{"env"} ||= $ENV{"PLACK_ENV"} || "development"
$ENV{'PLACK_ENV'} || 'development'
MC/DC0%0/2
$opts{"env"} ||= $ENV{"PLACK_ENV"} || "development"
$opts{"env"}
$ENV{'PLACK_ENV'}
Truth table66%2/3
A ||= B
A= $opts{"env"}B= $ENV{'PLACK_ENV'}
| |||||||||||||||||||||||||
| 61 | 5 | ▶ | $opts{dir} ||= File::Spec->catdir('..', 'etc'); | ||||||||||||||||||||||
|
Condition66%2/3
$opts{"dir"} ||= "File::Spec"->catdir("..", "etc")
MC/DC0%0/2
$opts{"dir"} ||= "File::Spec"->catdir("..", "etc")
$opts{"dir"}
"File::Spec"->catdir("..", "etc")
Truth table66%2/3
A ||= B
A= $opts{"dir"}B= "File::Spec"->catdir("..", "etc")
| |||||||||||||||||||||||||
| 62 | 5 | my ($caller_class, $caller_file, $line) = caller(); | |||||||||||||||||||||||
| 63 | 5 | my $basedir = dirname($caller_file); | |||||||||||||||||||||||
| 64 | my $confdir = File::Spec->file_name_is_absolute($opts{dir}) ? | ||||||||||||||||||||||||
| 65 | $opts{dir} : | ||||||||||||||||||||||||
| 66 | File::Spec->catdir($basedir, $opts{dir}) | ||||||||||||||||||||||||
| 67 | 5 | ▶ | ; | ||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||
| 68 | 5 | return File::Spec->catfile($confdir, $opts{env}. '.pl'); | |||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||
| 71 | =head1 AUTHOR | ||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||
| 73 | ytnobody, C<< <ytnobody aaaattttt gmail> >> | ||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||
| 75 | =head1 BUGS | ||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||
| 77 | Please report any bugs or feature requests to C<bug-config-micro at rt.cpan.org>, or through | ||||||||||||||||||||||||
| 78 | the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Config-Micro>. I will be notified, and then you'll | ||||||||||||||||||||||||
| 79 | automatically be notified of progress on your bug as I make changes. | ||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||
| 84 | =head1 SUPPORT | ||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||
| 86 | You can find documentation for this module with the perldoc command. | ||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||
| 88 | perldoc Config::Micro | ||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||
| 91 | You can also look for information at: | ||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||
| 93 | =over 4 | ||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||
| 95 | =item * RT: CPAN's request tracker (report bugs here) | ||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||
| 97 | L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Config-Micro> | ||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||
| 99 | =item * AnnoCPAN: Annotated CPAN documentation | ||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||
| 101 | L<http://annocpan.org/dist/Config-Micro> | ||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||
| 103 | =item * CPAN Ratings | ||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||
| 105 | L<http://cpanratings.perl.org/d/Config-Micro> | ||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||
| 107 | =item * Search CPAN | ||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||
| 109 | L<http://search.cpan.org/dist/Config-Micro/> | ||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||
| 111 | =back | ||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||
| 114 | =head1 ACKNOWLEDGEMENTS | ||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||
| 117 | =head1 LICENSE AND COPYRIGHT | ||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||
| 119 | Artistic | ||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||
| 121 | This program is free software; you can redistribute it and/or modify it | ||||||||||||||||||||||||
| 122 | under the terms of the the Artistic License (2.0). You may obtain a | ||||||||||||||||||||||||
| 123 | copy of the full license at: | ||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||
| 125 | L<http://www.perlfoundation.org/artistic_license_2_0> | ||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||
| 127 | Any use, modification, and distribution of the Standard or Modified | ||||||||||||||||||||||||
| 128 | Versions is governed by this Artistic License. By using, modifying or | ||||||||||||||||||||||||
| 129 | distributing the Package, you accept this license. Do not use, modify, | ||||||||||||||||||||||||
| 130 | or distribute the Package, if you do not accept this license. | ||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||
| 132 | If your Modified Version has been derived from a Modified Version made | ||||||||||||||||||||||||
| 133 | by someone other than you, you are nevertheless required to ensure that | ||||||||||||||||||||||||
| 134 | your Modified Version complies with the requirements of this license. | ||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||
| 136 | This license does not grant you the right to use any trademark, service | ||||||||||||||||||||||||
| 137 | mark, tradename, or logo of the Copyright Holder. | ||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||
| 139 | This license includes the non-exclusive, worldwide, free-of-charge | ||||||||||||||||||||||||
| 140 | patent license to make, have made, use, offer to sell, sell, import and | ||||||||||||||||||||||||
| 141 | otherwise transfer the Package with respect to any patent claims | ||||||||||||||||||||||||
| 142 | licensable by the Copyright Holder that are necessarily infringed by the | ||||||||||||||||||||||||
| 143 | Package. If you institute patent litigation (including a cross-claim or | ||||||||||||||||||||||||
| 144 | counterclaim) against any party alleging that the Package constitutes | ||||||||||||||||||||||||
| 145 | direct or contributory patent infringement, then this Artistic License | ||||||||||||||||||||||||
| 146 | to you shall terminate on the date that such litigation is filed. | ||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||
| 148 | Disclaimer of Warranty: THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER | ||||||||||||||||||||||||
| 149 | AND CONTRIBUTORS "AS IS' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES. | ||||||||||||||||||||||||
| 150 | THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR | ||||||||||||||||||||||||
| 151 | PURPOSE, OR NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY | ||||||||||||||||||||||||
| 152 | YOUR LOCAL LAW. UNLESS REQUIRED BY LAW, NO COPYRIGHT HOLDER OR | ||||||||||||||||||||||||
| 153 | CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, OR | ||||||||||||||||||||||||
| 154 | CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE OF THE PACKAGE, | ||||||||||||||||||||||||
| 155 | EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||
| 158 | =cut | ||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||
| 160 | 3 | 1; # End of Config::Micro | |||||||||||||||||||||||