File Coverage

lib/Settlers/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 Settlers::Resource;
2             $Settlers::Resource::VERSION = '0.07';
3 7     7   3063 use strict;
  7         13  
  7         162  
4 7     7   37 use warnings;
  7         21  
  7         1986  
5              
6             sub new
7             {
8 827     827 0 1146 my ($class, $quantity) = @_;
9 827   100     1892 $quantity ||= 0;
10 827 50       3126 die "quantity: $quantity must be an integer" unless $quantity =~ /^-?[0-9]+$/;
11 827         3269 return bless { quantity => $quantity }, $class;
12             }
13              
14 460     460 0 1944 sub quantity { $_[0]->{quantity} }
15 1830     1830 0 5045 sub amount { $_[0]->{quantity} }
16 0     0 0 0 sub name { $_[0]->{name} }
17 1724     1724 0 5723 sub code { $_[0]->{code} }
18              
19             # creates a new class with the amounts inverted - useful for balancing trades
20             sub invert
21             {
22 203     203 0 367 my $class = ref $_[0];
23 203         456 return $class->new( - $_[0]->amount );
24             }
25             1;
26              
27             __END__