script/mrsh

filter: Statementstmt 59.0% 39 / 66 Branchbran 32.1% 9 / 28 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 66.6% 6 / 9 Podpod n/a totaltotal 50.9% 55 / 108 CC 6 SCAR 29.3
CC
6
Cov
51%
show_groups_and_exit
42.0
__ANON__
2.0
__ANON__
2.0
CRAP 18.7
« lib/App/MrShell.pm ↑ Summary
1 #!/usr/local/bin/perl
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use Getopt::Long; Getopt::Long::Configure("bundling"); # make switches case sensitive (and turn on bundling)
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use Pod::Usage;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 1 ▶use App::MrShell;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 1 my @hosts;
11 1 my $conf = "$ENV{HOME}/.mrshrc";
12 1 my $log;
13 my $shell;
14 1 my $trunc;
15 1 my $debug;
16 1 my $no_esc;
17 1 my $show_groups_and_exit;
18  
19 1 my @orig_ARGV = @ARGV;
20 MAGICALLY_UNDERSTAND_HOSTGROUPS: {
21 1 GetOptions(
22 "groups|list|g" => \$show_groups_and_exit,
23 0 ▶ "version|v" => sub { print "This is Mr. Shell version $App::MrShell::VERSION.\n\n"; pod2usage() },
Subroutine __ANON__: not called CC=1 SCAR=6.9
24 "host|H=s@" => \@hosts,
25 "conf|c:s" => \$conf, # optional value
26 "noesc|N" => \$no_esc,
27 "log|l=s" => \$log,
28 "trunc|t" => \$trunc, # whether to truncate the log file
29 'debug|d:i' => \$debug,
30 "shell|s=s" => \$shell,
31 0 ▶ "help|h" => sub { pod2usage(-verbose=>1) },
Subroutine __ANON__: not called CC=1 SCAR=6.9
32  
33 0 ▶ ) or pod2usage(); do{ warn "ERROR: command required\n"; pod2usage()} unless @ARGV or $show_groups_and_exit;
Branch: 2 branches
BranchTrueFalseTotal
&GetOptions("groups|list|g", \$show_groups_and_exit, "version|v", sub { print "This is Mr. Shell version $App::MrShell::VERSION.\n\n"; pod2usage(); } , "host|H=s\@", \@hosts, "conf|c:s", \$conf, "noesc|N", \$no_esc, "log|l=s", \$log, "trunc|t", \$trunc, "debug|d:i", \$debug, "shell|s=s", \$shell, "help|h", sub { pod2usage("-verbose", 1); } ) or pod2usage() 1 0 1
unless (@ARGV or $show_groups_and_exit) 0 1 1
Condition33%1/3
@ARGV or $show_groups_and_exit
l!l&&r!l&&!r
100
MC/DC0%0/2
@ARGV or $show_groups_and_exit
@ARGV $show_groups_and_exit
Truth table33%1/3
A or B
A= @ARGVB= $show_groups_and_exit
ABresult
1X1
011
000
34  
35 1 ▶ no warnings 'uninitialized'; ## no critic: this is a stupid warning anyway
Subroutine BEGIN: called CC=1 SCAR=0.0
36 1 ▶ if( $ARGV[0] =~ m/^\@/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ARGV[0] =~ /^\@/) 0 1 1
37 0 ▶ while( $ARGV[0] =~ m/^\@/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ARGV[0] =~ /^\@/) 0 0 0
38 0 ▶ @orig_ARGV = map { $_ eq $ARGV[0] ? ('-H'=>$_) : ($_) } @orig_ARGV;
Branch: 1 branch
BranchTrueFalseTotal
$_ eq $ARGV[0] ? : 0 0 0
39 0 shift @ARGV;
40 }
41  
42 0 @ARGV = @orig_ARGV; ## no critic: no I really really meant to change the global one, thanks
43 0 redo MAGICALLY_UNDERSTAND_HOSTGROUPS;
44 }
45 }
46  
47 1 my $mrsh = App::MrShell->new->set_usage_error("pod2usage");
48  
49 1 ▶ $mrsh->read_config($conf) if $conf;
Branch: 1 branch
BranchTrueFalseTotal
if $conf 1 0 1
50 1 ▶ show_groups_and_exit() if $show_groups_and_exit;
Branch: 1 branch
BranchTrueFalseTotal
if $show_groups_and_exit 0 1 1
51 1 ▶ $mrsh->set_logfile_option($log, $trunc) if $log;
Branch: 1 branch
BranchTrueFalseTotal
if $log 1 0 1
52 1 ▶ $mrsh->set_shell_command_option($shell) if $shell;
Branch: 1 branch
BranchTrueFalseTotal
if $shell 1 0 1
53 1 ▶ $mrsh->set_debug_option($debug) if defined $debug;
Branch: 1 branch
BranchTrueFalseTotal
if defined $debug 0 1 1
54 1 ▶ $mrsh->set_no_command_escapes_option if $no_esc;
Branch: 1 branch
BranchTrueFalseTotal
if $no_esc 0 1 1
55  
56 1 $mrsh->set_hosts(@hosts) # tell Mr. Shell where to run things
57 ->queue_command(@ARGV) # queue a command for whatever hosts are set
58 ->run_queue; # tell POE to do what POE does
59  
60 0 ▶sub show_groups_and_exit {
Subroutine show_groups_and_exit: not called CC=6 SCAR=37.4
61 0 my %groups = $mrsh->groups;
62 0 my @groups = sort keys %groups;
63  
64 0 ▶ if( my @h = grep {s/^@//} @hosts ) { ## no critic: bah
Branch: 1 branch
BranchTrueFalseTotal
if (my(@h) = grep({s/^@//;} @hosts)) 0 0 0
65 0 @groups = @h;
66 }
67  
68 0 ▶ unless(@groups) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@groups) 0 0 0
69 0 print "(no gropus to show)\n";
70 0 exit 0;
71 }
72  
73 0 my $len = length $groups[0];
74 0 ▶ for(@groups) { $len = length $_ if length $_ > $len }
Branch: 1 branch
BranchTrueFalseTotal
if length $_ > $len 0 0 0
75  
76 0 $len ++;
77 0 for(@groups) {
78 0 printf '%-*s %s', $len, "$_:", "@{ $groups{$_} }\n";
79 }
80  
81 0 exit 0;
82 }
83  
84 __END__
« lib/App/MrShell.pm ↑ Summary