blib/lib/Game/Brandubh/Error.pm

filter: Statementstmt 97.3% 37 / 38 Branchbran 100% 10 / 10 Conditioncond 90.0% 9 / 10 MC/DCmcdc 83.3% 5 / 6 Subroutinesub 100% 13 / 13 Podpod 83.3% 5 / 6 totaltotal 95.1% 79 / 83 CC 11 SCAR 9.5
CC
11
Cov
97%
throw
5.0
code
3.0
known
3.0
CRAP 2.6
« blib/lib/Game/Brandubh/Rules.pm ↑ Summary blib/arch/Game/Brandubh/Install/Files.pm »
1 package Game::Brandubh::Error;
2  
3 44 ▶use 5.010;
Subroutine __ANON__: called CC=1 SCAR=0.0
4 44 ▶use strict;
Subroutine __ANON__: called CC=1 SCAR=0.0
5 44 ▶use warnings;
Subroutine __ANON__: called CC=1 SCAR=0.0
6  
7 44 ▶use Carp ();
Subroutine __ANON__: called CC=1 SCAR=0.0
8 44 ▶use Object::Proto::Sugar;
Subroutine __ANON__: called CC=1 SCAR=0.0
9  
10 44 our $VERSION = '0.02';
11  
12 44 our @FLAGS;
13 44 ▶BEGIN {
Subroutine __ANON__: called CC=1 SCAR=0.0
14 44 @FLAGS = qw(
15 bad_move
16 game_over
17 not_a_seat
18 not_your_turn
19 no_piece
20 not_your_piece
21 no_move
22 not_a_line
23 path_blocked
24 throne_closed
25 corner_closed
26 no_offer
27 own_offer
28 offer_standing
29 );
30 }
31  
32 44 our %MESSAGE;
33 44 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
34 44 %MESSAGE = (
35 bad_move => 'that is not a move',
36 game_over => 'the game is already over',
37 not_a_seat => 'that is not one of the two seats',
38 not_your_turn => 'it is not your turn',
39 no_piece => 'there is no piece there',
40 not_your_piece => 'that piece is not yours',
41 no_move => 'that piece did not move',
42 not_a_line => 'a piece moves in a straight line along a row or a column',
43 path_blocked => 'another piece is in the way',
44 throne_closed => 'no piece may stop on the throne',
45 corner_closed => 'only the king may stand on a corner',
46 no_offer => 'no draw has been offered',
47 own_offer => 'you cannot answer your own offer',
48 offer_standing => 'a draw has already been offered',
49 );
50 }
51  
52 44 has [@FLAGS] => (is => 'ro');
53  
54 44 has message => (is => 'ro', default => '');
55  
56 44 has move => (is => 'ro');
57  
58 4917 ▶sub throw {
Subroutine throw: called CC=5 SCAR=16.1
Pod documented
59 4917 my ($class, $flag, %extra) = @_;
60 Carp::croak("Game::Brandubh::Error: no such refusal as '" . ($flag // 'undef') . "'")
61 4917 ▶ unless defined $flag && exists $MESSAGE{$flag};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $flag and exists $Game::Brandubh::Error::MESSAGE{$flag} 2 4915 4917
Condition100%5/5
defined $flag and exists $Game::Brandubh::Error::MESSAGE{$flag}
!ll&&!rl&&r
114915
$flag // "undef"
l!l
11
MC/DC100%2/2
defined $flag and exists $Game::Brandubh::Error::MESSAGE{$flag}
defined $flag exists $Game::Brandubh::Error::MESSAGE{$flag}
MC/DC100%1/1
$flag // "undef"
$flag
Truth table100%3/3
A and B
A= defined $flagB= exists $Game::Brandubh::Error::MESSAGE{$flag}
ABresult
0X0
100
111
Truth table100%2/2
A
A= $flag
Aresult
11
00
62 return $class->new(
63 $flag => 1,
64 message => $MESSAGE{$flag},
65 4915 ▶ (defined $extra{move} ? (move => "$extra{move}") : ()),
Branch: 1 branch
BranchTrueFalseTotal
defined $extra{'move'} ? : 2473 2442 4915
66 );
67 }
68  
69 4917 ▶sub BUILD {
Subroutine BUILD: called CC=2 SCAR=6.9
Pod undocumented
70 4917 my ($self) = @_;
71 4917 my @set = grep { $self->$_ } @FLAGS;
72 4917 ▶ Carp::croak('Game::Brandubh::Error: a refusal is made by throw, and names exactly one thing')
Branch: 1 branch
BranchTrueFalseTotal
unless @set == 1 2 4915 4917
73 unless @set == 1;
74 4915 return;
75 }
76  
77 52 ▶sub code {
Subroutine code: called CC=3 SCAR=11.1
Pod documented
78 52 my ($self) = @_;
79 52 for my $flag (@FLAGS) {
80 333 ▶ return $flag if $self->$flag;
Branch: 1 branch
BranchTrueFalseTotal
if $self->$flag 52 281 333
81 }
82 0 return undef;
83 }
84  
85 1 ▶sub flags { @FLAGS }
Subroutine flags: called CC=1 SCAR=0.0
Pod documented
86  
87 49 ▶sub message_for { $MESSAGE{ $_[1] // '' } }
Subroutine message_for: called CC=2 SCAR=7.6
Pod documented
Condition50%1/2
$_[1] // ""
l!l
490
MC/DC0%0/1
$_[1] // ""
$_[1]
Truth table50%1/2
A
A= $_[1]
Aresult
11
00
88  
89 3 ▶sub known { defined $_[1] && exists $MESSAGE{ $_[1] } ? 1 : 0 }
Subroutine known: called CC=3 SCAR=11.0
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
defined $_[1] && exists $Game::Brandubh::Error::MESSAGE{$_[1]} ? : 1 2 3
Condition100%3/3
defined $_[1] and exists $Game::Brandubh::Error::MESSAGE{$_[1]}
!ll&&!rl&&r
111
MC/DC100%2/2
defined $_[1] and exists $Game::Brandubh::Error::MESSAGE{$_[1]}
defined $_[1] exists $Game::Brandubh::Error::MESSAGE{$_[1]}
Truth table100%3/3
A and B
A= defined $_[1]B= exists $Game::Brandubh::Error::MESSAGE{$_[1]}
ABresult
0X0
100
111
90  
91 44 1;
92  
93 __END__
« blib/lib/Game/Brandubh/Rules.pm ↑ Summary blib/arch/Game/Brandubh/Install/Files.pm »