« lib/BalanceOfPower/Relations/Role/Relation.pm
↑ Summary
blib/lib/BalanceOfPower/Role/Supporter.pm »
| 1 | package BalanceOfPower::Commands::TargetNation; | ||||||||||
| 2 | 11 | $BalanceOfPower::Commands::TargetNation::VERSION = '0.200000'; | |||||||||
| 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
| |||||||||||
| 29 | { | ||||||||||
| 30 | 0 | ▶ | if($self->good_target($argument)) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 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
| |||||||||||
| 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
| |||||||||||
| 48 | { | ||||||||||
| 49 | 0 | $nation = prompt $self->select_message, -menu=>\@nations; | |||||||||
| 50 | 0 | ▶ | return { status => -3} if ! $nation; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 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 | 3 | ▶ | my $self = shift; | ||||||||
|
Subroutine
good_target: called CC=3 SCAR=11.8
Pod
undocumented
| |||||||||||
| 62 | 3 | my $nation = shift; | |||||||||
| 63 | 3 | ▶ | return 0 if(! $nation); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 64 | 3 | my @nations = $self->get_available_targets(); | |||||||||
| 65 | 3 | my @selected = grep { $_ eq $nation} @nations; | |||||||||
| 66 | 3 | ▶ | if(@selected >= 1) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 67 | { | ||||||||||
| 68 | 0 | return 1; | |||||||||
| 69 | } | ||||||||||
| 70 | else | ||||||||||
| 71 | { | ||||||||||
| 72 | 3 | return 0; | |||||||||
| 73 | } | ||||||||||
| 74 | } | ||||||||||
| 75 | |||||||||||
| 76 | sub get_available_targets | ||||||||||
| 77 | { | ||||||||||
| 78 | 52 | ▶ | my $self = shift; | ||||||||
|
Subroutine
get_available_targets: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||
| 79 | 52 | my @nations = @{$self->world->nation_names}; | |||||||||
| 80 | 52 | ▶ | if($self->exclude_actor) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 81 | { | ||||||||||
| 82 | 52 | @nations = grep { $_ ne $self->actor } @nations; | |||||||||
| 83 | } | ||||||||||
| 84 | return @nations | ||||||||||
| 85 | 52 | } | |||||||||
| 86 | |||||||||||
| 87 | 11 | 1; | |||||||||