blib/lib/BalanceOfPower/Player/Role/Friend.pm untested

filter: Statementstmt 0.0% 0 / 39 Branchbran 0.0% 0 / 12 Conditioncond 0.0% 0 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 0.0% 0 / 7 Podpod 0.0% 0 / 3 totaltotal 0.0% 0 / 64 CC 7 SCAR 26.4
CC
7
Cov
0%
add_friendship
30.0
get_friendship
6.0
print_friendship
6.0
CRAP 14.0
1 package BalanceOfPower::Player::Role::Friend;
2 $BalanceOfPower::Player::Role::Friend::VERSION = '0.400115';
3 use strict;
4 use v5.10;
5 use Moo::Role;
6  
7 use BalanceOfPower::Constants ':all';
8  
9 has friendship => (
10 is => 'ro',
11 default => sub { {} },
12 );
13  
14 sub get_friendship
15 {
16 my $self = shift;
17 my $nation = shift;
18 if(exists $self->friendship->{$nation})
19 {
20 return 50 + $self->friendship->{$nation};
21 }
22 else
23 {
24 return 50;
25 }
26 }
27  
28 sub add_friendship
29 {
30 my $self = shift;
31 my $nation = shift;
32 my $value = shift;
33 if(exists $self->friendship->{$nation})
34 {
35 $self->friendship->{$nation} = $self->friendship->{$nation} + $value;
36 $self->friendship->{$nation} = 50 if $self->friendship->{$nation} > 50;
37 $self->friendship->{$nation} = -50 if $self->friendship->{$nation} < -50;
38 delete $self->friendship->{$nation} if $self->friendship->{$nation} == 0;
39 }
40 else
41 {
42 $self->friendship->{$nation} = $value;
43 }
44 return $self->get_friendship($nation);
45 }
46 sub print_friendship
47 {
48 my $self = shift;
49 my $nation = shift;
50 my $mode = shift || 'print';
51 if(! $nation)
52 {
53 my $data = { player => $self->name,
54 friendship => $self->friendship,
55 others => 1 };
56 return BalanceOfPower::Printer::print($mode, $self, 'print_player_friendship', $data);
57 }
58 else
59 {
60 my $data = { player => $self->name,
61 friendship => { $nation => $self->get_friendship($nation) },
62 others => 0 };
63 return BalanceOfPower::Printer::print($mode, $self, 'print_player_friendship', $data);
64 }
65  
66 }
67  
68 1;