TileMap/Legend.pm

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