File Coverage

blib/lib/Game/Battleship/Craft.pm
Criterion Covered Total %
statement 15 15 100.0
branch 1 2 50.0
condition n/a
subroutine 5 5 100.0
pod 1 2 50.0
total 22 24 91.6


line stmt bran cond sub pod time code
1             package Game::Battleship::Craft;
2             $Game::Battleship::Craft::VERSION = '0.0602';
3             our $AUTHORITY = 'cpan:GENE';
4              
5 1     1   6 use Carp;
  1         2  
  1         55  
6 1     1   561 use Moo;
  1         11757  
  1         7  
7 1     1   2051 use Types::Standard qw( ArrayRef Int Num Str );
  1         78467  
  1         12  
8              
9             has id => (
10             is => 'ro',
11             isa => Str,
12             );
13              
14             has name => (
15             is => 'ro',
16             isa => Str,
17             );
18              
19             has position => (
20             is => 'ro',
21             isa => ArrayRef[Num],
22             );
23              
24             has orient => (
25             is => 'ro',
26             isa => Int,
27             );
28              
29             has points => (
30             is => 'ro',
31             isa => Int,
32             );
33              
34             has hits => (
35             is => 'ro',
36             isa => Int,
37             );
38              
39             sub BUILD {
40 15     15 0 5050 my $self = shift;
41             # Default the id to the upper-cased first char of name.
42             # XXX This is brittle!
43 15 50       47 unless ( $self->id ) {
44 15         333 $self->{id} = ucfirst substr( $self->{name}, 0, 1 );
45             }
46             }
47              
48             sub hit {
49 23     23 1 43 my $self = shift;
50             # Tally the hit.
51 23         54 $self->{hits}++;
52             # Hand back the remainder of the craft's value.
53 23         77 return $self->points - $self->hits;
54             }
55              
56             1;
57              
58             __END__