File Coverage

blib/lib/Games/Rezrov/ZObjectStatus.pm
Criterion Covered Total %
statement 35 35 100.0
branch 7 10 70.0
condition 5 7 71.4
subroutine 4 4 100.0
pod 0 1 0.0
total 51 57 89.4


line stmt bran cond sub pod time code
1             package Games::Rezrov::ZObjectStatus;
2              
3 1     1   5 use strict;
  1         2  
  1         30  
4             #use SelfLoader;
5 1     1   5 use Carp qw(confess);
  1         2  
  1         64  
6              
7 1         5 use Games::Rezrov::MethodMaker qw(
8             is_player
9             is_current_room
10             is_toplevel_child
11             in_inventory
12             in_current_room
13             parent_room
14             toplevel_child
15 1     1   5 );
  1         2  
16              
17             1;
18              
19             #__DATA__
20              
21             sub new {
22 70 50   70 0 197 confess unless @_ == 3;
23 70         128 my ($type, $id, $object_cache) = @_;
24 70         113 my $self = {};
25 70         210 bless $self, $type;
26              
27 70   50     243 my $pid = Games::Rezrov::StoryFile::player_object() || -1;
28 70   50     226 my $current_room = Games::Rezrov::StoryFile::current_room() || -1;
29 70         2438 my $zo = $object_cache->get($id);
30 70         279 my $levels = 0;
31 70         78 my $last;
32              
33 70         1987 my $oid = $zo->object_id();
34 70         2247 $self->is_player($pid == $oid);
35 70         1978 $self->is_current_room($current_room == $oid);
36              
37 70         146 while (1) {
38 209 100       922 last unless defined $zo;
39 140         3892 my $oid = $zo->object_id();
40 140 50       315 $self->in_inventory(1) if $oid == $pid;
41 140 100 100     2280 if ($levels and $object_cache->is_room($oid)) {
42 1 50       6 $self->in_current_room(1) if ($oid == $current_room);
43 1         35 $self->parent_room($zo);
44 1         31 $self->toplevel_child($last);
45 1         2 last;
46             }
47 139         191 $levels++;
48 139         174 $last = $zo;
49 139         3880 $zo = $object_cache->get($zo->get_parent_id());
50             }
51 70         1973 $self->is_toplevel_child($levels == 1);
52            
53 70         2170 return $self;
54             }