Config-AWS
    
    
  
  
  
view release on metacpan or search on metacpan
            "IO::Handle" : "0",
            "IPC::Open3" : "0",
            "Test::More" : "0",
            "Test::Pod" : "1.41"
         }
      },
      "runtime" : {
         "requires" : {
            "Exporter::Tiny" : "1",
            "Path::Tiny" : "0.076",
            "Ref::Util" : "0",
            "perl" : "5.010"
         }
      },
      "test" : {
         "recommends" : {
            "CPAN::Meta" : "2.120900"
         },
         "requires" : {
            "ExtUtils::MakeMaker" : "0",
            "File::Spec" : "0",
    - share
    - t
    - xt
provides:
  Config::AWS:
    file: lib/Config/AWS.pm
    version: '0.12'
requires:
  Exporter::Tiny: '1'
  Path::Tiny: '0.076'
  Ref::Util: '0'
  perl: '5.010'
resources:
  bugtracker: https://gitlab.com/jjatria/Config-AWS/issues
  repository: git://gitlab.com/jjatria/Config-AWS.git
version: '0.12'
x_Dist_Zilla:
  perl:
    version: '5.036000'
  plugins:
    -
lib/Config/AWS.pm view on Meta::CPAN
package Config::AWS;
# ABSTRACT: Parse AWS config files
use strict;
use warnings;
use Carp ();
use Ref::Util;
use Scalar::Util;
use Exporter::Shiny qw(
    read
    read_all
    list_profiles
    read_file
    read_string
    read_handle
    config_file
    credentials_file
lib/Config/AWS.pm view on Meta::CPAN
# Internal methods for parsing and validation
my $prepare = sub {
    # Input is given argument or credentials file (if exists) or config file.
    my $input = shift // do {
        my $cred_file = credentials_file();
        -r $cred_file ? $cred_file : config_file();
    };
    unless ( Ref::Util::is_ref $input ) {
        require Path::Tiny;
        my @lines = eval { Path::Tiny::path( $input )->lines };
        if ($@) {
            Carp::croak "Cannot read from $input: $@->{err}"
                if ref $@ && $@->isa('Path::Tiny::Error');
            Carp::croak $@;
        }
        return \@lines;
    }
    return [ $input->getlines ] if Scalar::Util::openhandle $input;
    if ( Ref::Util::is_blessed_ref $input ) {
        return [ $input->slurp ] if $input->isa('Path::Class::File');
        return [ $input->lines ] if $input->isa('Path::Tiny');
        Carp::croak 'Cannot read from objects of type ', ref $input;
    }
    return [ split /\R/, $$input ] if Ref::Util::is_scalarref $input;
    return $input                  if Ref::Util::is_arrayref  $input;
    Carp::croak "Could not use $input as source for ", (caller 1)[3];
};
my $read = sub {
    my ($lines, $target_profile) = @_;
    Carp::carp 'Reading config with only one line or less. Faulty input?'
        if @$lines <= 1;
lib/Config/AWS.pm view on Meta::CPAN
}
sub config_file {
    $ENV{AWS_CONFIG_FILE} // ( glob '~/.aws/config' )[0];
}
# Methods for compatibility with Config::INI interface
sub read_file {
    Carp::croak 'Filename is missing' unless @_;
    Carp::croak 'Argument was not a string' if Ref::Util::is_ref $_[0];
    $read->( $prepare->(shift), @_ );
}
sub read_string {
    Carp::croak 'String is missing' unless @_;
    Carp::croak 'Argument was not a string' if Ref::Util::is_ref $_[0];
    $read->( [ split /\R/, shift // '' ], @_ );
}
sub read_handle {
    Carp::croak 'Handle is missing' unless @_;
    Carp::croak 'Argument was not a handle' unless Scalar::Util::openhandle $_[0];
    $read->( [ shift->getlines ], @_ );
}
1;
t/00-report-prereqs.dd view on Meta::CPAN
                                      'IO::Handle' => '0',
                                      'IPC::Open3' => '0',
                                      'Test::More' => '0',
                                      'Test::Pod' => '1.41'
                                    }
                    },
       'runtime' => {
                      'requires' => {
                                      'Exporter::Tiny' => '1',
                                      'Path::Tiny' => '0.076',
                                      'Ref::Util' => '0',
                                      'perl' => '5.010'
                                    }
                    },
       'test' => {
                   'recommends' => {
                                     'CPAN::Meta' => '2.120900'
                                   },
                   'requires' => {
                                   'ExtUtils::MakeMaker' => '0',
                                   'File::Spec' => '0',
use Test2::V0;
use Test2::Tools::Spec;
use Config::AWS;
use Path::Tiny qw( path tempdir );
use Ref::Util qw( is_globref );
my $DIR = tempdir 'ConfigAWS-XXXXXXXXX';
$DIR->child('config/.aws')->mkpath;
$DIR->child('credentials/.aws')->mkpath;
$DIR->child('config/.aws/config')->touch->spew(<<'CONFIG');
[alternate]
root_key = alternate root value
parent =
( run in 1.167 second using v1.01-cache-2.11-cpan-c333fce770f )