| 1 | package Shell::Amazon::S3::ConfigLoader; | ||||||||||||||||||||
| 2 | 1 | ▶ | use Moose; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 3 | 1 | ▶ | use YAML; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 4 | 1 | ▶ | use File::HomeDir; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 5 | 1 | ▶ | use Path::Class qw(file); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 6 | 1 | ▶ | use ExtUtils::MakeMaker (); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 7 | |||||||||||||||||||||
| 8 | has 'changed' => ( | ||||||||||||||||||||
| 9 | is => 'rw', | ||||||||||||||||||||
| 10 | isa => 'Int', | ||||||||||||||||||||
| 11 | 0 | ▶ | default => sub {0}, | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||
| 12 | 1 | ); | |||||||||||||||||||
| 13 | |||||||||||||||||||||
| 14 | has 'conf' => ( | ||||||||||||||||||||
| 15 | is => 'rw', | ||||||||||||||||||||
| 16 | 0 | ▶ | default => sub { file( File::HomeDir->my_home, ".psh3ll" ) }, | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||
| 17 | 1 | ); | |||||||||||||||||||
| 18 | |||||||||||||||||||||
| 19 | sub prompt { | ||||||||||||||||||||
| 20 | 0 | ▶ | my ( $self, $prompt ) = @_; | ||||||||||||||||||
|
Subroutine
prompt: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 21 | 0 | my $value = ExtUtils::MakeMaker::prompt($prompt); | |||||||||||||||||||
| 22 | 0 | $self->changed( $self->changed + 1 ); | |||||||||||||||||||
| 23 | 0 | return $value; | |||||||||||||||||||
| 24 | } | ||||||||||||||||||||
| 25 | |||||||||||||||||||||
| 26 | # TODO: More testable | ||||||||||||||||||||
| 27 | # we need to inject access key and secret access key outsied | ||||||||||||||||||||
| 28 | sub load { | ||||||||||||||||||||
| 29 | 0 | ▶ | my $self = shift; | ||||||||||||||||||
|
Subroutine
load: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||
| 30 | 0 | ▶ | my $config = eval { YAML::LoadFile( $self->conf ) } || {}; | ||||||||||||||||||
|
Condition0%0/2
eval { || {}
MC/DC0%0/1
eval {
do {
YAML::LoadFile($self->conf)
}
} || {}
eval {
do {
YAML::LoadFile($self->conf)
}
}
Truth table0%0/2
A
A= eval {
do {
YAML::LoadFile($self->conf)
}
}
| |||||||||||||||||||||
| 31 | 0 | ▶ | $config->{aws_access_key_id} ||= $self->prompt("AWS access key:"); | ||||||||||||||||||
|
Condition0%0/3
$config->{"aws_access_key_id"} ||= $self->prompt("AWS access key:")
MC/DC0%0/2
$config->{"aws_access_key_id"} ||= $self->prompt("AWS access key:")
$config->{"aws_access_key_id"}
$self->prompt("AWS access key:")
Truth table0%0/3
A ||= B
A= $config->{"aws_access_key_id"}B= $self->prompt("AWS access key:")
| |||||||||||||||||||||
| 32 | $config->{aws_secret_access_key} | ||||||||||||||||||||
| 33 | 0 | ▶ | ||= $self->prompt("AWS secret access key:"); | ||||||||||||||||||
|
Condition0%0/3
$config->{"aws_secret_access_key"} ||= $self->prompt("AWS secret access key:")
MC/DC0%0/2
$config->{"aws_secret_access_key"} ||= $self->prompt("AWS secret access key:")
$config->{"aws_secret_access_key"}
$self->prompt("AWS secret access key:")
Truth table0%0/3
A ||= B
A= $config->{"aws_secret_access_key"}B= $self->prompt("AWS secret access key:")
| |||||||||||||||||||||
| 34 | 0 | $self->save($config); | |||||||||||||||||||
| 35 | 0 | return $config; | |||||||||||||||||||
| 36 | } | ||||||||||||||||||||
| 37 | |||||||||||||||||||||
| 38 | sub update { | ||||||||||||||||||||
| 39 | 0 | ▶ | my ( $self, $key, $value ) = @_; | ||||||||||||||||||
|
Subroutine
update: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||
| 40 | 0 | ▶ | my $config = eval { YAML::LoadFile( $self->conf ) } || {}; | ||||||||||||||||||
|
Condition0%0/2
eval { || {}
MC/DC0%0/1
eval {
do {
YAML::LoadFile($self->conf)
}
} || {}
eval {
do {
YAML::LoadFile($self->conf)
}
}
Truth table0%0/2
A
A= eval {
do {
YAML::LoadFile($self->conf)
}
}
| |||||||||||||||||||||
| 41 | 0 | $config->{$key} = $value; | |||||||||||||||||||
| 42 | 0 | $self->changed( $self->changed + 1 ); | |||||||||||||||||||
| 43 | 0 | $self->save($config); | |||||||||||||||||||
| 44 | } | ||||||||||||||||||||
| 45 | |||||||||||||||||||||
| 46 | sub save { | ||||||||||||||||||||
| 47 | 0 | ▶ | my ( $self, $conf ) = @_; | ||||||||||||||||||
|
Subroutine
save: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||
| 48 | 0 | ▶ | if ( $self->changed ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 49 | 0 | YAML::DumpFile( $self->conf, $conf ); | |||||||||||||||||||
| 50 | 0 | chmod 0600, $self->conf; | |||||||||||||||||||
| 51 | } | ||||||||||||||||||||
| 52 | 0 | $self->changed(0); | |||||||||||||||||||
| 53 | } | ||||||||||||||||||||
| 54 | |||||||||||||||||||||
| 55 | 1 | __PACKAGE__->meta->make_immutable; | |||||||||||||||||||
| 56 | |||||||||||||||||||||
| 57 | 1 | 1; | |||||||||||||||||||