Installer/Configuration.pm

filter: Statementstmt 61.5% 64 / 104 Branchbran 30.4% 14 / 46 Conditioncond 32.0% 8 / 25 MC/DCmcdc 14.2% 2 / 14 Subroutinesub 81.4% 22 / 27 Podpod 0.0% 0 / 12 totaltotal 48.2% 110 / 228 CC 35 SCAR 27.7
CC
35
Cov
49%
effective_prepare_env
56.0
effective_version
42.0
effective_compute_deps
30.0
CRAP 15.9
« Installer/OS/linux/debian.pm ↑ Summary Installer/OS/linux/fedora.pm »
1 package LedgerSMB::Installer::Configuration v0.999.15;
2  
3 2 ▶use v5.20;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use experimental qw(signatures);
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 2 ▶use Cwd qw( getcwd );
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶use File::Spec;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 ▶use Symbol;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10  
11 2 ▶use HTTP::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 2 ▶use Log::Any qw($log);
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 2 my $http = HTTP::Tiny->new;
15  
16  
17 8 ▶sub new( $class, %args ) {
Subroutine new: called CC=6 SCAR=19.1
Pod undocumented
18 return bless {
19 # initialization options
20 _assume_yes => $args{assume_yes} // 0,
21 _installpath => $args{installpath} // 'ledgersmb',
22 _locallib => $args{locallib} // 'local',
23 _loglevel => $args{loglevel} // 'info',
24 _prep_env => $args{prepare_env},
25 _sys_pkgs => $args{sys_pkgs},
26 _verify_sig => $args{verify_sig} // 1,
27 _version => $args{version},
28 _uninstall_env => $args{uninstall_env},
29  
30 # internal state
31 8 ▶ _deps => undef,
Condition70%7/10
$args{"assume_yes"} // 0
l!l
08
$args{"installpath"} // "ledgersmb"
l!l
17
$args{"locallib"} // "local"
l!l
17
$args{"loglevel"} // "info"
l!l
08
$args{"verify_sig"} // 1
l!l
08
MC/DC0%0/1
$args{"assume_yes"} // 0
$args{"assume_yes"}
MC/DC100%1/1
$args{"installpath"} // "ledgersmb"
$args{"installpath"}
MC/DC100%1/1
$args{"locallib"} // "local"
$args{"locallib"}
MC/DC0%0/1
$args{"loglevel"} // "info"
$args{"loglevel"}
MC/DC0%0/1
$args{"verify_sig"} // 1
$args{"verify_sig"}
Truth table50%1/2
A
A= $args{"assume_yes"}
Aresult
11
00
Truth table100%2/2
A
A= $args{"installpath"}
Aresult
11
00
Truth table100%2/2
A
A= $args{"locallib"}
Aresult
11
00
Truth table50%1/2
A
A= $args{"loglevel"}
Aresult
11
00
Truth table50%1/2
A
A= $args{"verify_sig"}
Aresult
11
00
32 _cleanup_pkgs => [],
33 }, $class;
34 }
35  
36 4 ▶sub dependency_url($self, $distro, $id) {
Subroutine dependency_url: called CC=1 SCAR=0.0
Pod undocumented
37 4 return "https://download.ledgersmb.org/f/dependencies/$distro/$id\@$self->{_version}.json";
38 }
39  
40 0 ▶sub have_deps($self) {
Subroutine have_deps: not called CC=3 SCAR=24.8
Pod undocumented
41 return (defined $self->{_deps}
42 and defined $self->{_deps}->{packages}
43 0 ▶ and $self->{_deps}->{packages}->@*);
Condition0%0/6
defined $self->{'_deps'} && defined $self->{'_deps'}{'packages'} && @{$self->{'_deps'}{'packages'}}
!ll&&!rl&&r
000
defined $self->{"_deps"} and defined $self->{"_deps"}{"packages"}
!ll&&!rl&&r
000
MC/DC0%0/3
defined $self->{'_deps'} && defined $self->{'_deps'}{'packages'} && @{$self->{'_deps'}{'packages'}}
defined $self->{"_deps"} defined $self->{"_deps"}{"packages"} @{$self->{'_deps'}{'packages'}}
Truth table0%0/4
A and B && C
A= defined $self->{"_deps"}B= defined $self->{"_deps"}{"packages"}C= @{$self->{'_deps'}{'packages'}}
ABCresult
0XX0
10X0
1100
1111
44 }
45  
46 3 ▶sub retrieve_precomputed_deps($self, $name, $id) {
Subroutine retrieve_precomputed_deps: called CC=5 SCAR=16.3
Pod undocumented
47 3 ▶ return unless $name and $id;
Branch: 1 branch
BranchTrueFalseTotal
unless $name and $id 0 3 3
Condition33%1/3
$name and $id
!ll&&!rl&&r
003
MC/DC0%0/2
$name and $id
$name $id
Truth table33%1/3
A and B
A= $nameB= $id
ABresult
0X0
100
111
48  
49 3 my $url = $self->dependency_url($name, $id);
50  
51 3 $log->info( "Retrieving dependency listing from $url" );
52 3 my $r = $http->get( $url );
53 3 my $pkgs;
54 3 ▶ if ($r->{success}) {
Branch: 2 branches
BranchTrueFalseTotal
if ($r->{'success'}) { } 1 2 3
elsif ($r->{'status'} == 599) { } 1 1 2
55 1 $self->{_deps} = JSON::PP->new->utf8->decode( $r->{content} );
56 1 $pkgs = $self->{_deps}->{packages};
57 }
58 elsif ($r->{status} == 599) {
59 die $log->fatal(
60 'Error trying to retrieve precomputed dependencies: ' . $r->{content}
61 1 );
62 }
63 2 $self->{_deps_retrieved} = 1;
64 2 return ($self->{_deps}->{packages}, $self->{_deps}->{modules});
65 }
66  
67 2 ▶sub mark_pkgs_for_cleanup($self, $pkgs) {
Subroutine mark_pkgs_for_cleanup: called CC=1 SCAR=0.0
Pod undocumented
68 2 push $self->{_cleanup_pkgs}->@*, $pkgs->@*;
69 }
70  
71 1 ▶sub pkgs_for_cleanup($self) {
Subroutine pkgs_for_cleanup: called CC=1 SCAR=0.0
Pod undocumented
72 1 return $self->{_cleanup_pkgs}->@*;
73 }
74  
75 2 ▶sub normalize_paths($self) {
Subroutine normalize_paths: called CC=6 SCAR=18.3
Pod undocumented
76 2 my $installpath = $self->installpath;
77 2 ▶ if (not File::Spec->file_name_is_absolute( $installpath )) {
Branch: 1 branch
BranchTrueFalseTotal
unless ("File::Spec"->file_name_is_absolute($installpath)) 1 1 2
78 1 my @dirs = File::Spec->splitdir( $installpath );
79 1 ▶ if (@dirs) {
Branch: 1 branch
BranchTrueFalseTotal
if (@dirs) 1 0 1
80 1 ▶ if ($dirs[0] ne File::Spec->curdir) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dirs[0] ne "File::Spec"->curdir) 1 0 1
81 1 $self->installpath( File::Spec->catdir( getcwd(), $installpath ) );
82 }
83 }
84 }
85 2 my $locallib = $self->locallib;
86 2 ▶ if (not File::Spec->file_name_is_absolute( $locallib )) {
Branch: 1 branch
BranchTrueFalseTotal
if (not "File::Spec"->file_name_is_absolute($locallib)) 1 1 2
87 1 my @dirs = File::Spec->splitdir( $locallib );
88 1 ▶ if (@dirs == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (@dirs == 1) { } 1 0 1
89 1 $self->locallib( File::Spec->catdir( $installpath, $locallib ) );
90 }
91 else {
92 0 $self->locallib( File::Spec->catdir( getcwd(), $locallib ) );
93 }
94 }
95 }
96  
97 0 ▶sub effective_compute_deps( $self ) {
Subroutine effective_compute_deps: not called CC=5 SCAR=34.0
Pod undocumented
98 0 ▶ return '' unless $self->sys_pkgs;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->sys_pkgs 0 0 0
99 0 ▶ return '' if $self->{_deps};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_deps"} 0 0 0
100  
101 0 ▶ if (defined $self->compute_deps) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->compute_deps) 0 0 0
102 0 return $self->compute_deps;
103 }
104  
105 $log->warning( "Result of 'effective_compute_deps()' not reliable: "
106 . "no attempt to retrieve dependencies" )
107 0 ▶ unless $self->{_deps_retrieved};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"_deps_retrieved"} 0 0 0
108  
109 0 return 1;
110 }
111  
112 0 ▶sub effective_prepare_env( $self ) {
Subroutine effective_prepare_env: not called CC=7 SCAR=40.3
Pod undocumented
113 0 ▶ if (defined $self->prepare_env) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->prepare_env) 0 0 0
114 0 return $self->prepare_env;
115 }
116  
117 0 ▶ return 1 if $self->assume_yes;
Branch: 1 branch
BranchTrueFalseTotal
if $self->assume_yes 0 0 0
118  
119 # ask and set 'prepare_env' (so uninstall_env can use it) ...
120 0 ▶ if (-t STDIN) {
Branch: 1 branch
BranchTrueFalseTotal
if (-t STDIN) { } 0 0 0
121 0 while (1) {
122 0 my $key = '';
123 0 print "\nPackage installation required. Proceed? (y/N) ";
124 0 my $line = <STDIN>;
125 0 $key = substr( $line, 0, 1 );
126 0 ▶ if (lc($key) eq 'y') {
Branch: 2 branches
BranchTrueFalseTotal
if (lc $key eq 'y') { } 0 0 0
elsif (lc $key eq 'n' or $key eq "\n") { } 0 0 0
127 0 $self->prepare_env( 1 );
128 0 return 1;
129 }
130 ▶ elsif (lc($key) eq 'n'
Condition0%0/3
lc $key eq "n" or $key eq "\n"
l!l&&r!l&&!r
000
MC/DC0%0/2
lc $key eq "n" or $key eq "\n"
lc $key eq "n" $key eq "\n"
Truth table0%0/3
A or B
A= lc $key eq "n"B= $key eq "\n"
ABresult
1X1
011
000
131 or $key eq "\n") {
132 0 $self->prepare_env( 0 );
133 0 return 0;
134 }
135 else {
136 0 say "\nInvalid input";
137 }
138 }
139 }
140 else {
141 0 $log->info( "Input is not a TTY; assuming answer 'no' to package installation permission" );
142 0 $self->prepare_env( 0 );
143 0 return 0;
144 }
145 }
146  
147 0 ▶sub effective_uninstall_env( $self ) {
Subroutine effective_uninstall_env: not called CC=2 SCAR=17.9
Pod undocumented
148 0 ▶ if (defined $self->uninstall_env) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->uninstall_env) 0 0 0
149 0 return $self->uninstall_env;
150 }
151  
152 0 return $self->effective_prepare_env;
153 }
154  
155 0 ▶sub effective_version( $self ) {
Subroutine effective_version: not called CC=6 SCAR=37.4
Pod undocumented
156 0 ▶ return $self->version if defined $self->version;
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->version 0 0 0
157 0 $log->debug( "Resolving 'latest' version to actual version number" );
158  
159 0 my $r = $http->get( 'https://api.github.com/repos/ledgersmb/LedgerSMB/releases/latest' );
160 0 ▶ if ($r->{success}) {
Branch: 2 branches
BranchTrueFalseTotal
if ($r->{'success'}) { } 0 0 0
elsif ($r->{'status'} == 599) { } 0 0 0
161 0 my $content = JSON::PP->new->utf8->decode( $r->{content} );
162  
163 0 ▶ if (defined $content
Branch: 1 branch
BranchTrueFalseTotal
if (defined $content and defined $content->{'tag_name'}) { } 0 0 0
Condition0%0/3
defined $content and defined $content->{"tag_name"}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $content and defined $content->{"tag_name"}
defined $content defined $content->{"tag_name"}
Truth table0%0/3
A and B
A= defined $contentB= defined $content->{"tag_name"}
ABresult
0X0
100
111
164 and defined $content->{tag_name}) {
165 0 $self->version( $content->{tag_name} );
166 0 $log->info( "Resolved 'latest' version to $content->{tag_name} for installation" );
167  
168 0 return $content->{tag_name};
169 }
170 else {
171 0 die $log->fatal( "Information for 'latest' release does not include tag_name" );
172 }
173 # unreachable
174 }
175 elsif ($r->{status} == 599) {
176 die $log->fatal(
177 'Error trying to retrieve precomputed dependencies: ' . $r->{content}
178 0 );
179 }
180 # unreachable
181 }
182  
183 2 ▶sub option_callbacks($self, $options) {
Subroutine option_callbacks: called CC=1 SCAR=0.0
Pod undocumented
184 my %opts = (
185 2 ▶ 'yes|y!' => sub { $self->assume_yes( $_[1] ) },
Subroutine __ANON__: called CC=1 SCAR=0.0
186 2 ▶ 'system-packages!' => sub { $self->sys_pkgs( $_[1] ) },
Subroutine __ANON__: called CC=1 SCAR=0.0
187 2 ▶ 'prepare-env!' => sub { $self->prepare_env( $_[1] ) },
Subroutine __ANON__: called CC=1 SCAR=0.0
188 1 ▶ 'target=s' => sub { $self->installpath( $_[1] ) },
Subroutine __ANON__: called CC=1 SCAR=0.0
189 1 ▶ 'local-lib=s' => sub { $self->locallib( $_[1] ) },
Subroutine __ANON__: called CC=1 SCAR=0.0
190 1 ▶ 'log-level=s' => sub { $self->loglevel( $_[1] ) },
Subroutine __ANON__: called CC=1 SCAR=0.0
191 2 ▶ 'verify-sig!' => sub { $self->verify_sig( $_[1] ) },
Subroutine __ANON__: called CC=1 SCAR=0.0
192 2 );
193  
194 2 return %opts{$options->@*};
195 }
196  
197 2 for my $acc (qw( assume_yes installpath locallib loglevel
198 compute_deps prepare_env sys_pkgs
199 verify_sig uninstall_env version cpanfile cpanfile_path )) {
200 24 my $ref = qualify_to_ref $acc;
201 32 ▶ *{$ref} = sub($self, $arg = undef) {
Subroutine __ANON__: called CC=3 SCAR=11.0
202 32 ▶ $self->{"_$acc"} = $arg
Branch: 1 branch
BranchTrueFalseTotal
if defined $arg 14 18 32
203 if defined $arg;
204 32 return $self->{"_$acc"};
205 24 };
206 }
207  
208 2 1;
« Installer/OS/linux/debian.pm ↑ Summary Installer/OS/linux/fedora.pm »