TileMap/Legend.pm

filter: Statementstmt 100% 70 / 70 Branchbran 50.0% 2 / 4 Conditioncond 83.3% 5 / 6 MC/DCmcdc 66.6% 2 / 3 Subroutinesub 100% 19 / 19 Podpod 100% 5 / 5 totaltotal 96.2% 103 / 107 CC 8 SCAR 5.3
CC
8
Cov
96%
add_object
3.1
_build_object_map
3.0
get_class_of_object
2.1
CRAP 1.7
« TileMap/Role/Checks.pm ↑ Summary TileMap/Tile.pm »
1 package Game::TileMap::Legend;
2 4 $Game::TileMap::Legend::VERSION = '1.001';
3 4 ▶use v5.10;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 4 ▶use Mooish::Base -standard;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 4 ▶use Carp qw(croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 4 ▶use constant TERRAIN_CLASS => 'terrain';
Subroutine BEGIN: called CC=1 SCAR=0.0
11 4 ▶use constant WALL_OBJECT => 'wall';
Subroutine BEGIN: called CC=1 SCAR=0.0
12 4 ▶use constant VOID_OBJECT => 'void';
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 has field 'classes' => (
15 isa => HashRef [ ArrayRef [Str]],
16 4 ▶ default => sub { {} },
Subroutine __ANON__: called CC=1 SCAR=0.0
17 4 );
18  
19 has param 'characters_per_tile' => (
20 isa => PositiveInt,
21 3 ▶ default => sub { 1 },
Subroutine __ANON__: called CC=1 SCAR=0.0
22 4 );
23  
24 4 has field '_object_map' => (
25 isa => HashRef [Str],
26 lazy => 1,
27 );
28  
29 has field 'objects' => (
30 isa => HashRef [Any],
31 4 ▶ default => sub { {} },
Subroutine __ANON__: called CC=1 SCAR=0.0
32 4 );
33  
34 has field 'walls' => (
35 isa => HashRef [Bool],
36 4 ▶ default => sub { {} },
Subroutine __ANON__: called CC=1 SCAR=0.0
37 4 );
38  
39 has field 'voids' => (
40 isa => HashRef [Bool],
41 4 ▶ default => sub { {} },
Subroutine __ANON__: called CC=1 SCAR=0.0
42 4 );
43  
44 sub _build_object_map
45 4 ▶{
Subroutine _build_object_map: called CC=3 SCAR=11.0
46 4 my $self = shift;
47 4 my %classes = %{$self->classes};
48 4 my %objects = %{$self->objects};
49 4 my %map_reverse;
50  
51 4 foreach my $class (keys %classes) {
52 9 my @objects = map { $objects{$_} } @{$classes{$class}};
53 9 foreach my $obj (@objects) {
54 23 $map_reverse{$obj} = $class;
55 }
56 }
57  
58 4 return \%map_reverse;
59 }
60  
61 sub get_class_of_object
62 200 ▶{
Subroutine get_class_of_object: called CC=2 SCAR=7.2
Pod documented
63 200 my ($self, $obj) = @_;
64  
65 200 ▶ return $self->_object_map->{$obj}
Condition50%1/2
$self->_object_map->{$obj} // croak("no such object '${obj}' in map legend")
l!l
2000
MC/DC0%0/1
$self->_object_map->{$obj} // croak("no such object '${obj}' in map legend")
$self->_object_map->{$obj}
Truth table50%1/2
A
A= $self->_object_map->{$obj}
Aresult
11
00
66 // croak "no such object '$obj' in map legend";
67 }
68  
69 sub add_wall
70 5 ▶{
Subroutine add_wall: called CC=2 SCAR=6.9
Pod documented
71 5 my ($self, $marker, $object) = @_;
72 5 ▶ $object //= WALL_OBJECT;
Condition100%2/2
$object //= "wall"
l!l
14
MC/DC100%1/1
$object //= "wall"
$object
Truth table100%2/2
A
A= $object
Aresult
11
00
73  
74 5 $self->add_terrain($marker, $object);
75 5 $self->walls->{$object} = !!1;
76 5 return $self;
77 }
78  
79 sub add_void
80 5 ▶{
Subroutine add_void: called CC=2 SCAR=6.9
Pod documented
81 5 my ($self, $marker, $object) = @_;
82 5 ▶ $object //= VOID_OBJECT;
Condition100%2/2
$object //= "void"
l!l
14
MC/DC100%1/1
$object //= "void"
$object
Truth table100%2/2
A
A= $object
Aresult
11
00
83  
84 5 $self->add_terrain($marker, $object);
85 5 $self->voids->{$object} = !!1;
86 5 return $self;
87 }
88  
89 sub add_terrain
90 12 ▶{
Subroutine add_terrain: called CC=1 SCAR=0.0
Pod documented
91 12 my ($self, $marker, $object) = @_;
92  
93 12 return $self->add_object(TERRAIN_CLASS, $marker, $object);
94 }
95  
96 sub add_object
97 23 ▶{
Subroutine add_object: called CC=3 SCAR=11.2
Pod documented
98 23 my ($self, $class, $marker, $object) = @_;
99  
100 croak "marker '$marker' is already used"
101 23 ▶ if exists $self->objects->{$marker};
Branch: 1 branch
BranchTrueFalseTotal
if exists $self->objects->{$marker} 0 23 23
102  
103 23 ▶ croak "marker '$marker' has wrong length"
Branch: 1 branch
BranchTrueFalseTotal
unless length $marker == $self->characters_per_tile 0 23 23
104 unless length $marker == $self->characters_per_tile;
105  
106 23 push @{$self->classes->{$class}}, $marker;
107 23 $self->objects->{$marker} = $object;
108  
109 23 return $self;
110 }
111  
112 4 1;
113  
114 __END__
« TileMap/Role/Checks.pm ↑ Summary TileMap/Tile.pm »