lib/LEOCHARRE/Checksetup.pm

filter: Statementstmt 23.2% 20 / 86 Branchbran 0.0% 0 / 46 Conditioncond 0.0% 0 / 16 MC/DCmcdc 0.0% 0 / 8 Subroutinesub 27.7% 5 / 18 Podpod 70.0% 7 / 10 totaltotal 17.3% 32 / 184 CC 31 SCAR 36.5
CC
31
Cov
14%
ok_perldeps
110.0
_require_app
56.0
yn
30.0
CRAP 38.6
↑ Summary
1 package LEOCHARRE::Checksetup;
2 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 2 ▶use Exporter;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use Test::Simple '';
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use vars qw(@ISA %EXPORT_TAGS @EXPORT_OK $VERSION);
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 @ISA = qw/Exporter/;
8 2 @EXPORT_OK = qw(bad good ok_app ok_conf ok_mysql_local_server ok_os ok_perldeps ok_root say yn);
9 2 %EXPORT_TAGS = ( all => \@EXPORT_OK );
10 2 $VERSION = sprintf "%d.%02d", q$Revision: 1.3 $ =~ /(\d+)/g;
11  
12  
13  
14 sub bad;
15 sub good;
16 sub say;
17  
18  
19  
20  
21  
22  
23 0 ▶sub yn {
Subroutine yn: not called CC=5 SCAR=34.0
Pod documented
24 0 ▶ my $question = shift; $question ||='Your answer? ';
Condition0%0/2
$question ||= "Your answer? "
l!l
00
MC/DC0%0/1
$question ||= "Your answer? "
$question
Truth table0%0/2
A
A= $question
Aresult
11
00
25 0 my $val = undef;
26 0 ▶ until (defined $val){
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $val) 0 0 0
27 0 print "$question (y/n): ";
28 0 $val = <STDIN>;
29 0 chomp $val;
30 0 ▶ if ($val eq 'y'){ $val = 1; }
Branch: 2 branches
BranchTrueFalseTotal
if ($val eq 'y') { } 0 0 0
elsif ($val eq 'n') { } 0 0 0
31 0 elsif ($val eq 'n'){ $val = 0;}
32 0 else { $val = undef; }
33 }
34 0 return $val;
35 }
36  
37  
38  
39  
40  
41 0 ▶sub ok_app {
Subroutine ok_app: not called CC=2 SCAR=17.9
Pod documented
42 0 my $what = shift;
43 0 ▶ ok( _require_app($what), "Found '$what' installed.") or bad;
Branch: 1 branch
BranchTrueFalseTotal
&ok(scalar _require_app($what), "Found '${what}' installed.") or bad() 0 0 0
44 }
45  
46 0 ▶sub _require_app {
Subroutine _require_app: not called CC=7 SCAR=40.3
47 0 my $app = shift;
48  
49 0 require File::Which;
50 0 ▶ File::Which::which($app) and return 1;
Branch: 1 branch
BranchTrueFalseTotal
File::Which::which($app) and return 1 0 0 0
51
52 0 print "Sorry, you're missing the application '$app'.\n";
53  
54 0 ▶ if ( File::Which::which('yum') ){
Branch: 1 branch
BranchTrueFalseTotal
if (File::Which::which("yum")) 0 0 0
55
56 0 ▶ yn("It seems that you have 'yum'. Would you like me try to install '$app' via yum?")
Branch: 1 branch
BranchTrueFalseTotal
yn("It seems that you have 'yum'. Would you like me try to install '${app}' via yum?") or say("In that case you should find '${app}' and install it.\n") and bad() 0 0 0
Condition0%0/6
yn("It seems that you have 'yum'. Would you like me try to install '${app}' via yum?") || say("In that case you should find '${app}' and install it.\n") && bad()
l!l&&r!l&&!r
000
say("In that case you should find '${app}' and install it.\n") and bad()
!ll&&!rl&&r
000
MC/DC0%0/3
yn("It seems that you have 'yum'. Would you like me try to install '${app}' via yum?") || say("In that case you should find '${app}' and install it.\n") && bad()
yn("It seems that you have 'yum'. Would you like me try to install '${app}' via yum?") say("In that case you should find '${app}' and install it.\n") bad()
Truth table0%0/4
A || B and C
A= yn("It seems that you have 'yum'. Would you like me try to install '${app}' via yum?")B= say("In that case you should find '${app}' and install it.\n")C= bad()
ABCresult
1XX1
0111
00X0
0100
57 or say "In that case you should find '$app' and install it.\n"
58 and bad;
59  
60 0 ok_root();
61  
62 0 system('yum','-y','install',$app);
63  
64 0 ▶ File::Which::which($app) or say "Still can't find path to '$app'. Error.\n"
Branch: 1 branch
BranchTrueFalseTotal
File::Which::which($app) or say("Still can't find path to '${app}'. Error.\n") and bad() 0 0 0
Condition0%0/6
File::Which::which($app) || say("Still can't find path to '${app}'. Error.\n") && bad()
l!l&&r!l&&!r
000
say("Still can't find path to '${app}'. Error.\n") and bad()
!ll&&!rl&&r
000
MC/DC0%0/3
File::Which::which($app) || say("Still can't find path to '${app}'. Error.\n") && bad()
File::Which::which($app) say("Still can't find path to '${app}'. Error.\n") bad()
Truth table0%0/4
A || B and C
A= File::Which::which($app)B= say("Still can't find path to '${app}'. Error.\n")C= bad()
ABCresult
1XX1
0111
00X0
0100
65 and bad;
66  
67 0 return 1;
68 }
69 0 bad;
70 }
71  
72 #use Smart::Comments '###';
73 0 ▶sub _makefile_deps {
Subroutine _makefile_deps: not called CC=3 SCAR=24.8
74 0 local $/;
75 0 ▶ open(FILE,'<','./Makefile.PL') or die($!);
Branch: 1 branch
BranchTrueFalseTotal
open FILE, "<", "./Makefile.PL" or die $! 0 0 0
76 0 my $txt = <FILE>;
77 0 close FILE;
78
79 0 ▶ $txt=~/PREREQ_PM\s*=>\s*({[^\}]+})/s or return;
Branch: 1 branch
BranchTrueFalseTotal
$txt =~ /PREREQ_PM\s*=>\s*({[^\}]+})/s or return 0 0 0
80  
81 ### $txt
82 0 my $href = eval "$1";
83  
84 ### $href
85 0 my @m = keys %$href;
86 0 return @m;
87  
88 }
89  
90  
91  
92 0 ▶sub say { print STDERR "@_" }
Subroutine say: not called CC=1 SCAR=6.9
Pod undocumented
93 0 ▶sub bad { say("\nCHECK FAILED.\n"); exit 1 }
Subroutine bad: not called CC=1 SCAR=6.9
Pod documented
94 0 ▶sub good { say("\nCHECK PASSED.\n"); exit }
Subroutine good: not called CC=1 SCAR=6.9
Pod documented
95  
96 # MODULE CHECKS
97 0 ▶sub ok_perldeps {
Subroutine ok_perldeps: not called CC=10 SCAR=47.0
Pod undocumented
98 0 ▶ sub _havemod { my $name = shift; ( eval "require $name;" ) ? 1 : 0 }
Subroutine _havemod: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
eval "require $name;" ? : 0 0 0
99  
100  
101 0 my @mods = _makefile_deps();
102 0 my @missing;
103 0 MODULE: for my $mod ( @mods ){
104  
105 0 ▶ if (_havemod($mod)){
Branch: 1 branch
BranchTrueFalseTotal
if (_havemod($mod)) { } 0 0 0
106 0 ▶ ok(1,"Have module '$mod'") and next MODULE;
Branch: 1 branch
BranchTrueFalseTotal
&ok(1, "Have module '${mod}'") and next MODULE 0 0 0
107 }
108  
109  
110  
111 else {
112 0 push @missing, $mod;
113 }
114  
115 }
116  
117 0 ▶ if (@missing and scalar @missing){
Branch: 1 branch
BranchTrueFalseTotal
if (@missing and scalar @missing) 0 0 0
Condition0%0/2
@missing and scalar @missing
!ll
00
MC/DC0%0/1
@missing and scalar @missing
@missing
Truth table0%0/2
A
A= @missing
Aresult
00
11
118 0 say("Missing modules:\n");
119 0 say("\t$_\n") for @missing;
120 0 ▶ yn("Want me to call cpan to install these?") or bad;
Branch: 1 branch
BranchTrueFalseTotal
yn("Want me to call cpan to install these?") or bad() 0 0 0
121  
122 0 system("cpan @missing");
123  
124 0 for my $mod (@missing){
125 0 ▶ ok( _havemod($mod),"Found module: $mod.") or bad;
Branch: 1 branch
BranchTrueFalseTotal
&ok(scalar _havemod($mod), "Found module: $mod.") or bad() 0 0 0
126 }
127  
128 }
129
130 } # END MODULE CHECKS
131  
132  
133 0 ▶sub ok_os {
Subroutine ok_os: not called CC=2 SCAR=17.9
Pod documented
134  
135 0 ▶ ok( $^O=~/linux/, 'using Linux') or bad;
Branch: 1 branch
BranchTrueFalseTotal
&ok(scalar $^O =~ /linux/, "using Linux") or bad() 0 0 0
136  
137 }
138  
139 0 ▶sub ok_root {
Subroutine ok_root: not called CC=2 SCAR=17.9
Pod documented
140 0 my $who = `whoami`;
141 0 ▶ ok( $who=~/\broot\b/,'installing as root') or bad();
Branch: 1 branch
BranchTrueFalseTotal
&ok(scalar $who =~ /\broot\b/, "installing as root") or bad() 0 0 0
142 }
143  
144  
145 0 ▶sub ok_conf {
Subroutine ok_conf: not called CC=3 SCAR=24.8
Pod undocumented
146 0 my $abs = shift;
147 0 ▶ defined $abs or croak('missing abs conf arg');
Branch: 1 branch
BranchTrueFalseTotal
defined $abs or croak("missing abs conf arg") 0 0 0
148 0 ▶ ok( -e $abs,"have conf file '$abs'") or bad;
Branch: 1 branch
BranchTrueFalseTotal
&ok(-e $abs, "have conf file '${abs}'") or bad() 0 0 0
149 }
150  
151 0 ▶sub ok_mysql_local_server {
Subroutine ok_mysql_local_server: not called CC=4 SCAR=30.0
Pod documented
152  
153 0 require File::Which;
154 0 ▶ ok( File::Which::which('mysql'),'found mysql cli') or bad;
Branch: 1 branch
BranchTrueFalseTotal
&ok(scalar File::Which::which("mysql"), "found mysql cli") or bad() 0 0 0
155  
156  
157 0 my $mysqld = '/etc/init.d/mysqld';
158 0 ▶ if ( -e $mysqld ){
Branch: 1 branch
BranchTrueFalseTotal
if (-e $mysqld) { } 0 0 0
159 0 my $status = `$mysqld status`;
160 0 ▶ ok( $status=~/is running/,"$mysqld status, is running") or bad;
Branch: 1 branch
BranchTrueFalseTotal
&ok(scalar $status =~ /is running/, "$mysqld status, is running") or bad() 0 0 0
161 }
162 else {
163 0 ok( 1, "no '$mysqld'");
164 }
165  
166  
167 }
168  
169 2 1;
170  
171 __END__
↑ Summary