File Coverage

blib/lib/Config/Micro.pm
Criterion Covered Total %
statement 19 19 100.0
branch 2 2 100.0
condition 6 8 75.0
subroutine 5 5 100.0
pod 1 1 100.0
total 33 35 94.2


line stmt bran cond sub pod time code
1             package Config::Micro;
2              
3 2     2   107453 use strict;
  2         6  
  2         65  
4 2     2   11 use warnings FATAL => 'all';
  2         4  
  2         76  
5 2     2   10 use File::Spec;
  2         16  
  2         44  
6 2     2   11 use File::Basename 'dirname';
  2         3  
  2         2071  
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             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             sub file {
59 5     5 1 13308 my ($class, %opts) = @_;
60 5   100     35 $opts{env} ||= $ENV{PLACK_ENV} || 'development';
      66        
61 5   66     52 $opts{dir} ||= File::Spec->catdir('..', 'etc');
62 5         19 my ($caller_class, $caller_file, $line) = caller();
63 5         204 my $basedir = dirname($caller_file);
64 5 100       61 my $confdir = File::Spec->file_name_is_absolute($opts{dir}) ?
65             $opts{dir} :
66             File::Spec->catdir($basedir, $opts{dir})
67             ;
68 5         67 return File::Spec->catfile($confdir, $opts{env}. '.pl');
69             }
70              
71             =head1 AUTHOR
72              
73             ytnobody, C<< >>
74              
75             =head1 BUGS
76              
77             Please report any bugs or feature requests to C, or through
78             the web interface at L. 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
98              
99             =item * AnnoCPAN: Annotated CPAN documentation
100              
101             L
102              
103             =item * CPAN Ratings
104              
105             L
106              
107             =item * Search CPAN
108              
109             L
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
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             1; # End of Config::Micro