lib/BalanceOfPower/Commands/TargetNation.pm

filter: Statementstmt 30.6% 15 / 49 Branchbran 0.0% 0 / 16 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 50.0% 4 / 8 Podpod 0.0% 0 / 4 totaltotal 24.6% 19 / 77 CC 9 SCAR 29.5
CC
9
Cov
23%
execute
42.0
good_target
12.0
get_available_targets
6.0
CRAP 19.1
« blib/lib/BalanceOfPower/Commands/TargetNation.pm ↑ Summary lib/BalanceOfPower/Commands/AddRoute.pm »
1 package BalanceOfPower::Commands::TargetNation;
2 11 $BalanceOfPower::Commands::TargetNation::VERSION = '0.300010';
3 11 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 11 ▶use v5.10;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 11 ▶use IO::Prompter;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 11 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8  
9 11 with "BalanceOfPower::Commands::Role::Command";
10  
11 11 has exclude_actor => (
12 is => 'rw',
13 default => 1
14 );
15  
16 sub select_message
17 {
18 0 ▶ return "Select a nation:";
Subroutine select_message: not called CC=1 SCAR=6.9
Pod undocumented
19 }
20  
21 sub execute
22 {
23 0 ▶ my $self = shift;
Subroutine execute: not called CC=6 SCAR=37.4
Pod undocumented
24 0 my $query = shift;
25 0 my $nation = shift;
26 0 my $argument = $self->extract_argument($query);
27 0 $argument = $self->world->correct_nation_name($argument);
28 0 ▶ if($argument)
Branch: 1 branch
BranchTrueFalseTotal
if ($argument) { } 0 0 0
29 {
30 0 ▶ if($self->good_target($argument))
Branch: 1 branch
BranchTrueFalseTotal
if ($self->good_target($argument)) { } 0 0 0
31 {
32 0 return { status => 1, command => $self->name . " " . $argument };
33 }
34 else
35 {
36 0 say "Bad argument provided: $argument";
37 }
38 }
39 else
40 {
41 0 ▶ if($self->good_target($nation))
Branch: 1 branch
BranchTrueFalseTotal
if ($self->good_target($nation)) 0 0 0
42 {
43 0 return { status => 1, command => $self->name . " " . $nation };
44 }
45 }
46 0 my @nations = $self->get_available_targets;
47 0 ▶ if(@nations > 0)
Branch: 1 branch
BranchTrueFalseTotal
if (@nations > 0) { } 0 0 0
48 {
49 0 $nation = prompt $self->select_message, -menu=>\@nations;
50 0 ▶ return { status => -3} if ! $nation;
Branch: 1 branch
BranchTrueFalseTotal
unless $nation 0 0 0
51 0 return { status => 1, command => $self->name . " " . $nation };
52 }
53 else
54 {
55 0 return { status => -2 };
56 }
57 }
58  
59 sub good_target
60 {
61 0 ▶ my $self = shift;
Subroutine good_target: not called CC=3 SCAR=24.8
Pod undocumented
62 0 my $nation = shift;
63 0 ▶ return 0 if(! $nation);
Branch: 1 branch
BranchTrueFalseTotal
unless $nation 0 0 0
64 0 my @nations = $self->get_available_targets();
65 0 my @selected = grep { $_ eq $nation} @nations;
66 0 ▶ if(@selected >= 1)
Branch: 1 branch
BranchTrueFalseTotal
if (@selected >= 1) { } 0 0 0
67 {
68 0 return 1;
69 }
70 else
71 {
72 0 return 0;
73 }
74 }
75  
76 sub get_available_targets
77 {
78 0 ▶ my $self = shift;
Subroutine get_available_targets: not called CC=2 SCAR=17.9
Pod undocumented
79 0 my @nations = @{$self->world->nation_names};
80 0 ▶ if($self->exclude_actor)
Branch: 1 branch
BranchTrueFalseTotal
if ($self->exclude_actor) 0 0 0
81 {
82 0 @nations = grep { $_ ne $self->actor } @nations;
83 }
84 return @nations
85 0 }
86  
87 11 1;
« blib/lib/BalanceOfPower/Commands/TargetNation.pm ↑ Summary lib/BalanceOfPower/Commands/AddRoute.pm »