App-Toot
view release on metacpan or search on metacpan
lib/App/Toot/Config.pm view on Meta::CPAN
our $VERSION = '0.04';
sub load {
my $class = shift;
my $section = shift;
if ( !defined $section ) {
die 'section is required';
}
my $config = _load_and_verify();
if ( !exists $config->{$section} ) {
die "$section section was not found in the config";
}
return $config->{$section};
}
sub _get_conf_dir {
my $name = 'toot';
lib/App/Toot/Config.pm view on Meta::CPAN
elsif ( -d "/etc/$name" ) {
$dir = '/etc';
}
else {
die "error: unable to find config directory\n";
}
return "$dir/$name";
}
sub _load_and_verify {
my $rc = _get_conf_dir() . '/config.ini';
unless ( -e $rc && -r $rc ) {
die "error: $rc does not exist or cannot be read\n";
}
my $config = Config::Tiny->read($rc);
unless ( defined $config->{'default'} ) {
die "default section in $rc is not defined\n";
lib/App/Toot/Config.pm view on Meta::CPAN
}
1;
__END__
=pod
=head1 NAME
App::Toot::Config - load and verify the config
=head1 SYNOPSIS
use App::Toot::Config;
my $config = App::Toot::Config->load( 'section name' );
=head1 DESCRIPTION
C<App::Toot::Config> loads settings for L<App::Toot>.
t/unit/lib-App-Toot-Config/load.t view on Meta::CPAN
username => 'test',
client_id => '12345',
client_secret => '67890',
access_token => 'abcde'
},
},
};
App::Toot::Test::override(
package => 'App::Toot::Config',
name => '_load_and_verify',
subref => sub { return EXPECTED_CONFIG() },
);
HAPPY_PATH: {
note( 'happy path' );
my $section = 'default';
my $config = $class->load($section);
is_deeply( $config, EXPECTED_CONFIG()->{$section}, 'expected config section is returned' );
( run in 0.331 second using v1.01-cache-2.11-cpan-73692580452 )