Config-Micro

 view release on metacpan or  search on metacpan

lib/Config/Micro.pm  view on Meta::CPAN

package Config::Micro;

use strict;
use warnings FATAL => 'all';
use File::Spec;
use File::Basename 'dirname';

=head1 NAME

Config::Micro - micro config loader

=head1 VERSION

Version 0.02

=cut

our $VERSION = '0.02';


=head1 SYNOPSIS

    package Your::App::Class;
    use Config::Micro;
    use File::Spec;
    
    my $conf_dir  = File::Spec->catdir(qw/.. etc/);
    my $conf_file = Config::Micro->file( env => 'development', dir => $conf_dir );
    my $config = require( $conf_file );
    ...

=head1 SUBROUTINES/METHODS

=head2 file

Return a path of config file that matches for application environment.

You may specify following options.

=over 4

=item env

Specifier for deploy environment.

Default is $ENV{PLACK_ENV} || 'development' .

=item dir

Specifier for dir of config file.

Default is '../etc' .

=back

=cut

sub file {
    my ($class, %opts) = @_;
    $opts{env} ||= $ENV{PLACK_ENV} || 'development';
    $opts{dir} ||= File::Spec->catdir('..', 'etc'); 
    my ($caller_class, $caller_file, $line) = caller();
    my $basedir = dirname($caller_file);
    my $confdir = File::Spec->file_name_is_absolute($opts{dir}) ? 
        $opts{dir} : 
        File::Spec->catdir($basedir, $opts{dir})
    ;
    return File::Spec->catfile($confdir, $opts{env}. '.pl');
}

=head1 AUTHOR

ytnobody, C<< <ytnobody aaaattttt gmail> >>

=head1 BUGS

Please report any bugs or feature requests to C<bug-config-micro at rt.cpan.org>, or through
the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Config-Micro>.  I will be notified, and then you'll
automatically be notified of progress on your bug as I make changes.




=head1 SUPPORT

You can find documentation for this module with the perldoc command.

    perldoc Config::Micro



( run in 1.430 second using v1.01-cache-2.11-cpan-2398b32b56e )