File Coverage

blib/lib/Game/Battleship/Craft.pm
Criterion Covered Total %
statement 21 21 100.0
branch 1 2 50.0
condition n/a
subroutine 7 7 100.0
pod 2 2 100.0
total 31 32 96.8


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