File Coverage

lib/Catan/Resource.pm
Criterion Covered Total %
statement 15 16 93.7
branch 1 2 50.0
condition 2 2 100.0
subroutine 7 8 87.5
pod 0 6 0.0
total 25 34 73.5


line stmt bran cond sub pod time code
1             package Catan::Resource;
2             $Catan::Resource::VERSION = '0.02';
3 7     7   3194 use strict;
  7         12  
  7         167  
4 7     7   33 use warnings;
  7         17  
  7         2087  
5              
6             sub new
7             {
8 101     101 0 151 my ($class, $quantity) = @_;
9 101   100     302 $quantity ||= 0;
10 101 50       425 die "quantity: $quantity must be an integer" unless $quantity =~ /^-?[0-9]+$/;
11 101         382 return bless { quantity => $quantity }, $class;
12             }
13              
14 16     16 0 58 sub quantity { $_[0]->{quantity} }
15 41     41 0 177 sub amount { $_[0]->{quantity} }
16 0     0 0 0 sub name { $_[0]->{name} }
17 33     33 0 111 sub code { $_[0]->{code} }
18              
19             # creates a new class with the amounts inverted - useful for balancing trades
20             sub invert
21             {
22 3     3 0 5 my $class = ref $_[0];
23 3         8 return $class->new( - $_[0]->amount );
24             }
25             1;
26              
27             __END__