File Coverage

blib/lib/Games/ScottAdams/Item.pm
Criterion Covered Total %
statement 25 25 100.0
branch 5 6 83.3
condition n/a
subroutine 7 7 100.0
pod 0 6 0.0
total 37 44 84.0


line stmt bran cond sub pod time code
1             # $Id: Item.pm,v 1.1 2006-10-31 20:31:21 mike Exp $
2              
3             # Item.pm - an item in a Scott Adams game.
4              
5             package Games::ScottAdams::Item;
6 1     1   6 use strict;
  1         9  
  1         366  
7              
8              
9             sub new {
10 33     33 0 57 my $class = shift();
11 33         87 my($name, $desc, $num, $where) = @_;
12              
13 33         201 return bless {
14             name => $name,
15             desc => $desc,
16             num => $num, # 0-based index into Game's list of rooms
17             where => $where, # name of containing room (undef=nowhere)
18             getdrop => undef, # name for automatic get/drop (if provided)
19             }, $class;
20             }
21              
22              
23             sub name {
24 25     25 0 45 my $this = shift();
25 25         72 return $this->{name};
26             }
27              
28             sub desc {
29 33     33 0 113 my $this = shift();
30 33         146 return $this->{desc};
31             }
32              
33             sub num {
34 67     67 0 227 my $this = shift();
35 67         187 return $this->{num};
36             }
37              
38              
39             sub where {
40 55     55 0 85 my $this = shift();
41 55         110 my($where) = @_;
42              
43 55         116 my $old = $this->{where};
44 55 100       125 if (defined $where) {
45 11 50       35 undef $where if $where eq '';
46 11         19 $this->{where} = $where;
47             }
48 55         207 return $old;
49             }
50              
51              
52             # Allow special argument of empty string meaning nowhere
53             sub getdrop {
54 61     61 0 98 my $this = shift();
55 61         119 my($name) = @_;
56              
57 61         106 my $old = $this->{getdrop};
58 61 100       132 if (defined $name) {
59 14         27 $this->{getdrop} = $name;
60             }
61 61         154 return $old;
62             }
63              
64              
65             1;