Config-Station

 view release on metacpan or  search on metacpan

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

package Config::Station;
$Config::Station::VERSION = '0.002001';
# ABSTRACT: Load configs from files and the environment

use Moo;
use warnings NONFATAL => 'all';

use JSON::MaybeXS;
use IO::All;
use Try::Tiny;
use Module::Runtime 'use_module';

has _debug => (
   is => 'ro',
   init_arg => undef,
   lazy => 1,
   default => sub {
      my $self = shift;

      exists $ENV{'DEBUG_' . $self->_env_key}
         ? $ENV{'DEBUG_' . $self->_env_key}
         : $self->__debug
   },
);

has __debug => (
   is => 'ro',
   init_arg => 'debug',
);

has _env_key => (
   is => 'ro',
   init_arg => 'env_key',
   required => 1,
);

has _location => (
   is => 'ro',
   init_arg => undef,
   lazy => 1,
   default => sub {
      my $self = shift;

      my $path = $ENV{'FILE_' . $self->_env_key} ||
         $self->__location;

      warn "No path specified to load config from\n"
         if !$path && $self->_debug;

      return $path
   },
);

has __location => (
   is => 'ro',
   init_arg => 'location',
);

has _config_class => (
   is => 'ro',
   init_arg => 'config_class',
   required => 1,
);

has _decode_via => (
   is => 'ro',
   init_arg => 'decode_via',
   lazy => 1,
   builder => sub { \&decode_json },
);



( run in 0.575 second using v1.01-cache-2.11-cpan-39bf76dae61 )