bin/rcon-minecraft

filter: Statementstmt 100% 49 / 49 Branchbran 95.4% 21 / 22 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 9 / 9 Podpod n/a totaltotal 98.7% 79 / 80 CC 12 SCAR 15.7
CC
12
Cov
99%
main
8.0
run_command
5.0
BEGIN
1.0
CRAP 4.8
↑ Summary blib/lib/Net/RCON/Minecraft.pm »
1 #!/usr/bin/env perl
2  
3 3 ▶use 5.010;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 3 ▶use Net::RCON::Minecraft;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 3 ▶use Getopt::Long qw< GetOptionsFromArray >;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 3 ▶use Pod::Usage;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 3 ▶no warnings 'uninitialized';
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 3 ▶exit main(@ARGV) unless caller;
Branch: 1 branch
BranchTrueFalseTotal
unless &CORE::GLOBAL::caller() 0 3 3
13  
14 3 my $VER = Net::RCON::Minecraft->VERSION;
15  
16 18 ▶sub main {
Subroutine main: called CC=8 SCAR=20.8
17 18 my $ARGV = \@_;
18  
19 18 my %o = ( command => [ ] );
20 18 ▶ GetOptionsFromArray($ARGV, \%o, qw< host=s port=i password=s timeout=f
Branch: 1 branch
BranchTrueFalseTotal
&GetOptionsFromArray($ARGV, \%o, ("host=s", "port=i", "password=s", "timeout=f", "command|cmd=s\@", "color", "quiet", "echo", "help", "version")) or return 2 12 6 18
21 command|cmd=s@ color quiet echo help version > ) or return 2;
22 12 ▶ if ($o{help}) { pod2usage -verbose => 1, -exitval => 'noexit'; return }
Branch: 1 branch
BranchTrueFalseTotal
if ($o{"help"}) 1 11 12
23 11 ▶ if ($o{version}) { print "rcon-minecraft version $VER\n"; return }
Branch: 1 branch
BranchTrueFalseTotal
if ($o{"version"}) 1 10 11
24  
25 10 ▶ push @{$o{command}}, join(' ', @$ARGV) if @$ARGV;
Branch: 1 branch
BranchTrueFalseTotal
if @$ARGV 6 4 10
26  
27 10 $o{rcon} = Net::RCON::Minecraft->new(%o);
28 10 $o{rcon}->connect; # Not necessary, but better here to fail early
29  
30 9 ▶ if (@{$o{command}}) { for (@{$o{command}}) { run_command(\%o, $_) } }
Branch: 1 branch
BranchTrueFalseTotal
if (@{$o{'command'};}) { } 8 1 9
31 1 ▶ else { while (<STDIN>) { chomp; run_command(\%o, $_) } }
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline STDIN)) 2 1 3
32  
33 9 return;
34 }
35  
36 # Run the command and display the output, echoing if so configured
37 10 ▶sub run_command {
Subroutine run_command: called CC=5 SCAR=16.1
38 10 my $o = shift;
39 10 ▶ print "> $_[0]\n" if $o->{echo};
Branch: 1 branch
BranchTrueFalseTotal
if $o->{"echo"} 2 8 10
40  
41 10 my $resp = $o->{rcon}->command($_[0]);
42 10 ▶ my $disp = $o->{color} ? $resp->ansi : $resp->plain;
Branch: 1 branch
BranchTrueFalseTotal
$o->{'color'} ? : 1 9 10
43  
44 10 ▶ print length $resp ? "$disp\n" : "[Command sent]\n" unless $o->{quiet};
Branch: 2 branches
BranchTrueFalseTotal
unless $o->{"quiet"} 8 2 10
length $resp ? : 7 1 8
45 }
46  
47 __END__
↑ Summary blib/lib/Net/RCON/Minecraft.pm »