blib/lib/Amazon/Credentials/Role/File.pm

filter: Statementstmt 98.0% 49 / 50 Branchbran 92.8% 13 / 14 Conditioncond 50.0% 1 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 100% 10 / 10 Podpod n/a totaltotal 94.8% 73 / 77 CC 12 SCAR 12.2
CC
12
Cov
95%
_get_profile_sections
6.0
_get_profile
4.0
__ANON__
3.0
CRAP 3.4
« blib/lib/Amazon/Credentials/Provider/Process.pm ↑ Summary blib/lib/Amazon/Credentials/HTTP/UserAgent.pm »
1 package Amazon::Credentials::Role::File;
2  
3 14 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 14 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 14 ▶use 5.010;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 14 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 14 ▶use Role::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 14 ▶use Amazon::Credentials::Utils qw(choose);
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 ########################################################################
13 210 ▶sub _create_config_path {
Subroutine _create_config_path: called CC=2 SCAR=6.9
14 ########################################################################
15 210 my ( $self, $config ) = @_;
16  
17 210 require File::HomeDir;
18 210 File::HomeDir->import('home');
19  
20 210 my $fullpath = home() . q{/} . $config;
21  
22 210 ▶ return -e $fullpath ? $fullpath : q{};
Branch: 1 branch
BranchTrueFalseTotal
-e $fullpath ? : 146 64 210
23 }
24  
25 ########################################################################
26 105 ▶sub _get_profile_sections {
Subroutine _get_profile_sections: called CC=6 SCAR=18.0
27 ########################################################################
28 105 my ( $self, $profile ) = @_;
29  
30 105 require Config::Tiny;
31  
32 105 ▶ $profile ||= 'default';
Condition50%1/2
$profile ||= "default"
l!l
1050
MC/DC0%0/1
$profile ||= "default"
$profile
Truth table50%1/2
A
A= $profile
Aresult
11
00
33  
34 105 my @sections;
35  
36 105 foreach my $config (qw(.aws/config .aws/credentials)) {
37 210 my $fullpath = $self->_create_config_path($config);
38  
39 next
40 210 ▶ if !$fullpath;
Branch: 1 branch
BranchTrueFalseTotal
unless $fullpath 64 146 210
41  
42 146 my $ini = Config::Tiny->read($fullpath);
43  
44 146 ▶ if ( !$ini ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ini) 0 146 146
45 0 next;
46 }
47  
48 146 ▶ my $section = choose {
Subroutine __ANON__: called CC=3 SCAR=11.0
49  
50 return $ini->{$profile}
51 146 ▶ if $ini->{$profile};
Branch: 1 branch
BranchTrueFalseTotal
if $ini->{$profile} 35 111 146
52  
53 return $ini->{"profile $profile"}
54 111 ▶ if $ini->{"profile $profile"};
Branch: 1 branch
BranchTrueFalseTotal
if $$ini{"profile $profile"} 70 41 111
55 146 };
56  
57 next
58 146 ▶ if !$section;
Branch: 1 branch
BranchTrueFalseTotal
unless $section 41 105 146
59  
60 105 push @sections,
61 {
62 config => $config,
63 ini => $ini,
64 section => $section,
65 };
66 }
67  
68 105 return \@sections;
69 }
70  
71 ########################################################################
72 93 ▶sub _get_profile {
Subroutine _get_profile: called CC=4 SCAR=13.9
73 ########################################################################
74 93 my ( $self, $profile ) = @_;
75  
76 93 my $sections = $self->_get_profile_sections($profile);
77  
78 return
79 93 ▶ if !@{$sections};
Branch: 1 branch
BranchTrueFalseTotal
unless @{$sections;} 9 84 93
80  
81 84 my %profile;
82  
83 84 foreach my $entry ( @{$sections} ) {
84 93 foreach my $key ( keys %{ $entry->{section} } ) {
85 227 $profile{$key} = $entry->{section}{$key};
86 }
87 }
88  
89 84 return \%profile;
90 }
91  
92 14 1;
« blib/lib/Amazon/Credentials/Provider/Process.pm ↑ Summary blib/lib/Amazon/Credentials/HTTP/UserAgent.pm »