blib/lib/Test/Smoke/Util/FindHelpers.pm

filter: Statementstmt 31.5% 30 / 95 Branchbran 4.1% 2 / 48 Conditioncond 0.0% 0 / 12 MC/DCmcdc 0.0% 0 / 8 Subroutinesub 50.0% 7 / 14 Podpod 100% 9 / 9 totaltotal 25.8% 48 / 186 CC 33 SCAR 35.8
CC
33
Cov
21%
get_avail_w32compilers
90.0
get_avail_tar
56.0
get_avail_mailers
30.0
CRAP 35.9
« blib/lib/Test/Smoke/App/ConfigSmoke/MakeOptions.pm ↑ Summary blib/lib/Test/Smoke/App/ConfigSmoke/Mail.pm »
1 package Test::Smoke::Util::FindHelpers;
2 5 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 5 our $VERSION = '0.001';
6  
7 =head1 NAME
8  
9 Test::Smoke::Util::FindHelpers - Functions to help find Helpers (modules/bins)
10  
11 =head1 SYNOPSIS
12  
13 use Test::Smoke::Util::FindHelpers ':all';
14  
15 =cut
16  
17 5 ▶use Config;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 5 ▶use Test::Smoke::Util 'whereis';
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20 =head1 EXPORT_OK/EXPORT_TAGS
21  
22 has_module whereis
23 get_avail_tar get_avail_patchers
24 get_avail_posters get_avail_sync get_avail_mailers
25 get_avail_w32compilers
26 get_avail_vms_make
27  
28 :all
29 =cut
30  
31 5 ▶use Exporter 'import';
Subroutine BEGIN: called CC=1 SCAR=0.0
32 5 our @EXPORT_OK = qw/
33 has_module whereis
34 get_avail_tar get_avail_patchers
35 get_avail_posters get_avail_sync get_avail_mailers
36 get_avail_w32compilers
37 get_avail_vms_make
38 /;
39 5 our %EXPORT_TAGS = (
40 all => [ @EXPORT_OK ],
41  
42 );
43  
44 =head1 DESCRIPTION
45  
46 =head2 has_module($module)
47  
48 Retuns true if the named module could be C<require>d.
49  
50 =cut
51  
52 10 ▶sub has_module {
Subroutine has_module: called CC=1 SCAR=0.0
Pod documented
53 10 my ($module) = @_;
54 10 { local $^W; eval "require $module"; }
55 10 return !$@;
56 }
57  
58 =head2 get_avail_patchers
59  
60 Returns a list of available patch programs (gpatch npatch patch)
61  
62 =cut
63  
64 0 ▶sub get_avail_patchers {
Subroutine get_avail_patchers: not called CC=4 SCAR=30.0
Pod documented
65 0 my @patchers;
66  
67 0 foreach my $patcher (qw( gpatch npatch patch )) {
68 0 ▶ if (my $patch_bin = whereis($patcher)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $patch_bin = whereis($patcher)) 0 0 0
69 0 my $version = `$patch_bin -version`;
70 0 ▶ $? or push @patchers, $patch_bin;
Branch: 1 branch
BranchTrueFalseTotal
$? or push @patchers, $patch_bin 0 0 0
71 }
72 }
73 0 return @patchers;
74 }
75  
76 =head2 get_avail_posters
77  
78 Return a list of available modules/programs that can be used to HTTP/POST a message.
79 (HTTP::Tiny, LWP::UserAgent, curl)
80  
81 =cut
82  
83 2 ▶sub get_avail_posters {
Subroutine get_avail_posters: called CC=4 SCAR=14.2
Pod documented
84 2 my @posters;
85  
86 2 my @modules = qw/HTTP::Tiny LWP::UserAgent/;
87 2 for my $module (@modules) {
88 4 ▶ push @posters, $module if has_module($module);
Branch: 1 branch
BranchTrueFalseTotal
if has_module($module) 4 0 4
89 }
90 2 ▶ push @posters, 'curl', if whereis('curl');
Branch: 1 branch
BranchTrueFalseTotal
if whereis("curl") 2 0 2
91  
92 2 return @posters;
93 }
94  
95 =head2 get_avail_sync
96  
97 Returns a list of available syncer modules/programs (git, rsync)
98  
99 =cut
100  
101 0 ▶sub get_avail_sync {
Subroutine get_avail_sync: not called CC=3 SCAR=24.8
Pod documented
102 0 my @synctype = qw(copy hardlink snapshot);
103  
104 0 ▶ unshift @synctype, 'rsync' if whereis('rsync');
Branch: 1 branch
BranchTrueFalseTotal
if whereis("rsync") 0 0 0
105  
106 0 ▶ unshift @synctype, 'git' if whereis('git');
Branch: 1 branch
BranchTrueFalseTotal
if whereis("git") 0 0 0
107  
108 0 return @synctype;
109 }
110  
111 =head2 get_avail_tar
112  
113 Returns a list of available untar/ungzip modules/programs (Archive::Tar/...Zlib, tar/gzip)
114  
115 =cut
116  
117 0 ▶sub get_avail_tar {
Subroutine get_avail_tar: not called CC=7 SCAR=40.3
Pod documented
118 0 my $use_modules = 0;
119  
120 0 my $has_archive_tar = has_module('Archive::Tar');
121 0 ▶ if ($has_archive_tar) {
Branch: 1 branch
BranchTrueFalseTotal
if ($has_archive_tar) 0 0 0
122 0 ▶ if ( eval "$Archive::Tar::VERSION" >= 0.99 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (eval "$Archive::Tar::VERSION" >= 0.99) { } 0 0 0
123 0 $use_modules = has_module('IO::Zlib');
124 } else {
125 0 $use_modules = has_module('Compress::Zlib');
126 }
127 }
128  
129 0 my $fmt = tar_fmt();
130  
131 0 ▶ return $fmt && $use_modules
Branch: 3 branches
BranchTrueFalseTotal
$fmt && $use_modules ? : 0 0 0
$fmt ? : 0 0 0
$use_modules ? : 0 0 0
Condition0%0/3
$fmt and $use_modules
!ll&&!rl&&r
000
MC/DC0%0/2
$fmt and $use_modules
$fmt $use_modules
Truth table0%0/3
A and B
A= $fmtB= $use_modules
ABresult
0X0
100
111
132 ? ( $fmt, 'Archive::Tar' )
133 : $fmt ? ( $fmt ) : $use_modules ? ( 'Archive::Tar' ) : ();
134 }
135  
136 =head2 tar_fmt
137  
138 Returns the format with wich to gunzip and untar.
139 (gzip -cd %s | tar -xf -) or (tar -xzf %s)
140  
141 =cut
142  
143 0 ▶sub tar_fmt {
Subroutine tar_fmt: not called CC=4 SCAR=30.0
Pod documented
144 0 my $tar = whereis( 'tar' );
145 0 my $gzip = whereis( 'gzip' );
146  
147 0 ▶ return $tar && $gzip
Branch: 2 branches
BranchTrueFalseTotal
$tar && $gzip ? : 0 0 0
$tar ? : 0 0 0
Condition0%0/3
$tar and $gzip
!ll&&!rl&&r
000
MC/DC0%0/2
$tar and $gzip
$tar $gzip
Truth table0%0/3
A and B
A= $tarB= $gzip
ABresult
0X0
100
111
148 ? "$gzip -cd %s | $tar -xf -"
149 : $tar ? "tar -xzf %s" : "";
150 }
151  
152 =head2 get_avail_mailers
153  
154 Returns a list available mail modules/programs.
155  
156 =cut
157  
158 0 ▶sub get_avail_mailers {
Subroutine get_avail_mailers: not called CC=5 SCAR=34.0
Pod documented
159 0 my %map;
160  
161 0 for my $mailer (qw/mail mailx sendmail sendemail/) {
162 0 local $ENV{PATH} = "$ENV{PATH}$Config{path_sep}/usr/sbin";
163 0 ▶ if (my $mailer_bin = whereis($mailer)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $mailer_bin = whereis($mailer)) 0 0 0
164 0 $map{$mailer} = $mailer_bin;
165 }
166 }
167  
168 0 for my $module (qw/Mail::Sendmail MIME::Lite/) {
169 0 ▶ $map{$module} = $module if has_module($module);
Branch: 1 branch
BranchTrueFalseTotal
if has_module($module) 0 0 0
170 }
171 0 return %map;
172 }
173  
174 =head2 get_avail_w32compilers
175  
176 Returns a list of compilers found (Win32 specific)
177  
178 =cut
179  
180 0 ▶sub get_avail_w32compilers {
Subroutine get_avail_w32compilers: not called CC=9 SCAR=45.0
Pod documented
181  
182 0 my %map = (
183 MSVC => { ccname => 'cl', maker => [ 'nmake' ] },
184 BCC => { ccname => 'bcc32', maker => [ 'dmake' ] },
185 GCC => { ccname => 'gcc', maker => [ 'dmake', 'gmake' ] },
186 );
187  
188 0 my $CC = 'MSVC';
189 0 ▶ if ( $map{ $CC }->{ccbin} = whereis( $map{ $CC }->{ccname} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($map{$CC}{"ccbin"} = whereis($map{$CC}{"ccname"})) 0 0 0
190 # No, cl doesn't support --version (One can but try)
191 0 my $output =`$map{ $CC }->{ccbin} --version 2>&1`;
192 0 ▶ my $ccvers = $output =~ /^.*Version\s+([\d.]+)/ ? $1 : '?';
Branch: 1 branch
BranchTrueFalseTotal
$output =~ /^.*Version\s+([\d.]+)/ ? : 0 0 0
193 0 $map{ $CC }->{ccversarg} = "ccversion=$ccvers";
194 0 ▶ my $mainvers = $ccvers =~ /^(\d+)/ ? $1 : 1;
Branch: 1 branch
BranchTrueFalseTotal
$ccvers =~ /^(\d+)/ ? : 0 0 0
195 0 ▶ $map{ $CC }->{CCTYPE} = $mainvers < 12 ? 'MSVC' : 'MSVC60';
Branch: 1 branch
BranchTrueFalseTotal
$mainvers < 12 ? : 0 0 0
196 }
197  
198 0 $CC = 'BCC';
199 0 ▶ if ( $map{ $CC }->{ccbin} = whereis( $map{ $CC }->{ccname} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($map{$CC}{"ccbin"} = whereis($map{$CC}{"ccname"})) 0 0 0
200 # No, bcc32 doesn't support --version (One can but try)
201 0 my $output = `$map{ $CC }->{ccbin} --version 2>&1`;
202 0 ▶ my $ccvers = $output =~ /([\d.]+)/ ? $1 : '?';
Branch: 1 branch
BranchTrueFalseTotal
$output =~ /([\d.]+)/ ? : 0 0 0
203 0 $map{ $CC }->{ccversarg} = "ccversion=$ccvers";
204 0 $map{ $CC }->{CCTYPE} = 'BORLAND';
205 }
206  
207 0 $CC = 'GCC';
208 0 ▶ if ( $map{ $CC }->{ccbin} = whereis( $map{ $CC }->{ccname} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($map{$CC}{"ccbin"} = whereis($map{$CC}{"ccname"})) 0 0 0
209 0 local *STDERR;
210 0 open STDERR, ">&STDOUT"; #do we need an error?
211 0 select( (select( STDERR ), $|++ )[0] );
212 0 my $output = `$map{ $CC }->{ccbin} --version`;
213 0 ▶ my $ccvers = $output =~ /(\d+.*)/ ? $1 : '?';
Branch: 1 branch
BranchTrueFalseTotal
$output =~ /(\d+.*)/ ? : 0 0 0
214 0 $ccvers =~ s/\s+copyright.*//i;
215 0 $map{ $CC }->{ccversarg} = "gccversion=$ccvers";
216 0 $map{ $CC }->{CCTYPE} = $CC
217 }
218  
219 return map {
220 0 ( $map{ $_ }->{CCTYPE} => $map{ $_ } )
221 0 } grep length $map{ $_ }->{ccbin} => keys %map;
222 }
223  
224 =head2 get_avail_vms_make
225  
226 Return a list of "make" programs installed on the VMS system.
227  
228 =cut
229  
230 0 ▶sub get_avail_vms_make {
Subroutine get_avail_vms_make: not called CC=4 SCAR=30.0
Pod documented
231  
232 0 ▶ return map +( $_ => undef ) => grep defined $_ && length( $_ )
Condition0%0/3
defined $_ && length $_
!ll&&!rl&&r
000
MC/DC0%0/2
defined $_ && length $_
defined $_ length $_
Truth table0%0/3
A && B
A= defined $_B= length $_
ABresult
0X0
100
111
233 => map whereis( $_ ) => qw( MMK MMS );
234  
235 0 local *QXERR; open *QXERR, ">&STDERR"; close STDERR;
236  
237 my %makers = map {
238 0 my $maker = $_;
239 0 ▶ map +( $maker => /V([\d.-]+)/ ? $1 : '' )
Branch: 1 branch
BranchTrueFalseTotal
/V([\d.-]+)/ ? : 0 0 0
Condition0%0/3
/\b$maker\b/ && /V[\d.-]+/
!ll&&!rl&&r
000
MC/DC0%0/2
/\b$maker\b/ && /V[\d.-]+/
/\b$maker\b/ /V[\d.-]+/
Truth table0%0/3
A && B
A= /\b$maker\b/B= /V[\d.-]+/
ABresult
0X0
100
111
240 => grep /\b$maker\b/ && /V[\d.-]+/ => qx($maker/IDENT)
241 } qw( MMK MMS );
242  
243 0 open STDERR, ">&QXERR"; close QXERR;
244  
245 0 return %makers;
246 }
247  
248 5 1;
249  
250 =head1 COPYRIGHT
251  
252 (c) MMII - MMXV, The Test-Smoke Team <abeltje@cpan.org>
253  
254 See L<Test::Smoke> for full acknowlegements.
255  
256 =cut
« blib/lib/Test/Smoke/App/ConfigSmoke/MakeOptions.pm ↑ Summary blib/lib/Test/Smoke/App/ConfigSmoke/Mail.pm »