| 1 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 2 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||||
| 4 | package Net::Amazon::Config; | ||||||||||||||||||||||||||||||
| 5 | # ABSTRACT: Manage Amazon Web Services credentials | ||||||||||||||||||||||||||||||
| 6 | 1 | our $VERSION = '0.002'; # VERSION | |||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||
| 8 | 1 | ▶ | use Carp (); | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 9 | 1 | ▶ | use Config::Tiny 2.12 (); | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 10 | 1 | ▶ | use Net::Amazon::Config::Profile (); | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 11 | 1 | ▶ | use Params::Validate 0.91 (); | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 12 | 1 | ▶ | use Path::Class 0.17 (); | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 13 | 1 | ▶ | use Object::Tiny 1.06 qw( | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 14 | config_dir | ||||||||||||||||||||||||||||||
| 15 | config_file | ||||||||||||||||||||||||||||||
| 16 | config_path | ||||||||||||||||||||||||||||||
| 17 | 1 | ); | |||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||
| 19 | 1 | ▶ | use constant IS_WIN32 => $^O eq 'MSWin32'; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||
| 21 | 0 | ▶ | sub _default_dir { | ||||||||||||||||||||||||||||
|
Subroutine
_default_dir: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||
| 22 | 0 | my $base = Path::Class::dir( IS_WIN32 ? $ENV{USERPROFILE} : $ENV{HOME} ); | |||||||||||||||||||||||||||||
| 23 | 0 | return $base->subdir('.amazon')->absolute->stringify; | |||||||||||||||||||||||||||||
| 24 | } | ||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||
| 26 | 1 | ▶ | sub new { | ||||||||||||||||||||||||||||
|
Subroutine
new: called CC=5 SCAR=19.1
Pod
documented
| |||||||||||||||||||||||||||||||
| 27 | 1 | my $class = shift; | |||||||||||||||||||||||||||||
| 28 | my %args = Params::Validate::validate( | ||||||||||||||||||||||||||||||
| 29 | @_, | ||||||||||||||||||||||||||||||
| 30 | { | ||||||||||||||||||||||||||||||
| 31 | config_dir => { default => $ENV{NET_AMAZON_CONFIG_DIR} || _default_dir, }, | ||||||||||||||||||||||||||||||
| 32 | 1 | ▶ | config_file => { default => $ENV{NET_AMAZON_CONFIG} || 'profiles.conf', } | ||||||||||||||||||||||||||||
|
Condition40%2/5
$ENV{'NET_AMAZON_CONFIG_DIR'} || _default_dir()
$ENV{'NET_AMAZON_CONFIG'} || 'profiles.conf'
MC/DC0%0/2
$ENV{'NET_AMAZON_CONFIG_DIR'} || _default_dir()
$ENV{'NET_AMAZON_CONFIG_DIR'}
_default_dir()
MC/DC0%0/1
$ENV{'NET_AMAZON_CONFIG'} || 'profiles.conf'
$ENV{'NET_AMAZON_CONFIG'}
Truth table33%1/3
A || B
A= $ENV{'NET_AMAZON_CONFIG_DIR'}B= _default_dir()
Truth table50%1/2
A
A= $ENV{'NET_AMAZON_CONFIG'}
| |||||||||||||||||||||||||||||||
| 33 | } | ||||||||||||||||||||||||||||||
| 34 | ); | ||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||
| 36 | 1 | ▶ | if ( Path::Class::file( $args{config_file} )->is_absolute ) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 37 | 0 | $args{config_path} = $args{config_file}; | |||||||||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||||||||
| 39 | else { | ||||||||||||||||||||||||||||||
| 40 | $args{config_path} = | ||||||||||||||||||||||||||||||
| 41 | 1 | Path::Class::dir( $args{config_dir} )->file( $args{config_file} ); | |||||||||||||||||||||||||||||
| 42 | } | ||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||
| 44 | 1 | ▶ | unless ( -r $args{config_path} ) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 45 | 0 | die "Could not find readable file $args{config_path}"; | |||||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||
| 48 | 1 | return bless \%args, $class; | |||||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||
| 51 | 1 | ▶ | sub get_profile { | ||||||||||||||||||||||||||||
|
Subroutine
get_profile: called CC=4 SCAR=14.5
Pod
documented
| |||||||||||||||||||||||||||||||
| 52 | 1 | my ( $self, $profile_name ) = @_; | |||||||||||||||||||||||||||||
| 53 | 1 | my $config = Config::Tiny->read( $self->config_path ); | |||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||
| 55 | 1 | ▶ | $profile_name = $config->{_}{default} unless defined $profile_name; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 56 | 1 | ▶ | my $params = $config->{$profile_name} | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 57 | or return; | ||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||
| 59 | 1 | $params->{profile_name} = $profile_name; | |||||||||||||||||||||||||||||
| 60 | 1 | my $profile = eval { Net::Amazon::Config::Profile->new($params) }; | |||||||||||||||||||||||||||||
| 61 | 1 | ▶ | if ($@) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 62 | 0 | Carp::croak "Invalid profile: $@"; | |||||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||||
| 64 | 1 | return $profile; | |||||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||
| 67 | 1 | 1; | |||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||
| 69 | __END__ | ||||||||||||||||||||||||||||||