lib/App/gh/Config.pm

filter: Statementstmt 35.4% 17 / 48 Branchbran 0.0% 0 / 16 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 41.6% 5 / 12 Podpod 0.0% 0 / 7 totaltotal 26.5% 22 / 83 CC 11 SCAR 36.5
CC
11
Cov
27%
parse
90.0
current
6.0
global
6.0
CRAP 38.5
« lib/App/gh/Command/Import.pm ↑ Summary lib/App/gh/Command/Update.pm »
1 package App::gh::Config;
2 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use File::HomeDir ();
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use File::Spec;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use File::Basename qw(dirname);
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8  
9  
10  
11 2 my %_parse_memoize;
12 # XXX: use Config::Tiny to parse ini format config.
13 0 ▶sub parse {
Subroutine parse: not called CC=9 SCAR=45.0
Pod undocumented
14 0 my ( $class, $file ) = @_;
15  
16 # Return cached result.
17 0 $file = File::Spec->rel2abs($file);
18 0 ▶ return $_parse_memoize{$file} if exists $_parse_memoize{$file};
Branch: 1 branch
BranchTrueFalseTotal
if exists $_parse_memoize{$file} 0 0 0
19  
20 0 my %config;
21 0 for my $line (split "\n", qx(git config --list -f '$file')) {
22 # $line = foo.bar.baz=value
23 0 ▶ if (my ($key, $value) = ($line =~ m/^([^=]+)=(.*)/)) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = $line =~ /^([^=]+)=(.*)/) 0 0 0
24 0 my $h = \%config;
25 0 ▶ if ($key eq 'include.path') {
Branch: 1 branch
BranchTrueFalseTotal
if ($key eq "include.path") 0 0 0
26 0 ▶ my $path = File::Spec->file_name_is_absolute($value) ? $value : File::Spec->rel2abs($value, dirname($file));
Branch: 1 branch
BranchTrueFalseTotal
'File::Spec'->file_name_is_absolute($value) ? : 0 0 0
27 0 %config = (%config, %{ $class->parse($path) });
28 # Uncomment this to get rid of "include.path" in %config
29 #next;
30 }
31 0 my @keys = split /\./, $key;
32 0 ▶ next unless @keys;
Branch: 1 branch
BranchTrueFalseTotal
unless @keys 0 0 0
33 # Create empty hashref.
34 # %config = (foo => {bar => ($h = {})})
35 0 for (@keys[0..$#keys-1]) {
36 0 ▶ $h->{$_} = {} unless exists $h->{$_};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $h->{$_} 0 0 0
37 0 $h = $h->{$_};
38 }
39 # $config{foo}{bar}{baz} = $value;
40 0 $h->{$keys[-1]} = $value;
41 }
42 }
43  
44 # Cache result not to invoke 'git' command frequently.
45 0 $_parse_memoize{$file} = \%config;
46 0 return \%config;
47 }
48  
49  
50 0 ▶sub current {
Subroutine current: not called CC=2 SCAR=17.9
Pod undocumented
51 0 my $class = shift;
52 0 my $path = File::Spec->join(".git","config");
53 0 ▶ return unless -e $path;
Branch: 1 branch
BranchTrueFalseTotal
unless -e $path 0 0 0
54  
55 # TODO: prevent error
56 0 return $class->parse( $path );
57 }
58  
59 # when command trying to read config, we should let it die, and provide another
60 # method to check github id and token.
61 # XXX: abandoned, since we are using Net::GitHub V3
62 0 ▶sub github_token { return $_[0]->global()->{github}->{token}; }
Subroutine github_token: not called CC=1 SCAR=6.9
Pod undocumented
63  
64 0 ▶sub github_password { return $_[0]->global()->{github}->{password}; }
Subroutine github_password: not called CC=1 SCAR=6.9
Pod undocumented
65  
66 # Auth with OAuth
67 0 ▶sub github_access_token { return $_[0]->global()->{github}->{access_token}; }
Subroutine github_access_token: not called CC=1 SCAR=6.9
Pod undocumented
68  
69 0 ▶sub github_id { return $_[0]->global()->{github}->{user}; }
Subroutine github_id: not called CC=1 SCAR=6.9
Pod undocumented
70  
71 0 ▶sub global {
Subroutine global: not called CC=2 SCAR=17.9
Pod undocumented
72 0 my $class = shift;
73 0 my $path = File::Spec->join(File::HomeDir->my_home, '.gitconfig');
74 0 ▶ return unless -e $path;
Branch: 1 branch
BranchTrueFalseTotal
unless -e $path 0 0 0
75 0 return $class->parse( $path );
76 }
77  
78 2 1;
« lib/App/gh/Command/Import.pm ↑ Summary lib/App/gh/Command/Update.pm »