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.03';
3 7     7   3436 use strict;
  7         12  
  7         188  
4 7     7   35 use warnings;
  7         19  
  7         2036  
5              
6             sub new
7             {
8 799     799 0 1079 my ($class, $quantity) = @_;
9 799   100     1635 $quantity ||= 0;
10 799 50       3149 die "quantity: $quantity must be an integer" unless $quantity =~ /^-?[0-9]+$/;
11 799         2975 return bless { quantity => $quantity }, $class;
12             }
13              
14 904     904 0 3690 sub quantity { $_[0]->{quantity} }
15 1764     1764 0 4976 sub amount { $_[0]->{quantity} }
16 0     0 0 0 sub name { $_[0]->{name} }
17 2124     2124 0 7054 sub code { $_[0]->{code} }
18              
19             # creates a new class with the amounts inverted - useful for balancing trades
20             sub invert
21             {
22 195     195 0 350 my $class = ref $_[0];
23 195         422 return $class->new( - $_[0]->amount );
24             }
25             1;
26              
27             __END__