blib/lib/WebDyne/Install.pm

filter: Statementstmt 91.3% 84 / 92 Branchbran 47.0% 16 / 34 Conditioncond 36.3% 4 / 11 MC/DCmcdc 14.2% 1 / 7 Subroutinesub 100% 16 / 16 Podpod 0.0% 0 / 4 totaltotal 73.7% 121 / 164 CC 23 SCAR 19.9
CC
23
Cov
76%
uninstall
12.6
install
11.8
cache_dn
7.3
CRAP 7.3
« blib/lib/WebDyne/Request/Fake.pm ↑ Summary blib/lib/WebDyne/Filter.pm »
1 #
2 # This file is part of WebDyne.
3 #
4 # This software is copyright (c) 2026 by Andrew Speer <andrew.speer@isolutions.com.au>.
5 #
6 # This is free software; you can redistribute it and/or modify it under
7 # the same terms as the Perl 5 programming language system itself.
8 #
9 # Full license text is available at:
10 #
11 # <http://dev.perl.org/licenses/>
12 #
13 package WebDyne::Install;
14  
15  
16 # Compiler Pragma
17 #
18 6 ▶sub BEGIN {$^W=0}
Subroutine BEGIN: called CC=1 SCAR=0.0
19 6 ▶use strict qw(vars);
Subroutine BEGIN: called CC=1 SCAR=0.0
20 6 ▶use vars qw($VERSION @EXPORT_OK @ISA);
Subroutine BEGIN: called CC=1 SCAR=0.0
21 6 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
22 6 ▶no warnings qw(uninitialized);
Subroutine BEGIN: called CC=1 SCAR=0.0
23  
24  
25 # Export the message function
26 #
27 6 require Exporter;
28 6 @ISA=qw(Exporter);
29 6 @EXPORT_OK=qw(&message);
30  
31  
32 # WebDyne Modules
33 #
34 6 ▶use WebDyne::Util;
Subroutine BEGIN: called CC=1 SCAR=0.0
35  
36  
37 # Constants
38 #
39 6 ▶use WebDyne::Constant;
Subroutine BEGIN: called CC=1 SCAR=0.0
40 6 ▶use WebDyne::Install::Constant;
Subroutine BEGIN: called CC=1 SCAR=0.0
41  
42  
43 # External Modules
44 #
45 6 ▶use File::Path;
Subroutine BEGIN: called CC=1 SCAR=0.0
46 6 ▶use File::Spec;
Subroutine BEGIN: called CC=1 SCAR=0.0
47 6 ▶use IO::File;
Subroutine BEGIN: called CC=1 SCAR=0.0
48 6 ▶use Config;
Subroutine BEGIN: called CC=1 SCAR=0.0
49  
50  
51 # Version information
52 #
53 6 $VERSION='3.029';
54  
55  
56 # Debug
57 #
58 6 0 && debug("%s loaded, version $VERSION", __PACKAGE__);
59  
60  
61 # Uninstaller global
62 #
63 6 my $Uninstall_fg;
64  
65  
66 # Init done.
67 #
68 6 1;
69  
70  
71 #------------------------------------------------------------------------------
72  
73  
74 36 ▶sub message {
Subroutine message: called CC=4 SCAR=13.9
Pod undocumented
75  
76  
77 # Print out messages unless silent flag set
78 #
79 36 ▶ return if $ENV{'SILENT'};
Branch: 1 branch
BranchTrueFalseTotal
if $ENV{"SILENT"} 0 36 36
80 36 ▶ @_ || return print $/;
Branch: 1 branch
BranchTrueFalseTotal
@_ or return print($/) 29 7 36
81 29 ▶ my $message=
Condition100%2/2
$Uninstall_fg && 'un'
!ll
1217
MC/DC100%1/1
$Uninstall_fg && 'un'
$Uninstall_fg
Truth table100%2/2
A
A= $Uninstall_fg
Aresult
00
11
82 sprintf(join('[%sinstall] - ', undef, ucfirst(shift())) . $/, $Uninstall_fg && 'un', @_);
83 29 $message=~s/\.?$/\./;
84 29 print $message;
85  
86  
87 }
88  
89  
90 2 ▶sub uninstall {
Subroutine uninstall: called CC=11 SCAR=25.4
Pod undocumented
91  
92  
93 # Get prefix, discard class
94 #
95 2 my (undef, $prefix)=@_;
96 2 ▶ $prefix=undef if ($prefix eq $Config{'prefix'});
Branch: 1 branch
BranchTrueFalseTotal
if $prefix eq $WebDyne::Install::Config{"prefix"} 0 2 2
97  
98  
99 # Set uninstall flag
100 #
101 2 $Uninstall_fg++;
102 2 message;
103  
104  
105 # Get cache dn
106 #
107 2 my $cache_dn=&cache_dn($prefix);
108 2 my $dry_run=$ENV{'DRY_RUN'};
109  
110  
111 # Delete cache files and remove if empty
112 #
113 2 ▶ if ($cache_dn && (-d $cache_dn)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cache_dn and -d $cache_dn) 2 0 2
Condition33%1/3
$cache_dn and -d $cache_dn
!ll&&!rl&&r
002
MC/DC0%0/2
$cache_dn and -d $cache_dn
$cache_dn -d $cache_dn
Truth table33%1/3
A and B
A= $cache_dnB= -d $cache_dn
ABresult
0X0
100
111
114 2 my @file_cn=glob(File::Spec->catfile($cache_dn, '*'));
115 2 message "removing cache files from '$cache_dn'";
116 2 foreach my $fn (grep {/\w{32}(\.html)?$/} @file_cn) {
117 4 ▶ if ($dry_run) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dry_run) 2 2 4
118 2 message "would remove cache file '$fn'";
119 2 next;
120 }
121 2 ▶ unlink($fn) ||
Branch: 1 branch
BranchTrueFalseTotal
unlink $fn or return err("unable to remove cache file $fn, $!") 2 0 2
122 return err("unable to remove cache file $fn, $!");
123 }
124 2 message "removing cache directory '$cache_dn'";
125 2 ▶ unless ($cache_dn eq File::Spec->tmpdir) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($cache_dn eq "File::Spec"->tmpdir) 2 0 2
126 2 ▶ if ($dry_run) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dry_run) { } 1 1 2
127 1 message "would remove cache directory '$cache_dn'";
128 }
129 else {
130 1 my @remaining=glob(File::Spec->catfile($cache_dn, '*'));
131 1 ▶ unless (@remaining) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@remaining) 0 1 1
132 0 ▶ rmdir($cache_dn) ||
Branch: 1 branch
BranchTrueFalseTotal
rmdir $cache_dn or return err("unable to remove cache directory $cache_dn, $!") 0 0 0
133 return err("unable to remove cache directory $cache_dn, $!");
134 }
135 }
136 }
137 }
138  
139 #if ($prefix) {
140 # message "updating perl5lib config.";
141 # &perl5lib::del($prefix) if $prefix;
142 # rmdir($prefix) if $prefix;
143 #}
144  
145  
146 # Done
147 #
148 2 return \undef;
149  
150 }
151  
152  
153 # Create cache dir and update perl5lib param
154 #
155 1 ▶sub install {
Subroutine install: called CC=7 SCAR=24.7
Pod undocumented
156  
157  
158 # Get prefix, discard class
159 #
160 1 my (undef, $prefix)=@_;
161 #$prefix=undef if ($prefix eq $Config{'prefix'});
162 1 ▶ $prefix=undef if ($prefix=~/^$Config{'prefix'}/);
Branch: 1 branch
BranchTrueFalseTotal
if $prefix =~ /^$WebDyne::Install::Config{"prefix"}/ 0 1 1
163  
164 1 message;
165 1 ▶ message sprintf(q[installation source directory '%s'.], $prefix || $Config{'prefix'});
Condition33%1/3
$prefix || $WebDyne::Install::Config{'prefix'}
l!l&&r!l&&!r
100
MC/DC0%0/2
$prefix || $WebDyne::Install::Config{'prefix'}
$prefix $WebDyne::Install::Config{'prefix'}
Truth table33%1/3
A || B
A= $prefixB= $WebDyne::Install::Config{'prefix'}
ABresult
1X1
011
000
166  
167  
168 # Create the cache dir
169 #
170 1 ▶ unless (-d (my $cache_dn=&cache_dn($prefix))) {
Branch: 1 branch
BranchTrueFalseTotal
if (-d (my $cache_dn = &cache_dn($prefix))) { } 0 1 1
171  
172 # Make
173 #
174 1 message "creating cache directory '$cache_dn'.";
175 1 ▶ if ($ENV{'DRY_RUN'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ENV{'DRY_RUN'}) { } 1 0 1
176 1 message "would create cache directory '$cache_dn'.";
177 }
178 else {
179 0 ▶ File::Path::mkpath($cache_dn, 0, 0755) || do {
Branch: 1 branch
BranchTrueFalseTotal
File::Path::mkpath($cache_dn, 0, 493) or do { return err("unable to create dir $cache_dn") unless -d $cache_dn } 0 0 0
180 0 ▶ return err("unable to create dir $cache_dn") unless (-d $cache_dn)
Branch: 1 branch
BranchTrueFalseTotal
unless -d $cache_dn 0 0 0
181 };
182 }
183  
184 }
185 else {
186  
187 0 message "using existing cache directory '$cache_dn'.";
188  
189 }
190  
191  
192 # Add prefix to perl5lib store
193 #
194 #message "updating perl5lib config.";
195 #&perl5lib::add($prefix) if $prefix;
196  
197  
198 # Done
199 #
200 1 message;
201  
202  
203 # Done
204 #
205 1 return \undef;
206  
207 }
208  
209  
210 # Work out cache dn
211 #
212 7 ▶sub cache_dn {
Subroutine cache_dn: called CC=4 SCAR=19.8
Pod undocumented
213  
214  
215 # Get any prefix supplied
216 #
217 7 my $prefix=shift();
218  
219  
220 # Var to hold returned result
221 #
222 7 my $cache_dn;
223  
224  
225 # Use user specified location
226 #
227 7 ▶ if ($WEBDYNE_CACHE_DN) {
Branch: 2 branches
BranchTrueFalseTotal
if ($WebDyne::Install::WEBDYNE_CACHE_DN) { } 7 0 7
elsif ($prefix and not $prefix =~ /^$WebDyne::Install::Config{'prefix'}/) { } 0 0 0
228 7 $cache_dn=$WEBDYNE_CACHE_DN;
229 7 0 && debug("using WEBDYNE_CACHE_DN: $WEBDYNE_CACHE_DN for cache_dn");
230 }
231  
232 # If installed into custom location via PREFIX, but not the same
233 # as the Perl instal,
234 #elsif ($prefix && ($prefix ne $Config{'prefix'})) {
235 ▶ elsif ($prefix && ($prefix !~ /^$Config{'prefix'}/)) {
Condition0%0/3
$prefix and not $prefix =~ /^$WebDyne::Install::Config{"prefix"}/
!ll&&!rl&&r
000
MC/DC0%0/2
$prefix and not $prefix =~ /^$WebDyne::Install::Config{"prefix"}/
$prefix not $prefix =~ /^$WebDyne::Install::Config{"prefix"}/
Truth table0%0/3
A and not(B)
A= $prefixB= not $prefix =~ /^$WebDyne::Install::Config{"prefix"}/
ABresult
0X0
100
111
236 0 $cache_dn=File::Spec->catdir($prefix, 'cache');
237 0 0 && debug("using prefix: $prefix for cache_dn");
238 }
239  
240  
241 # No prefix spec'd, or prefix is the same as Perl install dir, so
242 # use default location
243 #
244 else {
245 0 $cache_dn=$DIR_CACHE_DEFAULT;
246 0 0 && debug("using DIR_CACHE_DEFAULT: $DIR_CACHE_DEFAULT as cache_dn");
247 }
248  
249  
250 # Done return result
251 #
252 7 return $cache_dn;
253  
254 }
255 __END__
« blib/lib/WebDyne/Request/Fake.pm ↑ Summary blib/lib/WebDyne/Filter.pm »