Installer.pm

filter: Statementstmt 14.7% 62 / 421 Branchbran 0.0% 0 / 170 Conditioncond 0.0% 0 / 41 MC/DCmcdc 0.0% 0 / 24 Subroutinesub 44.1% 19 / 43 Podpod 0.0% 0 / 6 totaltotal 11.4% 81 / 705 CC 111 SCAR 66.1
CC
111
Cov
10%
install
2256.0
_compute_all_deps
210.0
compute
156.0
CRAP 739.3
↑ Summary Installer/OS.pm »
1 package LedgerSMB::Installer v0.999.15;
2  
3 1 ▶use v5.20;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use experimental qw(signatures);
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 1 ▶use Carp qw( croak );
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use CPAN::Meta::Requirements;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use English;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use File::Path qw( make_path remove_tree );
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use File::Spec;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use File::Temp qw( tempfile );
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 ▶use Getopt::Long qw(GetOptionsFromArray);
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 ▶use HTTP::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 1 ▶use IO::Handle;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 1 ▶use JSON::PP;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 1 ▶use List::Util qw(uniq);
Subroutine BEGIN: called CC=1 SCAR=0.0
17 1 ▶use Module::CoreList;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 1 ▶use version;
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20 1 ▶use Log::Any qw($log);
Subroutine BEGIN: called CC=1 SCAR=0.0
21 1 ▶use Log::Any::Adapter;
Subroutine BEGIN: called CC=1 SCAR=0.0
22 1 ▶use Module::CPANfile;
Subroutine BEGIN: called CC=1 SCAR=0.0
23  
24 1 ▶use LedgerSMB::Installer::Configuration;
Subroutine BEGIN: called CC=1 SCAR=0.0
25  
26 1 my $INSTALLER_VERSION = 'version CLONED'; # not intended to be the module version
27  
28 1 my $http = HTTP::Tiny->new( agent => 'LedgerSMB-Installer/0.1' );
29 1 my $json = JSON::PP->new->canonical;
30  
31 0 ▶sub _post_boot_configure($class, $dss, $config) {
Subroutine _post_boot_configure: not called CC=1 SCAR=6.9
32 0 Log::Any::Adapter->set('Stdout', log_level => $config->loglevel);
33 }
34  
35 0 ▶sub _boot($class, $args, $options) {
Subroutine _boot: not called CC=1 SCAR=6.9
36 0 my $dss = $class->_load_dist_support;
37 0 my $config = LedgerSMB::Installer::Configuration->new(
38 sys_pkgs => ($EFFECTIVE_USER_ID == 0)
39 );
40  
41 0 GetOptionsFromArray(
42 $args,
43 $config->option_callbacks( $options ),
44 );
45  
46 # normalize $installpath (at least cpanm needs that)
47 # assume $locallib to be inside $installpath
48 0 $config->normalize_paths;
49  
50 0 $class->_post_boot_configure( $dss, $config );
51 0 return ($dss, $config);
52 }
53  
54 1 my $signing_key_data = <<'KEY_DATA_END';
55 -----BEGIN PGP PUBLIC KEY BLOCK-----
56 Comment: Hostname: fr.pgpkeys.eu
57 Version: Hockeypuck 2.2.4
58  
59 xsBNBEYTN1ABCACuVLUCasiD4KnetfEHtMo+qDjKbcWauIkw/KU+gj8kN7Y+E3ye
60 cLxtY1gJlZp0iIgnZ6aw7bPCleTXbBfXXbMyLs0+CN9cfCyXB5TU4nlh16or/vlE
61 C+0WjEuD9Qznm805RXJGvIRPobXrxcO7aB7pT3NkKj2z//9D0w0uC+BDEl0uihZG
62 +fIbb2ihPWO/r9ghHhyMRTibSRye09owhVpr/5gYRFtvp7OsYHaLhUD3+WXPhGIZ
63 U7YqBFRumDNR+S8EewuKj0CBxCtC+iSFyR/fNPh50FbtgqY/9qLmZa/u42oyjrCl
64 TM+ALCM+PutEPVEIyVoO4jluoZ8yG4IFVxyxABEBAAHNZUxlZGdlclNNQiBDb3Jl
65 IFRlYW0gKFRoaXMgaXMgdGhlIGtleSB1c2VkIGZvciBwYWNrYWdlIHNpZ25pbmcu
66 KSA8bGVkZ2VyLXNtYi1jb3JlQGxpc3RzLmxlZGdlcnNtYi5vcmc+wsB2BBMBAgAg
67 BQJGEzdQAhsDBgsJCAcDAgQVAggDBBYCAwECHgECF4AACgkQOaYpVY2grxAaDwgA
68 kp2LZNyrZDom1tBwR3aisfYFkkiuFrUZUn+fYwr7wnkq06gpYGZrNgdcanSxjGoD
69 wf2kMeCwWAD6sao824onboJWRi1LR3Q5RKIAvYBeLZ75/hYSy3JP/YLMl047IWcU
70 CMaqZfmXPHvkOdUblPxCaKJM8c9Sb6KxGzu4BU2Y97TvQjn9xNbq4t7Pgpu5RORH
71 Hp96V+kZXGxzQo0gCE+6dr1JFZeTKmTkGSvkchndn5UVLguLIg9kCxxcDiS7hmTx
72 yB+b0+kPgRUb0YVp6QqFq7O8fvzhsW8sYopBJsbArODS2qeMiwPUnKs+7qkZg8Jd
73 j2QoHZCY06NU6yvqq/CIt8JGBBARAgAGBQJIx9P/AAoJEHc352JrCredRJwAnRFe
74 UDqpUCw368z/Ht6FDInXnC2kAJ995NXymKbQVg478EdOrJT8h1SPRA==
75 =a/2y
76 -----END PGP PUBLIC KEY BLOCK-----
77 KEY_DATA_END
78  
79 0 ▶sub _build_install_tree($class, $dss, $config, $installpath, $version) {
Subroutine _build_install_tree: not called CC=3 SCAR=24.8
80 0 my $archive = "ledgersmb-$version.tar.gz";
81  
82 0 ▶ if (not -d $installpath ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-d $installpath) 0 0 0
83 0 $log->info( "Creating installation path $installpath" );
84 0 make_path( $installpath ); # croaks on fatal errors
85 }
86  
87 0 $log->info( "Downloading release tarball $archive" );
88 0 $class->_download( $installpath, $version );
89  
90 0 $log->info( "Verifying tarball against gpg public key & signature" );
91 0 my $downloaded_tar = File::Spec->catfile( $installpath, $archive );
92 0 ▶ $dss->verify_sig( $installpath,
Branch: 1 branch
BranchTrueFalseTotal
if $config->verify_sig 0 0 0
93 $downloaded_tar,
94 "$downloaded_tar.asc",
95 $signing_key_data )
96 if $config->verify_sig;
97  
98 0 $log->info( "Extracting release tarball" );
99 0 $dss->untar( $downloaded_tar,
100 $installpath,
101 no_same_owner => 1,
102 strip_components => 1 );
103 0 $config->cpanfile_path( File::Spec->catfile( $installpath, 'cpanfile' ) );
104  
105 0 $log->info( "Removing extracted release tarball" );
106 # croaks on fatal errors:
107 0 remove_tree( $downloaded_tar, "$downloaded_tar.asc" );
108 }
109  
110 0 ▶sub _get_cpanfile($class, $config) {
Subroutine _get_cpanfile: not called CC=4 SCAR=30.0
111 0 ▶ return $config->cpanfile if $config->cpanfile;
Branch: 1 branch
BranchTrueFalseTotal
if $config->cpanfile 0 0 0
112  
113 0 my $cpanfile;
114 0 ▶ if ($config->cpanfile_path) {
Branch: 1 branch
BranchTrueFalseTotal
if ($config->cpanfile_path) { } 0 0 0
115 0 $cpanfile = $config->cpanfile_path;
116 }
117 else {
118 0 my $url =
119 sprintf("https://raw.githubusercontent.com/ledgersmb/LedgerSMB/refs/tags/%s/cpanfile",
120 $config->effective_version);
121  
122 0 my $response = $http->get( $url );
123 0 ▶ unless ($response->{success}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($response->{"success"}) 0 0 0
124 0 die $log->fatal("Unable to get '$url' from GitHub: $response->{content}");
125 }
126  
127 0 my ($fh, $fn) = tempfile();
128 0 print $fh $response->{content};
129 0 $fh->flush;
130 0 $cpanfile = $fn;
131 }
132  
133 0 my $decl = Module::CPANfile->load( $cpanfile );
134 0 $config->cpanfile( $decl );
135  
136 0 return $decl;
137 }
138  
139 0 ▶sub _get_immediate_prereqs($class, $config) {
Subroutine _get_immediate_prereqs: not called CC=1 SCAR=6.9
140 0 my $decl = $class->_get_cpanfile( $config );
141 0 return $decl->prereqs;
142 }
143  
144 0 ▶sub _compute_immediate_deps($class, $config) {
Subroutine _compute_immediate_deps: not called CC=4 SCAR=30.0
145 0 my @types = qw( requires recommends );
146 0 my @phases = qw( runtime );
147 0 my $decl = $class->_get_cpanfile( $config );
148 0 my $prereqs = $decl->prereqs_with( map { $_->identifier } $decl->features ); # all features
149 0 my $effective = CPAN::Meta::Requirements->new;
150 0 for my $phase (@phases) {
151 0 for my $type (@types) {
152 0 $effective->add_requirements( $prereqs->requirements_for( $phase, $type ) );
153 }
154 }
155  
156 0 my @mods = sort { lc($a) cmp lc($b) } $effective->required_modules;
157  
158 0 $log->debug( "Direct dependency count: " . scalar(@mods) );
159 0 $log->trace( "- $_" ) for (sort @mods);
160 0 return sort @mods;
161 }
162  
163 0 ▶sub _compute_all_deps($class, $config) {
Subroutine _compute_all_deps: not called CC=14 SCAR=53.5
164 0 my @deps = $class->_compute_immediate_deps( $config );
165  
166 0 my @orig_deps = (@deps, );
167 0 my @last_deps = @deps;
168 0 my %dists;
169 0 my $iteration = 1;
170 0 ▶ do {
Branch: 1 branch
BranchTrueFalseTotal
@last_deps and do { do { my $query = {"_source", [("release", "distribution", "status", "provides"), "dependency.*"], "query", {"bool", {"must", [{"term", {"status", "latest"}}, {"terms", {"provides", [@last_deps]}}]}}}; my $body = $json->encode($query); my $r = $http->request("POST", "https://fastapi.metacpan.org/v1/release/_search?size=1000", {"headers", {"Content-Type", "application/json"}, "content", $body}); unless ($r->{"success"}) { die qq[Unable to request module dependencies; POST request failed for https://fastapi.metacpan.org/v1/release/_search, response: $r->{"status"} - $r->{"reason"}]; } ; my $hits = $json->decode($r->{"content"})->{"hits"}; if (@{$hits->{"hits"}} > 500) { my $hit_count = scalar @{$hits->{"hits"}}; warn "Unexpectedly high number of dependencies reported: $hit_count\nRequest body: $body\n"; } ; foreach my $release (@{$$hits{"hits"}}) { $dists{$release->{"_source"}{"distribution"}} = 1; } ; my %provide; foreach my $release (@{$$hits{"hits"}}) { foreach my $provided (@{$$release{"_source"}{"provides"}}) { $provide{$provided} = 1; } ; } ; my %rdeps; foreach my $release (@{$$hits{"hits"}}) { foreach my $dep (@{$$release{"_source"}{"dependency"}}) { next unless $dep->{"relationship"} eq "requires"; next unless $dep->{"phase"} eq "runtime"; $rdeps{$dep->{"module"}} = 1; } ; } ; delete $rdeps{"perl"}; @last_deps = sort(grep({my $m = $_; my $c = "Module::CoreList"->is_core($m); not $provide{$m} || $c;} keys %rdeps)); push @deps, @last_deps; $LedgerSMB::Installer::log->trace("Dependency resolution iteration $iteration - " . 'remaining to resolve: ' . scalar(@last_deps)); ++$iteration } } 0 0 0
171 0 my $query = {
172 _source => [ qw( release distribution status provides ), 'dependency.*' ],
173 query => {
174 bool => {
175 must => [
176 { term => { status => 'latest' } },
177 { terms => { provides => [ @last_deps ] } }
178 ],
179 }
180 }
181 };
182  
183 0 my $body = $json->encode( $query );
184 0 my $r = $http->request( 'POST', 'https://fastapi.metacpan.org/v1/release/_search?size=1000',
185 { headers => { 'Content-Type' => 'application/json' },
186 content => $body });
187 0 ▶ unless ($r->{success}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($r->{"success"}) 0 0 0
188 0 die "Unable to request module dependencies; POST request failed for https://fastapi.metacpan.org/v1/release/_search, response: $r->{status} - $r->{reason}";
189 }
190 0 my $hits = $json->decode($r->{content})->{hits};
191 0 ▶ if ($hits->{hits}->@* > 500) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$hits->{"hits"}} > 500) 0 0 0
192 0 my $hit_count = scalar $hits->{hits}->@*;
193 0 warn "Unexpectedly high number of dependencies reported: $hit_count\nRequest body: $body\n";
194 }
195  
196 0 for my $release ($hits->{hits}->@*) {
197 0 $dists{$release->{_source}->{distribution}} = 1;
198 }
199  
200 0 my %provide;
201 0 for my $release ($hits->{hits}->@*) {
202 0 for my $provided ($release->{_source}->{provides}->@*) {
203 0 $provide{$provided} = 1;
204 }
205 }
206  
207 0 my %rdeps;
208 0 for my $release ($hits->{hits}->@*) {
209 0 for my $dep ($release->{_source}->{dependency}->@*) {
210 0 ▶ next unless $dep->{relationship} eq 'requires';
Branch: 1 branch
BranchTrueFalseTotal
unless $dep->{"relationship"} eq "requires" 0 0 0
211 0 ▶ next unless $dep->{phase} eq 'runtime';
Branch: 1 branch
BranchTrueFalseTotal
unless $dep->{"phase"} eq "runtime" 0 0 0
212 0 $rdeps{$dep->{module}} = 1;
213 }
214 }
215  
216 0 delete $rdeps{perl};
217 @last_deps = sort grep {
218 0 my $m = $_;
219 0 my $c = Module::CoreList->is_core($m);
220  
221 0 ▶ not ($provide{$m} or $c);
Condition0%0/3
$provide{$m} || $c
l!l&&r!l&&!r
000
MC/DC0%0/2
$provide{$m} || $c
$provide{$m} $c
Truth table0%0/3
A || B
A= $provide{$m}B= $c
ABresult
1X1
011
000
222 } keys %rdeps;
223 0 push @deps, @last_deps;
224  
225 0 $log->trace( "Dependency resolution iteration $iteration - "
226 . "remaining to resolve: " . scalar(@last_deps) );
227 0 $iteration++;
228 } while (@last_deps);
229  
230 0 my @missed = do {
231 0 my %deps = map { $_ => 1 } @deps;
232 0 grep { !$deps{$_} } @orig_deps;
233 };
234 0 ▶ $log->error( "Unable to resolve dependencies for modules: "
Branch: 1 branch
BranchTrueFalseTotal
if @missed 0 0 0
235 . join(', ', @missed) )
236 if (@missed);
237 0 @deps = sort uniq (@deps, @missed);
238 0 $log->debug( "Dependency tree size: " . scalar(@deps) );
239 0 $log->trace( "- $_" ) for (@deps);
240 0 return @deps;
241 }
242  
243 0 ▶sub _compute_dep_pkgs($class, $dss, $config ) {
Subroutine _compute_dep_pkgs: not called CC=1 SCAR=6.9
244 0 my @mods = $class->_compute_all_deps( $config );
245  
246 # the array passed in gets modified; copy @mods so we still have it below
247 0 my ($pkgs, $unmapped) = $dss->pkgs_from_modules( [ @mods ] );
248  
249 0 my $c = scalar(@mods);
250 0 my $p = scalar(keys $pkgs->%*);
251 0 my $u = scalar($unmapped->@*);
252 0 $log->debug( "Resolved $c modules to $p packages; $u unmapped" );
253 0 return ([ sort keys $pkgs->%* ], $unmapped);
254 }
255  
256 0 ▶sub _download($class, $installpath, $version) {
Subroutine _download: not called CC=9 SCAR=45.0
257 0 my $fn = "ledgersmb-$version.tar.gz";
258 my $url =
259 $ENV{ARTIFACT_LOCATION} // (
260 0 ▶ ($version =~ m/\d+\.\d+\.\d+\-/)
Branch: 1 branch
BranchTrueFalseTotal
$version =~ /\d+\.\d+\.\d+\-/u ? : 0 0 0
Condition0%0/2
$ENV{"ARTIFACT_LOCATION"} // ($version =~ /\d+\.\d+\.\d+\-/u ? "https://download.ledgersmb.org/f/Beta%20Releases/$version/" : "https://download.ledgersmb.org/f/Releases/$version/")
l!l
00
MC/DC0%0/1
$ENV{"ARTIFACT_LOCATION"} // ($version =~ /\d+\.\d+\.\d+\-/u ? "https://download.ledgersmb.org/f/Beta%20Releases/$version/" : "https://download.ledgersmb.org/f/Releases/$version/")
$ENV{"ARTIFACT_LOCATION"}
Truth table0%0/2
A
A= $ENV{"ARTIFACT_LOCATION"}
Aresult
11
00
261 ? "https://download.ledgersmb.org/f/Beta%20Releases/$version/"
262 : "https://download.ledgersmb.org/f/Releases/$version/"
263 );
264 0 my $http = HTTP::Tiny->new;
265  
266 0 do {
267 0 ▶ open( my $fh, '>', File::Spec->catfile($installpath, $fn))
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, ">", "File::Spec"->catfile($installpath, $fn) or croak($LedgerSMB::Installer::log->fatal("Unable to open output file ${fn}: $!")) 0 0 0
268 or croak $log->fatal( "Unable to open output file $fn: $!" );
269 0 binmode $fh, ':raw';
270 my $r = $http->get(
271 "$url$fn",
272 {
273 0 ▶ data_callback => sub($data, $status) {
Subroutine __ANON__: not called CC=1 SCAR=6.9
274 0 print $fh $data;
275 }
276 0 });
277  
278 0 ▶ if ($r->{status} == 599) {
Branch: 2 branches
BranchTrueFalseTotal
if ($r->{'status'} == 599) { } 0 0 0
elsif (not $r->{'success'}) { } 0 0 0
279 0 croak $log->fatal( "Unable to request $url$fn: " . $r->{content} );
280 }
281 elsif (not $r->{success}) {
282 0 croak $log->fatal( "Unable to request $url$fn: $r->{status} - $r->{reason}" );
283 }
284 };
285  
286 0 do {
287 0 my $r = $http->get( "$url$fn.asc" );
288 0 ▶ if ($r->{status} == 599) {
Branch: 2 branches
BranchTrueFalseTotal
if ($r->{'status'} == 599) { } 0 0 0
elsif (not $r->{'success'}) { } 0 0 0
289 0 croak $log->fatal( "Unable to request $url/$fn: " . $r->{content} );
290 }
291 elsif (not $r->{success}) {
292 0 croak $log->fatal( "Unable to request $url/$fn: $r->{status} - $r->{reason}" );
293 }
294 else {
295 0 ▶ open( my $fh, '>', File::Spec->catfile($installpath, "$fn.asc"))
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, ">", "File::Spec"->catfile($installpath, "$fn.asc") or croak($LedgerSMB::Installer::log->fatal("Unable to open output file $fn.asc: $!")) 0 0 0
296 or croak $log->fatal( "Unable to open output file $fn.asc: $!" );
297 0 binmode $fh, ':raw';
298 0 print $fh $r->{content};
299 }
300 };
301 }
302  
303 0 ▶sub _find_executable($class, $dss, $executable, $dirs) {
Subroutine _find_executable: not called CC=6 SCAR=37.4
304 0 ▶ while (my $dir = shift $dirs->@*) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $dir = shift @$dirs) 0 0 0
305 0 my $exe = File::Spec->catfile( $dir, $dss->executable_name( $executable ) );
306 0 ▶ $log->trace( "Found $executable: $exe; but not executable" )
Branch: 1 branch
BranchTrueFalseTotal
if -e $exe and not -x $exe 0 0 0
Condition0%0/3
-e $exe and not -x $exe
!ll&&!rl&&r
000
MC/DC0%0/2
-e $exe and not -x $exe
-e $exe not -x $exe
Truth table0%0/3
A and not(B)
A= -e $exeB= not -x $exe
ABresult
0X0
100
111
307 if -e $exe and not -x $exe;
308 0 ▶ my $rv = -x $exe ? $exe : '';
Branch: 1 branch
BranchTrueFalseTotal
-x $exe ? : 0 0 0
309  
310 0 ▶ if ($rv) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rv) 0 0 0
311 0 $log->debug( "Searching for $executable; found $exe" );
312 0 return $rv;
313 }
314 }
315 0 return undef;
316 }
317  
318 # This function is borrowed from App::Info::RDBMS::PostgreSQL v0.57
319 # because that is what DBD::Pg uses to identify where pg_config lives
320 0 ▶sub _search_bin_dirs($class) {
Subroutine _search_bin_dirs: not called CC=3 SCAR=24.8
321 return (( exists $ENV{POSTGRES_HOME}
322 ? (File::Spec->catdir($ENV{POSTGRES_HOME}, "bin"))
323 : ()
324 ),
325 ( exists $ENV{POSTGRES_LIB}
326 0 ▶ ? (File::Spec->catdir($ENV{POSTGRES_LIB}, File::Spec->updir, "bin"))
Branch: 2 branches
BranchTrueFalseTotal
exists $ENV{'POSTGRES_HOME'} ? : 0 0 0
exists $ENV{'POSTGRES_LIB'} ? : 0 0 0
327 : ()
328 ),
329 File::Spec->path,
330 qw(/usr/local/pgsql/bin
331 /usr/local/postgres/bin
332 /usr/lib/postgresql/bin
333 /opt/pgsql/bin
334 /usr/local/bin
335 /usr/local/sbin
336 /usr/bin
337 /usr/sbin
338 /bin),
339 'C:\Program Files\PostgreSQL\bin');
340 }
341 # end of borrowed code
342  
343 0 ▶sub _find_pg_config($class, $dss, $config) {
Subroutine _find_pg_config: not called CC=1 SCAR=6.9
344 0 my @dirs = $class->_search_bin_dirs;
345  
346 # TODO: Check for pg_config in $config
347  
348 0 return $class->_find_executable( $dss, 'pg_config', \@dirs );
349 }
350  
351 0 ▶sub _find_xml2_config($class, $dss, $config) {
Subroutine _find_xml2_config: not called CC=1 SCAR=6.9
352 0 return $class->_find_executable( $dss, 'xml2-config', [ File::Spec->path ] );
353 }
354  
355 0 ▶sub _find_latex($class, $dss, $config) {
Subroutine _find_latex: not called CC=1 SCAR=6.9
356 0 return $class->_find_executable( $dss, 'latex', [ File::Spec->path ] );
357 }
358  
359  
360 # mapping taken from File::Spec
361 1 my %module = (
362 MSWin32 => 'win32',
363 os2 => 'os2',
364 VMS => 'vms',
365 NetWare => 'win32',
366 symbian => 'win32',
367 dos => 'os2',
368 cygwin => 'cygwin',
369 amigaos => 'amigaos',
370 linux => 'linux' # not mapped in File::Spec
371 );
372  
373 0 ▶sub _get_os($class) {
Subroutine _get_os: not called CC=2 SCAR=17.9
374 0 ▶ return $module{$^O} || 'unix';
Condition0%0/2
$module{$^O} || 'unix'
l!l
00
MC/DC0%0/1
$module{$^O} || 'unix'
$module{$^O}
Truth table0%0/2
A
A= $module{$^O}
Aresult
11
00
375 }
376  
377 0 ▶sub _load_dist_support($class) {
Subroutine _load_dist_support: not called CC=2 SCAR=17.9
378 0 my $OS = $class->_get_os;
379  
380 0 $log->info( "Detected O/S: $OS" );
381 0 my $oss_class = "LedgerSMB::Installer::OS::$OS";
382  
383 0 local $@ = undef;
384 0 ▶ unless (eval "require $oss_class") {
Branch: 1 branch
BranchTrueFalseTotal
unless (eval "require $oss_class") 0 0 0
385 0 say "Unable to load $oss_class: $@";
386 0 say "No support for $OS";
387 0 exit 2;
388 }
389  
390 0 my $oss = $oss_class->new; # operating system support instance
391 0 $log->debug( "Detecting distribution" );
392 0 return $oss->detect_dss; # detect and return distribution support instance
393 }
394  
395 0 ▶sub compute($class, @args) {
Subroutine compute: not called CC=12 SCAR=50.5
Pod undocumented
396 0 my ($dss, $config) = $class->_boot(
397 \@args,
398 [ 'yes|y!', 'target=s', 'local-lib=s', 'log-level=s' ]
399 );
400  
401 0 ▶ if (@args != 2) {
Branch: 1 branch
BranchTrueFalseTotal
if (@args != 2) 0 0 0
402 0 die "Incorrect number of arguments";
403 }
404  
405 0 my $version = shift @args;
406 0 $config->compute_deps( 1 );
407 0 ▶ $config->version( $version ) if defined $version;
Branch: 1 branch
BranchTrueFalseTotal
if defined $version 0 0 0
408  
409 0 my $deps_outfile = $args[0];
410 0 ▶ open( my $out, '>:raw', $deps_outfile )
Branch: 1 branch
BranchTrueFalseTotal
open my $out, ">:raw", $deps_outfile or die "Unable to open output file '${deps_outfile}': $!" 0 0 0
411 or die "Unable to open output file '$deps_outfile': $!";
412  
413  
414 0 ▶ unless ($dss->am_system_perl) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($dss->am_system_perl) 0 0 0
415 0 ▶ close( $out ) or warn $log->warn( "Unable to close output file" );
Branch: 1 branch
BranchTrueFalseTotal
close $out or warn $LedgerSMB::Installer::log->warn("Unable to close output file") 0 0 0
416 0 unlink $deps_outfile;
417 0 die $log->fatal( "Not running the system perl; not able to re-use system packages" );
418 }
419  
420 ###TODO: _get_immediate_prereqs may throw
421 0 my $prereqs = $class->_get_immediate_prereqs( $config );
422 0 my $requirements = $prereqs->merged_requirements();
423 0 ▶ unless ($requirements->accepts_module( 'perl', $])) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($requirements->accepts_module("perl", $])) 0 0 0
424 0 ▶ close( $out ) or warn $log->warn( "Unable to close output file" );
Branch: 1 branch
BranchTrueFalseTotal
close $out or warn $LedgerSMB::Installer::log->warn("Unable to close output file") 0 0 0
425 0 unlink $deps_outfile;
426 0 my $perl_version = version->parse( $] )->normal;
427 0 die $log->fatal( "Perl version ($perl_version) not compliant with LedgerSMB " . $config->effective_version
428 . "; requires: " . $requirements->requirements_for_module( 'perl' ));
429 }
430  
431 ###TODO: prepare_pkg_resolver_env may throw
432 0 ▶ if ($config->effective_prepare_env) {
Branch: 1 branch
BranchTrueFalseTotal
if ($config->effective_prepare_env) 0 0 0
433 0 $dss->prepare_pkg_resolver_env( $config );
434 }
435 0 my $exception;
436 0 do {
437 0 local $@ = undef;
438 0 my $failed = not eval {
439 0 $log->info( "Computing O/S packages for declared dependencies" );
440 0 my ($deps, $mods) = $class->_compute_dep_pkgs( $dss, $config );
441  
442 0 say $out $json->encode( { identifier => $dss->dependency_packages_identifier,
443 packages => $deps,
444 modules => $mods,
445 name => $dss->name,
446 'schema-version' => "1" } );
447  
448 0 return 1;
449 };
450 0 ▶ $exception = $@ if $failed;
Branch: 1 branch
BranchTrueFalseTotal
if $failed 0 0 0
451  
452 0 $log->info( "Dependencies written to $deps_outfile" );
453 0 ▶ if ($config->effective_uninstall_env) {
Branch: 1 branch
BranchTrueFalseTotal
if ($config->effective_uninstall_env) 0 0 0
454 0 $log->warning( "Cleaning up Perl module installation dependencies" );
455 0 $dss->cleanup_env($config);
456 }
457 };
458 0 ▶ die $exception if defined $exception;
Branch: 1 branch
BranchTrueFalseTotal
if defined $exception 0 0 0
459  
460 0 return 0;
461 }
462  
463 sub download($class, @args) {
464 }
465  
466 0 ▶sub help($class, @args) {
Subroutine help: not called CC=1 SCAR=6.9
Pod undocumented
467 0 my $help_text = do {
468 0 local $/ = undef;
469 0 <DATA>;
470 };
471 0 $help_text =~ s/\bSCRIPT\b/$0/g;
472 0 say $help_text;
473  
474 0 return 0;
475 }
476  
477 0 ▶sub _module_will_install($class, $mod, $pkgs, $unmapped) {
Subroutine _module_will_install: not called CC=4 SCAR=30.0
478 # no packages will be installed:
479 0 ▶ return 0 if ((not $pkgs) or (not $pkgs->@*));
Branch: 1 branch
BranchTrueFalseTotal
unless $pkgs and @$pkgs 0 0 0
Condition0%0/3
$pkgs and @$pkgs
!ll&&!rl&&r
000
MC/DC0%0/2
$pkgs and @$pkgs
$pkgs @$pkgs
Truth table0%0/3
A and B
A= $pkgsB= @$pkgs
ABresult
0X0
100
111
480  
481 # package in the list of those not installed through a package:
482 0 ▶ return 0 if (grep { $mod eq $_ } $unmapped->@*);
Branch: 1 branch
BranchTrueFalseTotal
if grep {$mod eq $_;} @$unmapped 0 0 0
483  
484 # package must be in one of the packages being installed
485 0 return 1;
486 }
487  
488 0 ▶sub available($class, @args) {
Subroutine available: not called CC=6 SCAR=37.4
Pod undocumented
489 0 my $r = $http->get( 'https://download.ledgersmb.org/f/Releases/' );
490 0 ▶ unless ($r->{success}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($r->{"success"}) 0 0 0
491 0 die $log->error( "Failed to retrieve download list; $r->{code} - $r->{reason}" );
492 }
493  
494 0 my @versions;
495 0 ▶ while ($r->{content} =~ s{<tr\s+class="(?:odd|even)"\s*>(.*?)</tr\s*>}{}m) {
Branch: 1 branch
BranchTrueFalseTotal
if ($r->{"content"} =~ s[<tr\s+class="(?:odd|even)"\s*>(.*?)</tr\s*>][]mu) 0 0 0
496 0 my $row = $1;
497 0 ▶ if ($row =~ m{">(\d+\.\d+\.\d+)/</a>}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($row =~ m[">(\d+\.\d+\.\d+)/</a>]u) 0 0 0
498 0 my $version = $1;
499 0 $version =~ m{(\d+\.\d+)\.};
500 0 my $minor = $1;
501 0 push @versions, {
502 version => version->parse($version),
503 minor => $minor
504 };
505 }
506 }
507  
508 0 my $last_minor = '';
509 0 for my $v (sort { $b->{version} <=> $a->{version} } @versions) {
510 0 ▶ next if $last_minor eq $v->{minor};
Branch: 1 branch
BranchTrueFalseTotal
if $last_minor eq $v->{"minor"} 0 0 0
511  
512 0 say ' ' . $v->{version}->stringify;
513 0 $last_minor = $v->{minor};
514 }
515 }
516  
517 0 ▶sub install($class, @args) {
Subroutine install: not called CC=47 SCAR=77.2
Pod undocumented
518 0 my $rv = 1;
519 0 my ($dss, $config) = $class->_boot(
520 \@args,
521 [ 'yes|y!', 'system-packages!', 'prepare-env!', 'target=s',
522 'local-lib=s', 'log-level=s', 'verify-sig!' ]
523 );
524 0 my $version = shift @args;
525 0 ▶ $config->version( $version ) if defined $version;
Branch: 1 branch
BranchTrueFalseTotal
if defined $version 0 0 0
526  
527 0 my ($pkg_deps, $unmapped_mods);
528 0 my @extra_pkgs;
529 0 ▶ if ($dss->am_system_perl) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dss->am_system_perl) 0 0 0
530 0 my $name = $dss->name;
531 0 my $dep_pkg_id = $dss->dependency_packages_identifier;
532 0 ▶ if ($config->sys_pkgs) {
Branch: 1 branch
BranchTrueFalseTotal
if ($config->sys_pkgs) 0 0 0
533 0 ($pkg_deps, $unmapped_mods) = $config->retrieve_precomputed_deps($name, $dep_pkg_id);
534 }
535 0 ▶ if ($pkg_deps) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pkg_deps) { } 0 0 0
536 0 ▶ if ($dss->pkg_can_install()) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dss->pkg_can_install) { } 0 0 0
537 0 ▶ if ($config->effective_prepare_env) {
Branch: 1 branch
BranchTrueFalseTotal
if ($config->effective_prepare_env) 0 0 0
538 0 $dss->prepare_builder_env( $config );
539 }
540 0 goto INSTALL_SYS_PKGS;
541 }
542 else {
543 0 $log->warn( "Unable to install system packages; will resort to installation of CPAN modules" );
544 0 $pkg_deps = undef;
545 }
546 }
547 else {
548 0 $log->warn( "No precomputed dependencies available for $name/$dep_pkg_id" );
549 0 $log->info( "Configuring environment for dependency computation" );
550 }
551 }
552  
553 ########################################################################################
554 #
555 # Need to clean up on failure after this point! We have changed system state!
556 #
557 ########################################################################################
558 0 $dss->prepare_extraction_env( $config );
559 0 $class->_build_install_tree( $dss, $config, $config->installpath, $config->effective_version );
560 0 my $prereqs = $class->_get_immediate_prereqs( $config );
561 0 my $requirements = $prereqs->merged_requirements();
562  
563 0 ▶ unless ($requirements->accepts_module( 'perl', $])) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($requirements->accepts_module("perl", $])) 0 0 0
564 # BAIL: No suitable Perl here...
565 #
566 # well, we might want to see if Perlbrew is installed with an acceptable version?
567 #
568 # and if not, we could install Perlbrew here...
569 0 die $log->fatal( "Not running a Perl version compliant with LedgerSMB " . $config->effective_version );
570 }
571  
572 0 ▶ if ($config->effective_prepare_env) {
Branch: 1 branch
BranchTrueFalseTotal
if ($config->effective_prepare_env) 0 0 0
573 0 $dss->prepare_builder_env( $config );
574 }
575  
576 0 ▶ if ($dss->am_system_perl and $dss->pkg_can_install) { # and $dss->deps_can_map
Branch: 1 branch
BranchTrueFalseTotal
if ($dss->am_system_perl and $dss->pkg_can_install) { } 0 0 0
Condition0%0/3
$dss->am_system_perl and $dss->pkg_can_install
!ll&&!rl&&r
000
MC/DC0%0/2
$dss->am_system_perl and $dss->pkg_can_install
$dss->am_system_perl $dss->pkg_can_install
Truth table0%0/3
A and B
A= $dss->am_system_perlB= $dss->pkg_can_install
ABresult
0X0
100
111
577 0 ▶ if ($config->effective_prepare_env) {
Branch: 1 branch
BranchTrueFalseTotal
if ($config->effective_prepare_env) 0 0 0
578 0 $dss->prepare_pkg_resolver_env( $config );
579 }
580 0 ($pkg_deps, $unmapped_mods) = $class->_compute_dep_pkgs( $dss, $config );
581 }
582 else {
583 0 $unmapped_mods = [ $class->_compute_all_deps( $config ) ];
584 }
585  
586 0 $log->info( "Checking for availability of DBD::Pg" );
587 0 ▶ if (not eval { require DBD::Pg; 1; } # not loadable, and
Branch: 3 branches
BranchTrueFalseTotal
if (not eval { do { require DBD::Pg; 1 } } || $class->_module_will_install('DBD::Pg', $pkg_deps, $unmapped_mods)) { } 0 0 0
elsif (eval { do { require DBD::Pg; 1 } }) { } 0 0 0
elsif (not grep({$_ eq 'DBD::Pg';} @$unmapped_mods)) { } 0 0 0
Condition0%0/3
eval { do { require DBD::Pg; 1 } } || $class->_module_will_install('DBD::Pg', $pkg_deps, $unmapped_mods)
l!l&&r!l&&!r
000
MC/DC0%0/2
eval { do { require DBD::Pg; 1 } } || $class->_module_will_install('DBD::Pg', $pkg_deps, $unmapped_mods)
eval { do { require DBD::Pg; 1 } } $class->_module_will_install('DBD::Pg', $pkg_deps, $unmapped_mods)
Truth table0%0/3
A || B
A= eval { do { require DBD::Pg; 1 } }B= $class->_module_will_install('DBD::Pg', $pkg_deps, $unmapped_mods)
ABresult
1X1
011
000
588 and not $class->_module_will_install( 'DBD::Pg', $pkg_deps, $unmapped_mods )) {
589 # don't have DBD::Pg
590 # *and* won't install as part of $pkg_deps
591  
592 0 my $pg_config = $class->_find_pg_config( $dss, $config );
593 0 ▶ die $log->fatal( "Missing 'pg_config' command to build DBD::Pg" )
Branch: 1 branch
BranchTrueFalseTotal
unless $pg_config 0 0 0
594 unless $pg_config;
595 0 chomp( my $include_dir = `'$pg_config' --includedir` );
596  
597 0 $log->debug( "Directory for PostgreSQL headers: $include_dir" );
598 0 my $header_file = File::Spec->catfile( $include_dir, 'libpq-fe.h' );
599  
600 0 ▶ if (not -e $header_file) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-e $header_file) 0 0 0
601 0 ▶ if (not $dss->pkg_can_install) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($dss->pkg_can_install) 0 0 0
602 0 die $log->fatal( "Missing 'libpq-fe.h' PostgreSQL header to build DBD::Pg" );
603 }
604  
605 0 my ($run_deps, $build_deps) = $dss->pkg_deps_dbd_pg;
606 0 $config->mark_pkgs_for_cleanup( $build_deps );
607 0 push @extra_pkgs, $run_deps->@*, $build_deps->@*;
608 }
609 }
610 0 elsif (eval { require DBD::Pg; 1; }) {
611 0 $log->info( "DBD::Pg is loadable" );
612 }
613 0 elsif (not grep { $_ eq 'DBD::Pg' } $unmapped_mods->@*) {
614 0 $log->info( "DBD::Pg will be installed" );
615 }
616 else {
617 0 $log->fatal( "Internal error: DBD::Pg not available and won't be installed, but build prereqs not checked?!?!" );
618 }
619  
620 0 $log->info( "Checking for availability of LaTeX::Driver" );
621 0 ▶ if (not eval { require LaTeX::Driver; 1; } # loadable, and
Branch: 3 branches
BranchTrueFalseTotal
if (not eval { do { require LaTeX::Driver; 1 } } || $class->_module_will_install('LaTeX::Driver', $pkg_deps, $unmapped_mods)) { } 0 0 0
elsif (eval { do { require LaTeX::Driver; 1 } }) { } 0 0 0
elsif (not grep({$_ eq 'LaTeX::Driver';} @$unmapped_mods)) { } 0 0 0
Condition0%0/3
eval { do { require LaTeX::Driver; 1 } } || $class->_module_will_install('LaTeX::Driver', $pkg_deps, $unmapped_mods)
l!l&&r!l&&!r
000
MC/DC0%0/2
eval { do { require LaTeX::Driver; 1 } } || $class->_module_will_install('LaTeX::Driver', $pkg_deps, $unmapped_mods)
eval { do { require LaTeX::Driver; 1 } } $class->_module_will_install('LaTeX::Driver', $pkg_deps, $unmapped_mods)
Truth table0%0/3
A || B
A= eval { do { require LaTeX::Driver; 1 } }B= $class->_module_will_install('LaTeX::Driver', $pkg_deps, $unmapped_mods)
ABresult
1X1
011
000
622 and not $class->_module_will_install( 'LaTeX::Driver', $pkg_deps, $unmapped_mods )) {
623 # don't have LaTeX::Driver
624 # *and* won't install as part of $pkg_deps
625  
626 # testing early, because LaTeX::Driver only installs
627 # when LaTeX is installed...
628  
629 0 my $latex = $class->_find_latex( $dss, $config );
630 0 ▶ if (not $latex) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($latex) 0 0 0
631 0 ▶ if (not $dss->pkg_can_install) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($dss->pkg_can_install) 0 0 0
632 0 die $log->fatal( "Missing 'latex' executable required for building 'LaTeX::Driver' module" );
633 }
634 }
635 }
636 0 elsif (eval { require LaTeX::Driver; 1; }) {
637 0 $log->info( "LaTeX::Driver is loadable" );
638 }
639 0 elsif (not grep { $_ eq 'LaTeX::Driver' } $unmapped_mods->@*) {
640 0 $log->info( "LaTeX::Driver will be installed" );
641 }
642 else {
643 0 $log->fatal( "Internal error: LaTeX::Driver not available and won't be installed, but build prereqs not checked?!?!" );
644 }
645 0 ▶ if ($dss->pkg_can_install) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dss->pkg_can_install) { } 0 0 0
646 # installs LaTeX *and* styles required for standard templates
647 0 my ($run_deps, $build_deps) = $dss->pkg_deps_latex;
648 0 $config->mark_pkgs_for_cleanup( $build_deps );
649 0 push @extra_pkgs, $run_deps->@*, $build_deps->@*;
650 }
651 else {
652 ###TODO: figure out how to warn the user of minimal required
653 # styles configuration...
654 }
655  
656 0 $log->info( "Checking for availability of XML::Parser" );
657 0 ▶ if (not eval { require XML::Parser; 1; }
Branch: 3 branches
BranchTrueFalseTotal
if (not eval { do { require XML::Parser; 1 } } || $class->_module_will_install('XML::Parser', $pkg_deps, $unmapped_mods)) { } 0 0 0
elsif (eval { do { require XML::Parser; 1 } }) { } 0 0 0
elsif (not grep({$_ eq 'XML::Parser';} @$unmapped_mods)) { } 0 0 0
Condition0%0/3
eval { do { require XML::Parser; 1 } } || $class->_module_will_install('XML::Parser', $pkg_deps, $unmapped_mods)
l!l&&r!l&&!r
000
MC/DC0%0/2
eval { do { require XML::Parser; 1 } } || $class->_module_will_install('XML::Parser', $pkg_deps, $unmapped_mods)
eval { do { require XML::Parser; 1 } } $class->_module_will_install('XML::Parser', $pkg_deps, $unmapped_mods)
Truth table0%0/3
A || B
A= eval { do { require XML::Parser; 1 } }B= $class->_module_will_install('XML::Parser', $pkg_deps, $unmapped_mods)
ABresult
1X1
011
000
658 and not $class->_module_will_install( 'XML::Parser', $pkg_deps, $unmapped_mods)) {
659  
660 0 $log->info( "Checking availability of libexpat" );
661 0 ▶ my $incpath = $ENV{EXPATINCPATH} // '';
Condition0%0/2
$ENV{"EXPATINCPATH"} // ""
l!l
00
MC/DC0%0/1
$ENV{"EXPATINCPATH"} // ""
$ENV{"EXPATINCPATH"}
Truth table0%0/2
A
A= $ENV{"EXPATINCPATH"}
Aresult
11
00
662 0 ▶ my $libpath = $ENV{EXPATLIBPATH} // '';
Condition0%0/2
$ENV{"EXPATLIBPATH"} // ""
l!l
00
MC/DC0%0/1
$ENV{"EXPATLIBPATH"} // ""
$ENV{"EXPATLIBPATH"}
Truth table0%0/2
A
A= $ENV{"EXPATLIBPATH"}
Aresult
11
00
663  
664 # Devel::CheckLib tries to find the C compiler when use-d
665 # however, we might be installing it as part of the installation
666 # process, so we don't want Devel::CheckLib to check when loading the script...
667 0 eval "use Devel::CheckLib qw(assert_lib);";
668 0 ▶ unless (eval { assert_lib( lib => [qw(expat)],
Branch: 2 branches
BranchTrueFalseTotal
if (eval { do { assert_lib('lib', ['expat'], 'header', ['expat.h'], 'incpath', $incpath, $libpath ? ('libpath', $libpath) : ()); 1 } }) { } 0 0 0
$libpath ? : 0 0 0
669 header => ['expat.h'],
670 incpath => $incpath,
671 ( $libpath ? (libpath => $libpath) : () )
672 0 ); 1; }) {
673 0 ▶ if (not $dss->pkg_can_install) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $dss->pkg_can_install) { } 0 0 0
674 ###TODO: We could push Alien::Expat into @unmapped_mods
675 # instead of bailing out here...
676 0 die $log->fatal( "Missing XML parser library Expat blocking installation of XML::Parser" );
677 }
678 else {
679 0 my ($run_deps, $build_deps) = $dss->pkg_deps_expat;
680 0 $config->mark_pkgs_for_cleanup( $build_deps );
681 0 push @extra_pkgs, $run_deps->@*, $build_deps->@*;
682 }
683 }
684 else {
685 0 $log->info( "Found expat header and library for XML::Parser compilation" );
686 }
687 }
688 0 elsif (eval { require XML::Parser; 1; }) {
689 0 $log->info( "XML::Parser is loadable" );
690 }
691 0 elsif (not grep { $_ eq 'XML::Parser' } $unmapped_mods->@*) {
692 0 $log->info( "XML::Parser will be installed" );
693 }
694 else {
695 0 $log->fatal( "Internal error: XML::Parser not available and won't be installed, but build prereqs not checked?!?!" );
696 }
697  
698 0 ▶ if ((not eval { require XML::LibXML; 1; }
Branch: 1 branch
BranchTrueFalseTotal
unless (eval { do { require XML::LibXML; 1 } } or $class->_module_will_install("XML::LibXML", $pkg_deps, $unmapped_mods) or (eval { do { require XML::Twig; 1 } } or $class->_module_will_install("XML::Twig", $pkg_deps, $unmapped_mods))) 0 0 0
Condition0%0/9
eval { do { require XML::LibXML; 1 } } or $class->_module_will_install("XML::LibXML", $pkg_deps, $unmapped_mods) or (eval { do { require XML::Twig; 1 } } or $class->_module_will_install("XML::Twig", $pkg_deps, $unmapped_mods))
l!l&&r!l&&!r
000
eval { do { require XML::LibXML; 1 } } or $class->_module_will_install("XML::LibXML", $pkg_deps, $unmapped_mods)
l!l&&r!l&&!r
000
eval { do { require XML::Twig; 1 } } or $class->_module_will_install("XML::Twig", $pkg_deps, $unmapped_mods)
l!l&&r!l&&!r
000
MC/DC0%0/4
eval { do { require XML::LibXML; 1 } } or $class->_module_will_install("XML::LibXML", $pkg_deps, $unmapped_mods) or (eval { do { require XML::Twig; 1 } } or $class->_module_will_install("XML::Twig", $pkg_deps, $unmapped_mods))
eval { do { require XML::LibXML; 1 } } $class->_module_will_install("XML::LibXML", $pkg_deps, $unmapped_mods) eval { do { require XML::Twig; 1 } } $class->_module_will_install("XML::Twig", $pkg_deps, $unmapped_mods)
Truth table0%0/5
A or B or C or D
A= eval { do { require XML::LibXML; 1 } }B= $class->_module_will_install("XML::LibXML", $pkg_deps, $unmapped_mods)C= eval { do { require XML::Twig; 1 } }D= $class->_module_will_install("XML::Twig", $pkg_deps, $unmapped_mods)
ABCDresult
1XXX1
01XX1
001X1
00011
00000
699 and not $class->_module_will_install( 'XML::LibXML', $pkg_deps, $unmapped_mods ))
700 0 and (not eval { require XML::Twig; 1; }
701 and not $class->_module_will_install( 'XML::Twig', $pkg_deps, $unmapped_mods ))) {
702 # don't have either XML::LibXML or XML::Twig
703  
704 0 my $xml2_config = $class->_find_xml2_config( $dss, $config );
705 0 ▶ if (not $xml2_config) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($xml2_config) 0 0 0
706 0 ▶ if (not $dss->pkg_can_install) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $dss->pkg_can_install) { } 0 0 0
707 0 warn $log->warning("Missing 'xml2-config' executable required for building XML::LibXML -- falling back to Alien::Libxml2" );
708 }
709 else {
710 0 my ($run_deps, $build_deps) = $dss->pkg_deps_xml;
711 0 $config->mark_pkgs_for_cleanup( $build_deps );
712 0 push @extra_pkgs, $run_deps->@*, $build_deps->@*;
713 }
714 }
715 }
716  
717 0 ▶ goto PREPARE_TREE if (not $pkg_deps or not $pkg_deps->@*);
Branch: 1 branch
BranchTrueFalseTotal
unless $pkg_deps and @$pkg_deps 0 0 0
Condition0%0/3
$pkg_deps and @$pkg_deps
!ll&&!rl&&r
000
MC/DC0%0/2
$pkg_deps and @$pkg_deps
$pkg_deps @$pkg_deps
Truth table0%0/3
A and B
A= $pkg_depsB= @$pkg_deps
ABresult
0X0
100
111
718  
719 0 INSTALL_SYS_PKGS:
720 $log->info( "Installing O/S packages: " . join(' ', $pkg_deps->@*) );
721 0 $dss->pkg_install( $pkg_deps );
722  
723 PREPARE_TREE:
724 0 ▶ if (@extra_pkgs) {
Branch: 1 branch
BranchTrueFalseTotal
if (@extra_pkgs) 0 0 0
725 0 $log->info( "Installing build dependency packages: " . join(' ', @extra_pkgs) );
726 0 $dss->pkg_install( \@extra_pkgs );
727 }
728 0 ▶ if ($config->effective_prepare_env) {
Branch: 1 branch
BranchTrueFalseTotal
if ($config->effective_prepare_env) 0 0 0
729 0 $dss->prepare_installer_env( $config );
730 }
731  
732 ###TODO: ideally, we pass the immediate dependencies instead of the installation path;
733 # that allows selection of specific features in a later iteration
734 #
735 # Installs dependencies from cpanfile (because it respects dependency versions,
736 # which the simple list of dependencies does not); then installs the extra
737 # dependencies which were not satisfied from the list of unmapped_mods)
738 0 $dss->cpanm_install( $config->installpath, $config->locallib, $unmapped_mods );
739 0 $rv = 0;
740  
741 0 $log->info( "Generating application server startup script (server-start)" );
742 0 $dss->generate_start_script( File::Spec->rel2abs( $config->installpath ),
743 File::Spec->rel2abs( $config->locallib ) );
744  
745 0 CLEANUP:
746 $log->warning( "Cleaning up Perl module installation dependencies" );
747 0 $dss->cleanup_env($config);
748  
749 0 ▶ if ($rv) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rv) { } 0 0 0
750 0 ▶ if (-e $config->installpath) {
Branch: 1 branch
BranchTrueFalseTotal
if (-e $config->installpath) 0 0 0
751 0 $log->warning( "Cleaning up installation path" );
752 0 remove_tree $config->installpath;
753 }
754  
755 0 say "Failed to complete server installation.";
756 }
757 else {
758 0 my $installpath = $config->installpath;
759 0 say "
760 LedgerSMB installation into $installpath completed.
761  
762 The LedgerSMB server can be started using the generated
763 startup script:
764  
765 \$ $installpath/server-start
766  
767 The server will run with its default configuration. To change
768 the configuration, copy the file doc/conf/ledgersmb.yaml to
769 $installpath and modify it. After modification, restart the
770 LedgerSMB server to activate the new configuration.
771  
772 ";
773 }
774  
775 0 return $rv;
776 }
777  
778 0 ▶sub print_id( $class, @args) {
Subroutine print_id: not called CC=1 SCAR=6.9
Pod undocumented
779 0 my $dss = $class->_load_dist_support;
780 0 say $dss->dependency_packages_identifier;
781 }
782  
783 0 ▶sub run($class, $cmd, @args) {
Subroutine run: not called CC=8 SCAR=42.8
Pod undocumented
784 0 STDOUT->autoflush(1);
785 0 STDERR->autoflush(1);
786  
787 0 ▶ if ($cmd =~ m/^-/) { # option(s)
Branch: 1 branch
BranchTrueFalseTotal
if ($cmd =~ /^-/u) 0 0 0
788 0 unshift @args, $cmd;
789 0 $cmd = 'install';
790 }
791  
792 0 ▶ if ($cmd eq 'compute') {
Branch: 6 branches
BranchTrueFalseTotal
if ($cmd eq 'compute') { } 0 0 0
elsif ($cmd eq 'download') { } 0 0 0
elsif ($cmd eq 'help') { } 0 0 0
elsif ($cmd eq 'available') { } 0 0 0
elsif ($cmd eq 'install') { } 0 0 0
elsif ($cmd eq 'system-id') { } 0 0 0
793 0 say $log->info( "Computing dependencies using installer $INSTALLER_VERSION" );
794 0 return $class->compute( @args );
795 }
796 elsif ($cmd eq 'download') {
797 0 return $class->download( @args );
798 }
799 elsif ($cmd eq 'help') {
800 0 return $class->help( @args );
801 }
802 elsif ($cmd eq 'available') {
803 0 say $log->info( "Retrieving list of available versions for installation" );
804 0 return $class->available( @args );
805 }
806 elsif ($cmd eq 'install') {
807 0 say $log->info( "Installing LedgerSMB using installer $INSTALLER_VERSION" );
808 0 return $class->install( @args );
809 }
810 elsif ($cmd eq 'system-id') {
811 0 return $class->print_id( @args );
812 }
813 else {
814 0 $class->help();
815 0 exit 1;
816 }
817 }
818  
819  
820 1 1;
821  
822 =head1 NAME
823  
824 LedgerSMB::Installer - Installer for the LedgerSMB accounting web application
825  
826 =head1 DESCRIPTION
827  
828 =head1 MAINTAINER
829  
830 Erik Huelsmann
831  
832 =head1 AUTHOR
833  
834 Erik Huelsmann
835  
836 =head1 LICENSE
837  
838 Copyright 2025 Erik Huelsmann
839  
840 Permission is hereby granted, free of charge, to any person obtaining a copy
841 of this software and associated documentation files (the "Software"), to deal
842 in the Software without restriction, including without limitation the rights
843 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
844 copies of the Software, and to permit persons to whom the Software is
845 furnished to do so, subject to the following conditions:
846  
847 The above copyright notice and this permission notice shall be included in
848 all copies or substantial portions of the Software.
849  
850 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
851 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
852 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
853 THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
854 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
855 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
856 SOFTWARE.
857  
858 =cut
859  
860 __DATA__
↑ Summary Installer/OS.pm »