| 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? "
MC/DC0%0/1
$question ||= "Your answer? "
$question
Truth table0%0/2
A
A= $question
| |||||||||||||||||||||||||||||||||||||||||||
| 25 | 0 | my $val = undef; | |||||||||||||||||||||||||||||||||||||||||
| 26 | 0 | ▶ | until (defined $val){ | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||||||||
| 52 | 0 | print "Sorry, you're missing the application '$app'.\n"; | |||||||||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||||||||||
| 54 | 0 | ▶ | if ( File::Which::which('yum') ){ | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||||||||||
| 56 | 0 | ▶ | yn("It seems that you have 'yum'. Would you like me try to install '$app' via yum?") | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
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()
say("In that case you should find '${app}' and install it.\n") and bad()
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()
| |||||||||||||||||||||||||||||||||||||||||||
| 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
Condition0%0/6
File::Which::which($app) || say("Still can't find path to '${app}'. Error.\n") && bad()
say("Still can't find path to '${app}'. Error.\n") and bad()
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()
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 76 | 0 | my $txt = <FILE>; | |||||||||||||||||||||||||||||||||||||||||
| 77 | 0 | close FILE; | |||||||||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||||||||
| 79 | 0 | ▶ | $txt=~/PREREQ_PM\s*=>\s*({[^\}]+})/s or return; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 106 | 0 | ▶ | ok(1,"Have module '$mod'") and next MODULE; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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
Condition0%0/2
@missing and scalar @missing
MC/DC0%0/1
@missing and scalar @missing
@missing
Truth table0%0/2
A
A= @missing
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 148 | 0 | ▶ | ok( -e $abs,"have conf file '$abs'") or bad; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||||||||||||||||
| 157 | 0 | my $mysqld = '/etc/init.d/mysqld'; | |||||||||||||||||||||||||||||||||||||||||
| 158 | 0 | ▶ | if ( -e $mysqld ){ | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 159 | 0 | my $status = `$mysqld status`; | |||||||||||||||||||||||||||||||||||||||||
| 160 | 0 | ▶ | ok( $status=~/is running/,"$mysqld status, is running") or bad; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 161 | } | ||||||||||||||||||||||||||||||||||||||||||
| 162 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 163 | 0 | ok( 1, "no '$mysqld'"); | |||||||||||||||||||||||||||||||||||||||||
| 164 | } | ||||||||||||||||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||||||||||||||||
| 167 | } | ||||||||||||||||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||||||||||||||||
| 169 | 2 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||||||||||||||||
| 171 | __END__ | ||||||||||||||||||||||||||||||||||||||||||