_build/lib/MyModuleBuilder.pm

filter: Statementstmt 31.9% 60 / 188 Branchbran 17.7% 16 / 90 Conditioncond 44.4% 4 / 9 MC/DCmcdc 20.0% 1 / 5 Subroutinesub 51.8% 14 / 27 Podpod 0.0% 0 / 18 totaltotal 28.1% 95 / 337 CC 52 SCAR 46.1
CC
52
Cov
28%
ACTION_post_install
380.0
manify_sbin_pods
30.0
process_sbin_files
30.0
CRAP 100.8
« blib/lib/XAS/Lib/Process.pm ↑ Summary blib/lib/XAS/Lib/Batch/Interface/Torque.pm »
1 package MyModuleBuilder;
2 1 ▶use Module::Build;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 our @ISA = qw(Module::Build);
4  
5 1 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶ use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶ use IO::File;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶ use File::Find;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶ use File::Basename;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶ use File::Spec::Functions qw( catfile catdir rel2abs );
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 # override and add a few things
13  
14 sub new {
15 0 ▶ my $class = shift;
Subroutine new: not called CC=1 SCAR=6.9
Pod undocumented
16  
17 0 my $self = $class->SUPER::new(@_);
18  
19 0 my $blib = $self->{properties}{blib};
20 0 my $sbin = catfile($blib, 'sbin');
21 0 $self->{properties}{sbindoc_dirs} = [ $sbin ];
22  
23 0 return $self;
24  
25 }
26  
27 # create man pages for files within sbin
28  
29 sub manify_sbin_pods {
30 0 ▶ my $self = shift;
Subroutine manify_sbin_pods: not called CC=5 SCAR=34.0
Pod undocumented
31  
32 my $files = $self->_find_pods(
33 $self->{properties}{sbindoc_dirs},
34 0 exclude => [ $self->file_qr('\.bat$') ]
35 );
36  
37 0 ▶ return unless keys %$files;
Branch: 1 branch
BranchTrueFalseTotal
unless keys %$files 0 0 0
38  
39 0 my $mandir = File::Spec->catdir( $self->blib, 'bindoc' );
40 0 File::Path::mkpath( $mandir, 0, oct(777) );
41  
42 0 require Pod::Man;
43  
44 0 foreach my $file (keys %$files) {
45  
46 # Pod::Simple based parsers only support one document per instance.
47 # This is expected to change in a future version
48 # (Pod::Simple > 3.03).
49  
50 # binaries go in section 1p
51  
52 0 my $parser = Pod::Man->new( section => '1p' );
53 0 my $manpage = $self->man1page_name( $file ) . '.' .
54 $self->config( 'man1ext' );
55  
56 0 my $outfile = File::Spec->catfile($mandir, $manpage);
57  
58 0 ▶ next if $self->up_to_date( $file, $outfile );
Branch: 1 branch
BranchTrueFalseTotal
if $self->up_to_date($file, $outfile) 0 0 0
59  
60 0 $self->log_verbose("Manifying $file -> $outfile\n");
61  
62 0 ▶ eval { $parser->parse_from_file( $file, $outfile ); 1 }
Branch: 1 branch
BranchTrueFalseTotal
eval { do { $parser->parse_from_file($file, $outfile); 1 } } or $self->log_warn("Error creating '${outfile}': $@\n") 0 0 0
63 or $self->log_warn("Error creating '$outfile': $@\n");
64
65 0 $files->{$file} = $outfile;
66  
67 }
68  
69 }
70  
71 # set up directory structure and user/group accounts
72  
73 sub ACTION_post_install {
74 0 ▶ my $self = shift;
Subroutine ACTION_post_install: not called CC=19 SCAR=59.4
Pod undocumented
75  
76 # create xas owner/group
77  
78 0 ▶ unless ($^O eq 'MSWin32') {
Branch: 1 branch
BranchTrueFalseTotal
if ($^O eq 'MSWin32') { } 0 0 0
79  
80 0 ▶ unless (getpwnam('xas')) {
Branch: 1 branch
BranchTrueFalseTotal
unless (getpwnam "xas") 0 0 0
81  
82 0 system("groupadd -f -r xas");
83 0 system("useradd -r -g xas -d /var/lib/xas -s /sbin/nologin -c \"XAS\" xas");
84  
85 }
86  
87 # using the standard filesystem layout
88  
89 0 ▶ system("mkdir /etc/xas") unless ( -e '/etc/xas');
Branch: 1 branch
BranchTrueFalseTotal
unless -e "/etc/xas" 0 0 0
90 0 ▶ system("mkdir /var/log/xas") unless ( -e '/var/log/xas');
Branch: 1 branch
BranchTrueFalseTotal
unless -e "/var/log/xas" 0 0 0
91 0 ▶ system("mkdir /var/lib/xas") unless ( -e '/var/lib/xas');
Branch: 1 branch
BranchTrueFalseTotal
unless -e "/var/lib/xas" 0 0 0
92 0 ▶ system("mkdir /var/run/xas") unless ( -e '/var/run/xas');
Branch: 1 branch
BranchTrueFalseTotal
unless -e "/var/run/xas" 0 0 0
93 0 ▶ system("mkdir /var/spool/xas") unless ( -e '/var/spool/xas');
Branch: 1 branch
BranchTrueFalseTotal
unless -e "/var/spool/xas" 0 0 0
94  
95 # create some spool directories
96  
97 0 ▶ system("mkdir /var/spool/xas/alerts") unless ( -e '/var/spool/xas/alerts');
Branch: 1 branch
BranchTrueFalseTotal
unless -e "/var/spool/xas/alerts" 0 0 0
98 0 ▶ system("mkdir /var/spool/xas/logs") unless ( -e '/var/spool/xas/logs');
Branch: 1 branch
BranchTrueFalseTotal
unless -e "/var/spool/xas/logs" 0 0 0
99  
100 # set ownership/permissions on the files/directories
101  
102 0 system("chown -R xas:xas /var/log/xas");
103 0 system("chown -R xas:xas /var/lib/xas");
104 0 system("chown -R xas:xas /var/run/xas");
105 0 system("chown -R xas:xas /var/spool/xas");
106  
107 0 system("chmod 0775 /var/log/xas");
108 0 system("chmod 0775 /var/lib/xas");
109 0 system("chmod 0775 /var/run/xas");
110 0 system("chmod 0775 /var/spool/xas");
111 0 system("chmod 0775 /var/spool/xas/alerts");
112 0 system("chmod 0775 /var/spool/xas/logs");
113  
114 0 system("chmod g+s /var/log/xas");
115 0 system("chmod g+s /var/lib/xas");
116 0 system("chmod g+s /var/run/xas");
117 0 system("chmod g+s /var/spool/xas");
118 0 system("chmod g+s /var/spool/xas/alerts");
119 0 system("chmod g+s /var/spool/xas/logs");
120  
121 } else {
122  
123 0 my $dir;
124 0 ▶ my $base = defined($ENV{'XAS_ROOT'}) ? $ENV{'XAS_ROOT'} : 'C:\\xas';
Branch: 1 branch
BranchTrueFalseTotal
defined $ENV{'XAS_ROOT'} ? : 0 0 0
125  
126 0 $dir = catdir($base, 'tmp');
127 0 ▶ system("mkdir $dir") unless ( -e $dir);
Branch: 1 branch
BranchTrueFalseTotal
unless -e $dir 0 0 0
128  
129 0 $dir = catdir($base, 'var');
130 0 ▶ system("mkdir $dir") unless ( -e $dir);
Branch: 1 branch
BranchTrueFalseTotal
unless -e $dir 0 0 0
131  
132 0 $dir = catdir($base, 'var', 'log');
133 0 ▶ system("mkdir $dir") unless ( -e $dir);
Branch: 1 branch
BranchTrueFalseTotal
unless -e $dir 0 0 0
134  
135 0 $dir = catdir($base, 'var', 'run');
136 0 ▶ system("mkdir $dir") unless ( -e $dir);
Branch: 1 branch
BranchTrueFalseTotal
unless -e $dir 0 0 0
137  
138 0 $dir = catdir($base, 'var', 'lib');
139 0 ▶ system("mkdir $dir") unless ( -e $dir);
Branch: 1 branch
BranchTrueFalseTotal
unless -e $dir 0 0 0
140  
141 0 $dir = catdir($base, 'var', 'spool');
142 0 ▶ system("mkdir $dir") unless ( -e $dir);
Branch: 1 branch
BranchTrueFalseTotal
unless -e $dir 0 0 0
143  
144 0 $dir = catdir($base, 'var', 'spool', 'alerts');
145 0 ▶ system("mkdir $dir") unless ( -e $dir);
Branch: 1 branch
BranchTrueFalseTotal
unless -e $dir 0 0 0
146  
147 0 $dir = catdir($base, 'var', 'spool', 'logs');
148 0 ▶ system("mkdir $dir") unless ( -e $dir);
Branch: 1 branch
BranchTrueFalseTotal
unless -e $dir 0 0 0
149  
150 }
151  
152 0 return $self;
153  
154 }
155  
156 # remove redhat stuff when installing to debian
157  
158 sub ACTION_debian {
159 0 ▶ my $self = shift;
Subroutine ACTION_debian: not called CC=3 SCAR=24.8
Pod undocumented
160  
161 # cleanup the profile.d directory
162  
163 0 my $destdir = $self->destdir;
164 0 my @files = ('xas.bat');
165 0 my @names = map { catfile($destdir, 'etc', 'profile.d', $_) } @files;
166  
167 0 foreach my $file (@names) {
168  
169 0 ▶ unlink $file if (-e $file);
Branch: 1 branch
BranchTrueFalseTotal
if -e $file 0 0 0
170  
171 }
172  
173 }
174  
175 # remove debian stuff when installing to redhat
176  
177 sub ACTION_redhat {
178 0 ▶ my $self = shift;
Subroutine ACTION_redhat: not called CC=3 SCAR=24.8
Pod undocumented
179  
180 # cleanup the profile.d directory
181  
182 0 my $destdir = $self->destdir;
183 0 my @files = ('xas.bat');
184 0 my @names = map { catfile($destdir, 'etc', 'profile.d', $_) } @files;
185  
186 0 foreach my $file (@names) {
187  
188 0 ▶ unlink $file if (-e $file);
Branch: 1 branch
BranchTrueFalseTotal
if -e $file 0 0 0
189  
190 }
191  
192 }
193  
194 # correctly process additional directories
195  
196 sub process_etc_files {
197 1 ▶ my $self = shift;
Subroutine process_etc_files: called CC=3 SCAR=11.0
Pod undocumented
198  
199 1 my $result;
200 1 my $dir = catfile('blib', 'etc');
201 1 my $files = $self->find_etc_files;
202  
203 1 ▶ mkdir $dir unless (-e $dir);
Branch: 1 branch
BranchTrueFalseTotal
unless -e $dir 0 1 1
204  
205 1 ▶ while (my ($from, $to) = each %$files) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %$files) 1 1 2
206  
207 1 $to = catfile('blib', $to);
208 1 $result = $self->copy_if_modified(from => $from, to => $to);
209  
210 }
211  
212 1 return $self;
213  
214 }
215  
216 # correctly process additional directories
217  
218 sub process_sbin_files {
219 0 ▶ my $self = shift;
Subroutine process_sbin_files: not called CC=5 SCAR=34.0
Pod undocumented
220  
221 0 my $result;
222 0 my $dir = catfile('blib', 'sbin');
223 0 my $files = $self->find_sbin_files;
224  
225 0 ▶ mkdir $dir unless (-e $dir);
Branch: 1 branch
BranchTrueFalseTotal
unless -e $dir 0 0 0
226  
227 0 ▶ while (my ($from, $to) = each %$files) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %$files) 0 0 0
228  
229 0 $to = catfile('blib', $to);
230 0 ▶ $result = $self->copy_if_modified(from => $from, to => $to) or next;
Branch: 1 branch
BranchTrueFalseTotal
$result = $self->copy_if_modified("from", $from, "to", $to) or next 0 0 0
231 0 ▶ $self->fix_shebang_line($result) unless $self->is_vmsish;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->is_vmsish 0 0 0
232 0 $self->make_executable($result);
233  
234 }
235  
236 0 $self->manify_sbin_pods();
237  
238 0 return $self;
239  
240 }
241  
242 sub process_initd_files {
243 0 ▶ my $self = shift;
Subroutine process_initd_files: not called CC=4 SCAR=30.0
Pod undocumented
244  
245 0 my $result;
246 0 my $dir = catfile('blib', 'init.d');
247 0 my $files = $self->find_initd_files;
248  
249 0 ▶ mkdir $dir unless (-e $dir);
Branch: 1 branch
BranchTrueFalseTotal
unless -e $dir 0 0 0
250  
251 0 ▶ while (my ($from, $to) = each %$files) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %$files) 0 0 0
252  
253 0 $to = catfile('blib', $to);
254 0 ▶ $result = $self->copy_if_modified(from => $from, to => $to) or next;
Branch: 1 branch
BranchTrueFalseTotal
$result = $self->copy_if_modified("from", $from, "to", $to) or next 0 0 0
255 0 $self->make_executable($from);
256  
257 }
258  
259 0 return $self;
260  
261 }
262  
263 sub process_sysconf_files {
264 0 ▶ my $self = shift;
Subroutine process_sysconf_files: not called CC=3 SCAR=24.8
Pod undocumented
265  
266 0 my $result;
267 0 my $dir = catfile('blib', 'sysconfig');
268 0 my $files = $self->find_sysconf_files;
269  
270 0 ▶ mkdir $dir unless (-e $dir);
Branch: 1 branch
BranchTrueFalseTotal
unless -e $dir 0 0 0
271  
272 0 ▶ while (my ($from, $to) = each %$files) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %$files) 0 0 0
273  
274 0 $to = catfile('blib', $to);
275 0 $result = $self->copy_if_modified(from => $from, to => $to);
276  
277 }
278  
279 0 return $self;
280  
281 }
282  
283 sub process_profiled_files {
284 1 ▶ my $self = shift;
Subroutine process_profiled_files: called CC=4 SCAR=14.1
Pod undocumented
285  
286 1 my $result;
287 1 my $dir = catfile('blib', 'profile.d');
288 1 my $files = $self->find_profiled_files;
289  
290 1 ▶ mkdir $dir unless (-e $dir);
Branch: 1 branch
BranchTrueFalseTotal
unless -e $dir 0 1 1
291  
292 1 ▶ while (my ($from, $to) = each %$files) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %$files) 2 1 3
293  
294 2 $to = catfile('blib', $to);
295 2 ▶ $result = $self->copy_if_modified(from => $from, to => $to) or next;
Branch: 1 branch
BranchTrueFalseTotal
$result = $self->copy_if_modified("from", $from, "to", $to) or next 2 0 2
296 0 $self->make_executable($result);
297  
298 }
299  
300 1 return $self;
301  
302 }
303  
304 sub process_logrotated_files {
305 0 ▶ my $self = shift;
Subroutine process_logrotated_files: not called CC=3 SCAR=24.8
Pod undocumented
306  
307 0 my $result;
308 0 my $dir = catfile('blib', 'logrotate.d');
309 0 my $files = $self->find_logrotated_files;
310  
311 0 ▶ mkdir $dir unless (-e $dir);
Branch: 1 branch
BranchTrueFalseTotal
unless -e $dir 0 0 0
312  
313 0 ▶ while (my ($from, $to) = each %$files) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %$files) 0 0 0
314  
315 0 $to = catfile('blib', $to);
316 0 $result = $self->copy_if_modified(from => $from, to => $to);
317  
318 }
319  
320 0 return $self;
321  
322 }
323  
324 1 ▶ sub find_etc_files { shift->find_all_files_no_svn('etc'); }
Subroutine find_etc_files: called CC=1 SCAR=0.0
Pod undocumented
325 0 ▶ sub find_sbin_files { shift->find_all_files_no_svn('sbin'); }
Subroutine find_sbin_files: not called CC=1 SCAR=6.9
Pod undocumented
326 0 ▶ sub find_initd_files { shift->find_all_files_no_svn('init.d'); }
Subroutine find_initd_files: not called CC=1 SCAR=6.9
Pod undocumented
327 0 ▶ sub find_sysconf_files { shift->find_all_files_no_svn('sysconfig'); }
Subroutine find_sysconf_files: not called CC=1 SCAR=6.9
Pod undocumented
328 1 ▶ sub find_profiled_files { shift->find_all_files_no_svn('profile.d'); }
Subroutine find_profiled_files: called CC=1 SCAR=0.0
Pod undocumented
329 0 ▶ sub find_logrotated_files { shift->find_all_files_no_svn('logrotate.d'); }
Subroutine find_logrotated_files: not called CC=1 SCAR=6.9
Pod undocumented
330  
331 sub find_all_files_no_svn {
332 2 ▶ my ($self, $dir) = @_;
Subroutine find_all_files_no_svn: called CC=1 SCAR=0.1
Pod undocumented
333  
334 my $sub = sub {
335 5 ▶ return 1 if (($File::Find::dir !~ /SVN/i or
Subroutine __ANON__: called CC=4 SCAR=15.2
Branch: 1 branch
BranchTrueFalseTotal
if not $File::Find::dir =~ /SVN/i && $File::Find::Dir =~ /GIT/i and -f $File::Find::name 3 2 5
Condition50%3/6
not $File::Find::dir =~ /SVN/i && $File::Find::Dir =~ /GIT/i and -f $File::Find::name
!ll&&!rl&&r
023
$File::Find::dir =~ /SVN/i && $File::Find::Dir =~ /GIT/i
!ll&&!rl&&r
500
MC/DC33%1/3
not $File::Find::dir =~ /SVN/i && $File::Find::Dir =~ /GIT/i and -f $File::Find::name
$File::Find::dir =~ /SVN/i $File::Find::Dir =~ /GIT/i -f $File::Find::name
Truth table40%2/5
not(A && B) and C
A= $File::Find::dir =~ /SVN/iB= $File::Find::Dir =~ /GIT/iC= -f $File::Find::name
ABCresult
11X0
0X00
1000
0X11
1011
336 $File::Find::Dir !~ /GIT/i) and
337 -f $File::Find::name);
338 2 };
339  
340 2 return { map {$_, $_} @{ $self->rscan_dir($dir, $sub) } };
341  
342 }
343  
344 # fix for when scm files are in the script directory
345  
346 sub _files_in {
347 1 ▶ my ($self, $dir) = @_;
Subroutine _files_in: called CC=7 SCAR=20.1
348 1 ▶ return unless -d $dir;
Branch: 1 branch
BranchTrueFalseTotal
unless -d $dir 0 1 1
349  
350 1 local *DH;
351 1 ▶ opendir DH, $dir or die "Can't read directory $dir: $!";
Branch: 1 branch
BranchTrueFalseTotal
opendir DH, $dir or die "Can't read directory ${dir}: $!" 0 1 1
352  
353 1 my @files;
354 1 ▶ while (defined (my $file = readdir DH)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $file = readdir DH)) 3 1 4
355 3 my $full_path = File::Spec->catfile($dir, $file);
356 3 ▶ next if -d $full_path;
Branch: 1 branch
BranchTrueFalseTotal
if -d $full_path 2 1 3
357 1 ▶ next if (($file =~ /SVN/i) or ($file =~ /GIT/i));
Branch: 1 branch
BranchTrueFalseTotal
if $file =~ /SVN/i or $file =~ /GIT/i 0 1 1
Condition33%1/3
$file =~ /SVN/i or $file =~ /GIT/i
l!l&&r!l&&!r
001
MC/DC0%0/2
$file =~ /SVN/i or $file =~ /GIT/i
$file =~ /SVN/i $file =~ /GIT/i
Truth table33%1/3
A or B
A= $file =~ /SVN/iB= $file =~ /GIT/i
ABresult
1X1
011
000
358 1 push @files, $full_path;
359 }
360 1 return @files;
361 }
362  
363 1 1;
« blib/lib/XAS/Lib/Process.pm ↑ Summary blib/lib/XAS/Lib/Batch/Interface/Torque.pm »