| 1 | package LEOCHARRE::CLI; | ||||||||||||||||||||||||||||||||
| 2 | 4 | ▶ | use strict; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 3 | 4 | ▶ | use Carp; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 4 | 4 | ▶ | use Cwd; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 5 | 4 | ▶ | use vars qw($VERSION); | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 6 | 4 | $VERSION = sprintf "%d.%02d", q$Revision: 1.19 $ =~ /(\d+)/g; | |||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||
| 8 | 4 | $main::DEBUG = 0; | |||||||||||||||||||||||||||||||
| 9 | 4 | $main::USAGE = 0; | |||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||
| 11 | 2 | ▶ | sub main::DEBUG : lvalue { | ||||||||||||||||||||||||||||||
|
Subroutine
DEBUG: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 12 | 2 | $main::DEBUG; | |||||||||||||||||||||||||||||||
| 13 | } | ||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||
| 15 | 1 | ▶ | sub main::debug { | ||||||||||||||||||||||||||||||
|
Subroutine
debug: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||||||
| 16 | 1 | ▶ | $main::DEBUG or return 1; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 17 | 1 | my $msg = shift; | |||||||||||||||||||||||||||||||
| 18 | 1 | print STDERR " $0, $msg\n"; | |||||||||||||||||||||||||||||||
| 19 | 1 | return 1; | |||||||||||||||||||||||||||||||
| 20 | } | ||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||
| 32 | # BEGIN USER | ||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||
| 34 | 4 | ▶ | sub main::whoami { | ||||||||||||||||||||||||||||||
|
Subroutine
whoami: called CC=4 SCAR=14.8
| |||||||||||||||||||||||||||||||||
| 35 | 4 | ▶ | unless (defined $::WHOAMI){ | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 36 | 2 | require File::Which; | |||||||||||||||||||||||||||||||
| 37 | 2 | ▶ | if (my $wb = File::Which::which('whoami')){ | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 38 | 2 | my $whoami = `$wb`; | |||||||||||||||||||||||||||||||
| 39 | 2 | chomp $whoami; | |||||||||||||||||||||||||||||||
| 40 | 2 | $::WHOAMI = $whoami; | |||||||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||||||
| 42 | else { | ||||||||||||||||||||||||||||||||
| 43 | 0 | warn("whoami bin path not found."); | |||||||||||||||||||||||||||||||
| 44 | 0 | $::WHOAMI = 0; | |||||||||||||||||||||||||||||||
| 45 | 0 | return; | |||||||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||||||
| 48 | 4 | ▶ | $::WHOAMI or return; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||
| 50 | 4 | return $::WHOAMI; | |||||||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||
| 53 | 0 | ▶ | sub main::force_root { | ||||||||||||||||||||||||||||||
|
Subroutine
force_root: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||
| 54 | 0 | ▶ | main::running_as_root() or print "$0, only root can use this." and exit; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/5
main::running_as_root() || print("$0, only root can use this.") && exit
print "$0, only root can use this." and exit
MC/DC0%0/2
main::running_as_root() || print("$0, only root can use this.") && exit
main::running_as_root()
print "$0, only root can use this."
Truth table0%0/3
A || B
A= main::running_as_root()B= print "$0, only root can use this."
| |||||||||||||||||||||||||||||||||
| 55 | 0 | return 1; | |||||||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||
| 58 | 1 | ▶ | sub main::running_as_root { | ||||||||||||||||||||||||||||||
|
Subroutine
running_as_root: called CC=3 SCAR=13.1
| |||||||||||||||||||||||||||||||||
| 59 | 1 | ▶ | my $whoami = main::whoami() or return 0; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 60 | 1 | ▶ | $whoami eq 'root' or return 0; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 61 | 0 | return 1; | |||||||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||
| 64 | 0 | ▶ | sub main::get_uid { | ||||||||||||||||||||||||||||||
|
Subroutine
get_uid: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||
| 65 | 0 | my $name = shift; | |||||||||||||||||||||||||||||||
| 66 | 0 | ▶ | main::user_exists($name) or return; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||
| 68 | 0 | require Linux::usermod; | |||||||||||||||||||||||||||||||
| 69 | 0 | my $user = Linux::usermod->new($name); | |||||||||||||||||||||||||||||||
| 70 | 0 | my $id = $user->get('uid'); | |||||||||||||||||||||||||||||||
| 71 | 0 | ▶ | $id=~/^\d+$/ or return; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 72 | 0 | return $id; | |||||||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||
| 75 | 0 | ▶ | sub main::user_exists { | ||||||||||||||||||||||||||||||
|
Subroutine
user_exists: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||
| 76 | 0 | my $name = shift; | |||||||||||||||||||||||||||||||
| 77 | 0 | require Linux::usermod; | |||||||||||||||||||||||||||||||
| 78 | 0 | my %u = Linux::usermod->users; | |||||||||||||||||||||||||||||||
| 79 | 0 | ▶ | $u{$name} or return 0; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 80 | 0 | return 1; | |||||||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||
| 83 | 0 | ▶ | sub main::get_gid { | ||||||||||||||||||||||||||||||
|
Subroutine
get_gid: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||
| 84 | 0 | my $name = shift; | |||||||||||||||||||||||||||||||
| 85 | 0 | ▶ | main::user_exists($name) or return; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 86 | 0 | require Linux::usermod; | |||||||||||||||||||||||||||||||
| 87 | 0 | my $g = Linux::usermod->new($name,1); | |||||||||||||||||||||||||||||||
| 88 | 0 | my $id = $g->get('gid'); | |||||||||||||||||||||||||||||||
| 89 | 0 | ▶ | $id=~/^\d+$/ or return; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 90 | 0 | return $id; | |||||||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||
| 93 | # END USER | ||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||
| 100 | 0 | ▶ | sub main::get_mode { | ||||||||||||||||||||||||||||||
|
Subroutine
get_mode: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||
| 101 | 0 | my $abs = shift; | |||||||||||||||||||||||||||||||
| 102 | 0 | require File::chmod; | |||||||||||||||||||||||||||||||
| 103 | 0 | ▶ | my $mod = File::chmod::getmod($abs) or return; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 104 | 0 | return $mod; | |||||||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||
| 116 | # BEGIN GOPTS AND ARGS | ||||||||||||||||||||||||||||||||
| 117 | 0 | ▶ | sub main::gopts { | ||||||||||||||||||||||||||||||
|
Subroutine
gopts: not called CC=8 SCAR=42.8
| |||||||||||||||||||||||||||||||||
| 118 | 0 | my $opts = shift; | |||||||||||||||||||||||||||||||
| 119 | 0 | ▶ | $opts||=''; | ||||||||||||||||||||||||||||||
|
Condition0%0/2
$opts ||= ""
MC/DC0%0/1
$opts ||= ""
$opts
Truth table0%0/2
A
A= $opts
| |||||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||
| 121 | 0 | ▶ | if($opts=~s/v\:?|h\:?|d\:?//sg){ | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 122 | 0 | ▶ | print STDERR("$0, options changed") if ::DEBUG; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 123 | } | ||||||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||||||
| 125 | 0 | $opts.='vhd'; | |||||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||||||
| 127 | 0 | my $o = {}; | |||||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||||||
| 129 | 0 | require Getopt::Std; | |||||||||||||||||||||||||||||||
| 130 | 0 | Getopt::Std::getopts($opts, $o); | |||||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||||||
| 132 | 0 | ▶ | if($o->{v}){ | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 133 | 0 | ▶ | if (defined $::VERSION){ | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 134 | 0 | print $::VERSION; | |||||||||||||||||||||||||||||||
| 135 | 0 | exit; | |||||||||||||||||||||||||||||||
| 136 | } | ||||||||||||||||||||||||||||||||
| 137 | 0 | print STDERR "$0 has no version\n"; | |||||||||||||||||||||||||||||||
| 138 | 0 | exit; | |||||||||||||||||||||||||||||||
| 139 | } | ||||||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||||||
| 141 | 0 | ▶ | if ($o->{d}){ | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 142 | 0 | $main::DEBUG = 1; | |||||||||||||||||||||||||||||||
| 143 | } | ||||||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||||||
| 146 | 0 | ▶ | if($o->{h}){ | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 147 | 0 | main::man() | |||||||||||||||||||||||||||||||
| 148 | } | ||||||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||||||
| 150 | 0 | return $o; | |||||||||||||||||||||||||||||||
| 151 | } | ||||||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||||||
| 156 | 0 | ▶ | sub main::argv_aspaths { | ||||||||||||||||||||||||||||||
|
Subroutine
argv_aspaths: not called CC=8 SCAR=42.8
| |||||||||||||||||||||||||||||||||
| 157 | 0 | my @argv; | |||||||||||||||||||||||||||||||
| 158 | 0 | ▶ | scalar @ARGV or return; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||||||
| 160 | 0 | for(@ARGV){ | |||||||||||||||||||||||||||||||
| 161 | 0 | ▶ | my $abs = Cwd::abs_path($_) or warn("$0, Does not resolve: $_, skipped.") and next; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/5
(my $abs = Cwd::abs_path($_)) || warn("$0, Does not resolve: $_, skipped.") && (next)
warn "$0, Does not resolve: $_, skipped." and next
MC/DC0%0/2
(my $abs = Cwd::abs_path($_)) || warn("$0, Does not resolve: $_, skipped.") && (next)
(my $abs = Cwd::abs_path($_))
warn "$0, Does not resolve: $_, skipped."
Truth table0%0/3
A || B
A= (my $abs = Cwd::abs_path($_))B= warn "$0, Does not resolve: $_, skipped."
| |||||||||||||||||||||||||||||||||
| 162 | 0 | ▶ | -e $abs or warn("$0, Does not exist: $_, skipped.") and next; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/5
-e $abs || warn("$0, Does not exist: $_, skipped.") && (next)
warn "$0, Does not exist: $_, skipped." and next
MC/DC0%0/2
-e $abs || warn("$0, Does not exist: $_, skipped.") && (next)
-e $abs
warn "$0, Does not exist: $_, skipped."
Truth table0%0/3
A || B
A= -e $absB= warn "$0, Does not exist: $_, skipped."
| |||||||||||||||||||||||||||||||||
| 163 | 0 | push @argv, $abs; | |||||||||||||||||||||||||||||||
| 164 | } | ||||||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||||||
| 166 | 0 | ▶ | scalar @argv or return; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||||||
| 168 | 0 | return \@argv; | |||||||||||||||||||||||||||||||
| 169 | } | ||||||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||||||
| 171 | 0 | ▶ | sub main::argv_aspaths_strict { | ||||||||||||||||||||||||||||||
|
Subroutine
argv_aspaths_strict: not called CC=8 SCAR=42.8
| |||||||||||||||||||||||||||||||||
| 172 | 0 | my @argv; | |||||||||||||||||||||||||||||||
| 173 | 0 | ▶ | scalar @ARGV or return; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||||||
| 175 | 0 | for(@ARGV){ | |||||||||||||||||||||||||||||||
| 176 | 0 | ▶ | my $abs = Cwd::abs_path($_) or warn("Does not resolve: $_.") and return; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/5
(my $abs = Cwd::abs_path($_)) || warn("Does not resolve: $_.") && (return)
warn "Does not resolve: $_." and return
MC/DC0%0/2
(my $abs = Cwd::abs_path($_)) || warn("Does not resolve: $_.") && (return)
(my $abs = Cwd::abs_path($_))
warn "Does not resolve: $_."
Truth table0%0/3
A || B
A= (my $abs = Cwd::abs_path($_))B= warn "Does not resolve: $_."
| |||||||||||||||||||||||||||||||||
| 177 | 0 | ▶ | -e $abs or warn("Is not on disk: $_.") and return; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/5
-e $abs || warn("Is not on disk: $_.") && (return)
warn "Is not on disk: $_." and return
MC/DC0%0/2
-e $abs || warn("Is not on disk: $_.") && (return)
-e $abs
warn "Is not on disk: $_."
Truth table0%0/3
A || B
A= -e $absB= warn "Is not on disk: $_."
| |||||||||||||||||||||||||||||||||
| 178 | 0 | push @argv, $abs; | |||||||||||||||||||||||||||||||
| 179 | } | ||||||||||||||||||||||||||||||||
| 180 | 0 | ▶ | scalar @argv or return; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 181 | 0 | return \@argv; | |||||||||||||||||||||||||||||||
| 182 | } | ||||||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||||||
| 184 | 0 | ▶ | sub main::argv_aspaths_loose { | ||||||||||||||||||||||||||||||
|
Subroutine
argv_aspaths_loose: not called CC=6 SCAR=37.4
| |||||||||||||||||||||||||||||||||
| 185 | 0 | my @argv; | |||||||||||||||||||||||||||||||
| 186 | 0 | ▶ | scalar @ARGV or return; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||||||
| 188 | 0 | for(@ARGV){ | |||||||||||||||||||||||||||||||
| 189 | 0 | ▶ | my $abs = Cwd::abs_path($_) or warn("$0, Does not resolve: $_, skipped.") and next; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/5
(my $abs = Cwd::abs_path($_)) || warn("$0, Does not resolve: $_, skipped.") && (next)
warn "$0, Does not resolve: $_, skipped." and next
MC/DC0%0/2
(my $abs = Cwd::abs_path($_)) || warn("$0, Does not resolve: $_, skipped.") && (next)
(my $abs = Cwd::abs_path($_))
warn "$0, Does not resolve: $_, skipped."
Truth table0%0/3
A || B
A= (my $abs = Cwd::abs_path($_))B= warn "$0, Does not resolve: $_, skipped."
| |||||||||||||||||||||||||||||||||
| 190 | 0 | push @argv, $abs; | |||||||||||||||||||||||||||||||
| 191 | } | ||||||||||||||||||||||||||||||||
| 192 | 0 | ▶ | scalar @argv or return; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 193 | 0 | return \@argv; | |||||||||||||||||||||||||||||||
| 194 | } | ||||||||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||||||
| 196 | 0 | ▶ | sub main::yn { | ||||||||||||||||||||||||||||||
|
Subroutine
yn: not called CC=5 SCAR=34.0
| |||||||||||||||||||||||||||||||||
| 197 | 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
| |||||||||||||||||||||||||||||||||
| 198 | 0 | my $val = undef; | |||||||||||||||||||||||||||||||
| 199 | 0 | ▶ | until (defined $val){ | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 200 | 0 | print "$question (y/n): "; | |||||||||||||||||||||||||||||||
| 201 | 0 | $val = <STDIN>; | |||||||||||||||||||||||||||||||
| 202 | 0 | chomp $val; | |||||||||||||||||||||||||||||||
| 203 | 0 | ▶ | if ($val eq 'y'){ $val = 1; } | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||
| 204 | 0 | elsif ($val eq 'n'){ $val = 0;} | |||||||||||||||||||||||||||||||
| 205 | 0 | else { $val = undef; } | |||||||||||||||||||||||||||||||
| 206 | } | ||||||||||||||||||||||||||||||||
| 207 | 0 | return $val; | |||||||||||||||||||||||||||||||
| 208 | } | ||||||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||||||
| 210 | # END GOPTS AND ARGS | ||||||||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||||||
| 213 | |||||||||||||||||||||||||||||||||
| 214 | |||||||||||||||||||||||||||||||||
| 215 | |||||||||||||||||||||||||||||||||
| 216 | |||||||||||||||||||||||||||||||||
| 217 | |||||||||||||||||||||||||||||||||
| 218 | |||||||||||||||||||||||||||||||||
| 219 | |||||||||||||||||||||||||||||||||
| 220 | |||||||||||||||||||||||||||||||||
| 221 | |||||||||||||||||||||||||||||||||
| 222 | |||||||||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||||||
| 224 | |||||||||||||||||||||||||||||||||
| 225 | |||||||||||||||||||||||||||||||||
| 226 | |||||||||||||||||||||||||||||||||
| 227 | |||||||||||||||||||||||||||||||||
| 228 | |||||||||||||||||||||||||||||||||
| 229 | |||||||||||||||||||||||||||||||||
| 230 | # BEIGN HELP , USAGE, MAN ETC | ||||||||||||||||||||||||||||||||
| 231 | |||||||||||||||||||||||||||||||||
| 232 | 0 | ▶ | sub main::man { | ||||||||||||||||||||||||||||||
|
Subroutine
man: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||
| 233 | |||||||||||||||||||||||||||||||||
| 234 | 0 | ▶ | if( defined $main::usage ){ | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||
| 235 | 0 | my $output = $main::usage; | |||||||||||||||||||||||||||||||
| 236 | 0 | print STDERR "$output\n"; | |||||||||||||||||||||||||||||||
| 237 | } | ||||||||||||||||||||||||||||||||
| 238 | |||||||||||||||||||||||||||||||||
| 239 | elsif( defined &main::usage ){ | ||||||||||||||||||||||||||||||||
| 240 | 0 | my $output = main::usage(); | |||||||||||||||||||||||||||||||
| 241 | 0 | print STDERR "$output\n"; | |||||||||||||||||||||||||||||||
| 242 | } | ||||||||||||||||||||||||||||||||
| 243 | |||||||||||||||||||||||||||||||||
| 244 | else { | ||||||||||||||||||||||||||||||||
| 245 | 0 | my $name = main::_scriptname(); | |||||||||||||||||||||||||||||||
| 246 | 0 | print `man $name`; | |||||||||||||||||||||||||||||||
| 247 | } | ||||||||||||||||||||||||||||||||
| 248 | |||||||||||||||||||||||||||||||||
| 249 | 0 | exit; | |||||||||||||||||||||||||||||||
| 250 | } | ||||||||||||||||||||||||||||||||
| 251 | |||||||||||||||||||||||||||||||||
| 252 | # END HELP | ||||||||||||||||||||||||||||||||
| 253 | |||||||||||||||||||||||||||||||||
| 254 | |||||||||||||||||||||||||||||||||
| 255 | |||||||||||||||||||||||||||||||||
| 256 | |||||||||||||||||||||||||||||||||
| 257 | |||||||||||||||||||||||||||||||||
| 258 | |||||||||||||||||||||||||||||||||
| 259 | |||||||||||||||||||||||||||||||||
| 260 | |||||||||||||||||||||||||||||||||
| 261 | 1 | ▶ | sub main::_scriptname{ | ||||||||||||||||||||||||||||||
|
Subroutine
_scriptname: called CC=2 SCAR=7.1
| |||||||||||||||||||||||||||||||||
| 262 | 1 | ▶ | my $name = $0 or return; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 263 | 1 | $name=~s/^.+\///; | |||||||||||||||||||||||||||||||
| 264 | 1 | return $name; | |||||||||||||||||||||||||||||||
| 265 | } | ||||||||||||||||||||||||||||||||
| 266 | |||||||||||||||||||||||||||||||||
| 267 | 4 | ▶ | sub main::_scriptname_only{ | ||||||||||||||||||||||||||||||
|
Subroutine
_scriptname_only: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||||||
| 268 | 4 | ▶ | my $name = $0 or return; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 269 | 4 | $name=~s/^.+\///; | |||||||||||||||||||||||||||||||
| 270 | 4 | $name=~s/\.\w{1,}$//; | |||||||||||||||||||||||||||||||
| 271 | 4 | return $name; | |||||||||||||||||||||||||||||||
| 272 | } | ||||||||||||||||||||||||||||||||
| 273 | |||||||||||||||||||||||||||||||||
| 274 | 3 | ▶ | sub main::config { | ||||||||||||||||||||||||||||||
|
Subroutine
config: called CC=6 SCAR=20.2
| |||||||||||||||||||||||||||||||||
| 275 | 3 | my $abs_conf = shift; | |||||||||||||||||||||||||||||||
| 276 | |||||||||||||||||||||||||||||||||
| 277 | 3 | ▶ | $abs_conf ||= main::suggest_abs_conf(); | ||||||||||||||||||||||||||||||
|
Condition66%2/3
$abs_conf ||= main::suggest_abs_conf()
MC/DC0%0/2
$abs_conf ||= main::suggest_abs_conf()
$abs_conf
main::suggest_abs_conf()
Truth table66%2/3
A ||= B
A= $abs_confB= main::suggest_abs_conf()
| |||||||||||||||||||||||||||||||||
| 278 | |||||||||||||||||||||||||||||||||
| 279 | 3 | ▶ | $abs_conf | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition20%1/5
$abs_conf || warn('Cannot determine abs_conf automatically and no arg passed') && (return)
warn "Cannot determine abs_conf automatically and no arg passed" and return
MC/DC0%0/2
$abs_conf || warn('Cannot determine abs_conf automatically and no arg passed') && (return)
$abs_conf
warn "Cannot determine abs_conf automatically and no arg passed"
Truth table33%1/3
A || B
A= $abs_confB= warn "Cannot determine abs_conf automatically and no arg passed"
| |||||||||||||||||||||||||||||||||
| 280 | or warn("Cannot determine abs_conf automatically and no arg passed") | ||||||||||||||||||||||||||||||||
| 281 | and return; | ||||||||||||||||||||||||||||||||
| 282 | |||||||||||||||||||||||||||||||||
| 283 | 3 | ▶ | -f $abs_conf | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition60%3/5
-f $abs_conf || warn("$0, [$abs_conf] does not exist.") && (return)
warn "$0, [$abs_conf] does not exist." and return
MC/DC0%0/2
-f $abs_conf || warn("$0, [$abs_conf] does not exist.") && (return)
-f $abs_conf
warn "$0, [$abs_conf] does not exist."
Truth table66%2/3
A || B
A= -f $abs_confB= warn "$0, [$abs_conf] does not exist."
| |||||||||||||||||||||||||||||||||
| 284 | or warn("$0, [$abs_conf] does not exist.") | ||||||||||||||||||||||||||||||||
| 285 | and return; | ||||||||||||||||||||||||||||||||
| 286 | |||||||||||||||||||||||||||||||||
| 287 | 2 | require YAML; | |||||||||||||||||||||||||||||||
| 288 | 2 | return (YAML::LoadFile($abs_conf)); | |||||||||||||||||||||||||||||||
| 289 | } | ||||||||||||||||||||||||||||||||
| 290 | |||||||||||||||||||||||||||||||||
| 291 | 3 | ▶ | sub main::suggest_abs_conf { | ||||||||||||||||||||||||||||||
|
Subroutine
suggest_abs_conf: called CC=3 SCAR=15.1
| |||||||||||||||||||||||||||||||||
| 292 | 3 | ▶ | $ENV{HOME} or warn("ENV HOME not set") and return; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition20%1/5
$ENV{'HOME'} || warn('ENV HOME not set') && (return)
warn "ENV HOME not set" and return
MC/DC0%0/2
$ENV{'HOME'} || warn('ENV HOME not set') && (return)
$ENV{'HOME'}
warn "ENV HOME not set"
Truth table33%1/3
A || B
A= $ENV{'HOME'}B= warn "ENV HOME not set"
| |||||||||||||||||||||||||||||||||
| 293 | 3 | return ( $ENV{HOME}.'/'. main::_scriptname_only().'.conf'); | |||||||||||||||||||||||||||||||
| 294 | } | ||||||||||||||||||||||||||||||||
| 295 | |||||||||||||||||||||||||||||||||
| 296 | 1 | ▶ | sub main::suggest_abs_log { | ||||||||||||||||||||||||||||||
|
Subroutine
suggest_abs_log: called CC=3 SCAR=15.1
| |||||||||||||||||||||||||||||||||
| 297 | 1 | ▶ | $ENV{HOME} or warn("ENV HOME not set") and return; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition20%1/5
$ENV{'HOME'} || warn('ENV HOME not set') && (return)
warn "ENV HOME not set" and return
MC/DC0%0/2
$ENV{'HOME'} || warn('ENV HOME not set') && (return)
$ENV{'HOME'}
warn "ENV HOME not set"
Truth table33%1/3
A || B
A= $ENV{'HOME'}B= warn "ENV HOME not set"
| |||||||||||||||||||||||||||||||||
| 298 | 1 | return ( $ENV{HOME}.'/'. main::_scriptname_only().'.log'); | |||||||||||||||||||||||||||||||
| 299 | } | ||||||||||||||||||||||||||||||||
| 300 | |||||||||||||||||||||||||||||||||
| 301 | 1 | ▶ | sub main::mktmpdir { | ||||||||||||||||||||||||||||||
|
Subroutine
mktmpdir: called CC=3 SCAR=11.4
| |||||||||||||||||||||||||||||||||
| 302 | 1 | my $d = '/tmp/tmp_'.time().( int rand(2000000) ); | |||||||||||||||||||||||||||||||
| 303 | 1 | ▶ | return undef and warn("$0, $d exists") if -d $d; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 304 | 1 | ▶ | mkdir $d or die("$0, cannot make $d, $!"); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 305 | 1 | return $d; | |||||||||||||||||||||||||||||||
| 306 | } | ||||||||||||||||||||||||||||||||
| 307 | |||||||||||||||||||||||||||||||||
| 308 | |||||||||||||||||||||||||||||||||
| 309 | |||||||||||||||||||||||||||||||||
| 310 | |||||||||||||||||||||||||||||||||
| 311 | |||||||||||||||||||||||||||||||||
| 312 | |||||||||||||||||||||||||||||||||
| 313 | # BEGIN OPERATING SYSTEM AND WITCH | ||||||||||||||||||||||||||||||||
| 314 | |||||||||||||||||||||||||||||||||
| 315 | 2 | ▶ | sub main::os_is_win { | ||||||||||||||||||||||||||||||
|
Subroutine
os_is_win: called CC=3 SCAR=12.0
| |||||||||||||||||||||||||||||||||
| 316 | 2 | for(qw(dos os2 mswin32)){ | |||||||||||||||||||||||||||||||
| 317 | 6 | ▶ | $^O=~/^$_/i or next; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 318 | 0 | return 1; | |||||||||||||||||||||||||||||||
| 319 | } | ||||||||||||||||||||||||||||||||
| 320 | 2 | return 0; | |||||||||||||||||||||||||||||||
| 321 | } | ||||||||||||||||||||||||||||||||
| 322 | |||||||||||||||||||||||||||||||||
| 323 | 0 | ▶ | sub witch { | ||||||||||||||||||||||||||||||
|
Subroutine
witch: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||
| 324 | 0 | my $bin = shift; | |||||||||||||||||||||||||||||||
| 325 | 0 | require File::Which; | |||||||||||||||||||||||||||||||
| 326 | 0 | ▶ | my $binpath = File::Which::which($bin) | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 327 | or dye("Can't find $bin, is it installed?"); | ||||||||||||||||||||||||||||||||
| 328 | 0 | return $binpath; | |||||||||||||||||||||||||||||||
| 329 | } | ||||||||||||||||||||||||||||||||
| 330 | |||||||||||||||||||||||||||||||||
| 331 | |||||||||||||||||||||||||||||||||
| 332 | |||||||||||||||||||||||||||||||||
| 333 | 0 | ▶ | sub say { print STDERR (+shift)."\n" and return 1; } | ||||||||||||||||||||||||||||||
|
Subroutine
say: not called CC=2 SCAR=17.9
Pod
documented
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 334 | 0 | ▶ | sub dye { say("$0, ".(+shift)) and exit 1; } | ||||||||||||||||||||||||||||||
|
Subroutine
dye: not called CC=2 SCAR=17.9
Pod
documented
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 335 | |||||||||||||||||||||||||||||||||
| 336 | 4 | *::witch = \&witch; | |||||||||||||||||||||||||||||||
| 337 | 4 | *::say = \&say; | |||||||||||||||||||||||||||||||
| 338 | 4 | *::dye = \&dye; | |||||||||||||||||||||||||||||||
| 339 | |||||||||||||||||||||||||||||||||
| 340 | # END OPERATING SYSTEM AND WITCH | ||||||||||||||||||||||||||||||||
| 341 | |||||||||||||||||||||||||||||||||
| 342 | |||||||||||||||||||||||||||||||||
| 343 | |||||||||||||||||||||||||||||||||
| 344 | |||||||||||||||||||||||||||||||||
| 345 | |||||||||||||||||||||||||||||||||
| 346 | |||||||||||||||||||||||||||||||||
| 347 | 4 | 1; | |||||||||||||||||||||||||||||||
| 348 | |||||||||||||||||||||||||||||||||
| 349 | __END__ | ||||||||||||||||||||||||||||||||