blib/lib/Game/TextMapper.pm

filter: Statementstmt 46.7% 205 / 439 Branchbran 13.3% 12 / 90 Conditioncond 14.8% 20 / 135 MC/DCmcdc 5.6% 4 / 71 Subroutinesub 55.2% 37 / 67 Podpod 0.0% 0 / 7 totaltotal 34.3% 278 / 809 CC 102 SCAR 58.4
CC
102
Cov
36%
border_modification
1482.0
__ANON__
42.0
archipelago_map
30.0
CRAP 342.4
↑ Summary blib/lib/Game/TextMapper/Gridmapper.pm »
1 #!/usr/bin/env perl
2 # License: AGPL 3 (see below)
3 package Game::TextMapper;
4  
5 11 our $VERSION = 1.09;
6  
7 11 ▶use Game::TextMapper::Log;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 11 ▶use Game::TextMapper::Point;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 11 ▶use Game::TextMapper::Line;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 11 ▶use Game::TextMapper::Mapper::Hex;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 11 ▶use Game::TextMapper::Mapper::Square;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 11 ▶use Game::TextMapper::Smale;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 11 ▶use Game::TextMapper::Apocalypse;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 11 ▶use Game::TextMapper::Gridmapper;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 11 ▶use Game::TextMapper::Schroeder::Alpine;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 11 ▶use Game::TextMapper::Schroeder::Archipelago;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 11 ▶use Game::TextMapper::Schroeder::Island;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 11 ▶use Game::TextMapper::Traveller;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 11 ▶use Game::TextMapper::Folkesten;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 11 ▶use Game::TextMapper::Solo;
Subroutine BEGIN: called CC=1 SCAR=0.0
21  
22 11 ▶use Modern::Perl '2018';
Subroutine BEGIN: called CC=1 SCAR=0.0
23 11 ▶use Mojolicious::Lite;
Subroutine BEGIN: called CC=1 SCAR=0.0
24 11 ▶use Mojo::DOM;
Subroutine BEGIN: called CC=1 SCAR=0.0
25 11 ▶use Mojo::Util qw(url_escape xml_escape);
Subroutine BEGIN: called CC=1 SCAR=0.0
26 11 ▶use File::ShareDir 'dist_dir';
Subroutine BEGIN: called CC=1 SCAR=0.0
27 11 ▶use Pod::Simple::HTML;
Subroutine BEGIN: called CC=1 SCAR=0.0
28 11 ▶use Pod::Simple::Text;
Subroutine BEGIN: called CC=1 SCAR=0.0
29 11 ▶use List::Util qw(none);
Subroutine BEGIN: called CC=1 SCAR=0.0
30 11 ▶use Cwd;
Subroutine BEGIN: called CC=1 SCAR=0.0
31  
32 # Commands for the command line!
33 11 push @{app->commands->namespaces}, 'Game::TextMapper::Command';
34  
35 # Change scheme if "X-Forwarded-Proto" header is set (presumably to HTTPS)
36 10 ▶app->hook(before_dispatch => sub {
Subroutine __ANON__: called CC=2 SCAR=7.2
37 10 my $c = shift;
38 10 ▶ $c->req->url->base->scheme('https')
Branch: 1 branch
BranchTrueFalseTotal
if $c->req->headers->header("X-Forwarded-Proto") 0 10 10
39 11 if $c->req->headers->header('X-Forwarded-Proto') } );
40  
41 11 plugin Config => {
42 default => {
43 loglevel => 'warn',
44 logfile => undef,
45 contrib => undef,
46 },
47 file => getcwd() . '/text-mapper.conf',
48 };
49  
50 11 my $log = Game::TextMapper::Log->get;
51 11 $log->level(app->config('loglevel'));
52 11 $log->path(app->config('logfile'));
53 11 ▶$log->info($log->path ? "Logfile is " . $log->path : "Logging to stderr");
Branch: 1 branch
BranchTrueFalseTotal
$log->path ? : 0 11 11
54  
55 11 ▶my $dist_dir = app->config('contrib') // dist_dir('Game-TextMapper');
Condition33%1/3
app()->config("contrib") // dist_dir("Game-TextMapper")
l!l&&r!l&&!r
0110
MC/DC0%0/2
app()->config("contrib") // dist_dir("Game-TextMapper")
app()->config("contrib") dist_dir("Game-TextMapper")
Truth table33%1/3
A // B
A= app()->config("contrib")B= dist_dir("Game-TextMapper")
ABresult
1X1
011
000
56 11 $log->debug("Reading contrib files from $dist_dir");
57  
58 1 ▶get '/' => sub {
Subroutine __ANON__: called CC=4 SCAR=20.8
59 1 my $c = shift;
60 1 my $param = $c->param('map');
61 1 ▶ if ($param) {
Branch: 1 branch
BranchTrueFalseTotal
if ($param) { } 0 1 1
62 0 my $mapper;
63 0 ▶ if ($c->param('type') and $c->param('type') eq 'square') {
Branch: 1 branch
BranchTrueFalseTotal
if ($c->param('type') and $c->param('type') eq 'square') { } 0 0 0
Condition0%0/3
$c->param("type") and $c->param("type") eq "square"
!ll&&!rl&&r
000
MC/DC0%0/2
$c->param("type") and $c->param("type") eq "square"
$c->param("type") $c->param("type") eq "square"
Truth table0%0/3
A and B
A= $c->param("type")B= $c->param("type") eq "square"
ABresult
0X0
100
111
64 0 $mapper = Game::TextMapper::Mapper::Square->new(dist_dir => $dist_dir);
65 } else {
66 0 $mapper = Game::TextMapper::Mapper::Hex->new(dist_dir => $dist_dir);
67 }
68 0 $mapper->initialize($param);
69 0 $c->render(text => $mapper->svg, format => 'svg');
70 } else {
71 1 my $mapper = new Game::TextMapper::Mapper;
72 1 my $map = $mapper->initialize('')->example();
73 1 $c->render(template => 'edit', map => $map);
74 }
75 11 };
76  
77 0 ▶any '/edit' => sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
78 0 my $c = shift;
79 0 my $mapper = new Game::TextMapper::Mapper;
80 0 ▶ my $map = $c->param('map') || $mapper->initialize('')->example();
Condition0%0/3
$c->param('map') || $mapper->initialize('')->example
l!l&&r!l&&!r
000
MC/DC0%0/2
$c->param('map') || $mapper->initialize('')->example
$c->param('map') $mapper->initialize('')->example
Truth table0%0/3
A || B
A= $c->param('map')B= $mapper->initialize('')->example
ABresult
1X1
011
000
81 0 $c->render(map => $map);
82 11 };
83  
84 1 ▶any '/render' => sub {
Subroutine __ANON__: called CC=3 SCAR=12.0
85 1 my $c = shift;
86 1 my $mapper;
87 1 ▶ if ($c->param('type') and $c->param('type') eq 'square') {
Branch: 1 branch
BranchTrueFalseTotal
if ($c->param('type') and $c->param('type') eq 'square') { } 0 1 1
Condition33%1/3
$c->param("type") and $c->param("type") eq "square"
!ll&&!rl&&r
100
MC/DC0%0/2
$c->param("type") and $c->param("type") eq "square"
$c->param("type") $c->param("type") eq "square"
Truth table33%1/3
A and B
A= $c->param("type")B= $c->param("type") eq "square"
ABresult
0X0
100
111
88 0 $mapper = Game::TextMapper::Mapper::Square->new(dist_dir => $dist_dir);
89 } else {
90 1 $mapper = Game::TextMapper::Mapper::Hex->new(dist_dir => $dist_dir);
91 }
92 1 $mapper->initialize($c->param('map'));
93 1 $c->render(text => $mapper->svg, format => 'svg');
94 11 };
95  
96 0 ▶get '/:type/redirect' => sub {
Subroutine __ANON__: not called CC=4 SCAR=30.0
97 0 my $self = shift;
98 0 my $type = $self->param('type');
99 0 my $rooms = $self->param('rooms');
100 0 my $seed = $self->param('seed');
101 0 my $caves = $self->param('caves');
102 0 my %params = ();
103 0 ▶ $params{rooms} = $rooms if $rooms;
Branch: 1 branch
BranchTrueFalseTotal
if $rooms 0 0 0
104 0 ▶ $params{seed} = $seed if $seed;
Branch: 1 branch
BranchTrueFalseTotal
if $seed 0 0 0
105 0 ▶ $params{caves} = $caves if $caves;
Branch: 1 branch
BranchTrueFalseTotal
if $caves 0 0 0
106 0 $self->redirect_to($self->url_for($type . "random")->query(%params));
107 11 } => 'redirect';
108  
109 # alias for /smale
110 0 ▶get '/random' => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
111 0 my $c = shift;
112 0 my $bw = $c->param('bw');
113 0 my $width = $c->param('width');
114 0 my $height = $c->param('height');
115 0 $c->render(template => 'edit', map => Game::TextMapper::Smale->new->generate_map($width, $height, $bw));
116 11 };
117  
118 0 ▶get '/smale' => sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
119 0 my $c = shift;
120 0 my $bw = $c->param('bw');
121 0 my $width = $c->param('width');
122 0 my $height = $c->param('height');
123 0 ▶ if ($c->stash('format')||'' eq 'txt') {
Branch: 1 branch
BranchTrueFalseTotal
if ($c->stash('format') or !1) { } 0 0 0
Condition0%0/2
$c->stash("format") or
l!l
00
MC/DC0%0/1
$c->stash("format") or
$c->stash("format")
Truth table0%0/2
A
A= $c->stash("format")
Aresult
11
00
124 0 $c->render(text => Game::TextMapper::Smale->new->generate_map($width, $height));
125 } else {
126 0 $c->render(template => 'edit',
127 map => Game::TextMapper::Smale->new->generate_map($width, $height, $bw));
128 }
129 11 };
130  
131 1 ▶get '/smale/random' => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
132 1 my $c = shift;
133 1 my $bw = $c->param('bw');
134 1 my $width = $c->param('width');
135 1 my $height = $c->param('height');
136 1 my $map = Game::TextMapper::Smale->new->generate_map($width, $height, $bw);
137 1 my $svg = Game::TextMapper::Mapper::Hex->new(dist_dir => $dist_dir)
138 ->initialize($map)
139 ->svg();
140 1 $c->render(text => $svg, format => 'svg');
141 11 };
142  
143 0 ▶get '/smale/random/text' => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
144 0 my $c = shift;
145 0 my $bw = $c->param('bw');
146 0 my $width = $c->param('width');
147 0 my $height = $c->param('height');
148 0 my $text = Game::TextMapper::Smale->new->generate_map($width, $height, $bw);
149 0 $c->render(text => $text, format => 'txt');
150 11 };
151  
152 2 ▶sub alpine_map {
Subroutine alpine_map: called CC=5 SCAR=16.6
Pod undocumented
153 2 my $c = shift;
154 # must be able to override this for the documentation
155 2 ▶ my $step = shift // $c->param('step');
Condition33%1/3
shift() // $c->param("step")
l!l&&r!l&&!r
002
MC/DC0%0/2
shift() // $c->param("step")
shift() $c->param("step")
Truth table33%1/3
A // B
A= shift()B= $c->param("step")
ABresult
1X1
011
000
156 # need to compute the seed here so that we can send along the URL
157 2 ▶ my $seed = $c->param('seed') || int(rand(1000000000));
Condition33%1/3
$c->param('seed') || int rand 1000000000
l!l&&r!l&&!r
020
MC/DC0%0/2
$c->param('seed') || int rand 1000000000
$c->param('seed') int rand 1000000000
Truth table33%1/3
A || B
A= $c->param('seed')B= int rand 1000000000
ABresult
1X1
011
000
158 2 my $url = $c->url_with('alpinedocument')->query({seed => $seed})->to_abs;
159 2 my @params = ($c->param('width'),
160 $c->param('height'),
161 $c->param('steepness'),
162 $c->param('peaks'),
163 $c->param('peak'),
164 $c->param('peak-min'),
165 $c->param('bumps'),
166 $c->param('bump'),
167 $c->param('bottom'),
168 $c->param('arid'),
169 $c->param('climate'),
170 $c->param('wind'),
171 $seed,
172 $url,
173 $step,
174 );
175 2 ▶ my $type = $c->param('type') // 'hex';
Condition100%2/2
$c->param("type") // "hex"
l!l
11
MC/DC100%1/1
$c->param("type") // "hex"
$c->param("type")
Truth table100%2/2
A
A= $c->param("type")
Aresult
11
00
176 2 ▶ if ($type eq 'hex') {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq 'hex') { } 1 1 2
177 1 return Game::TextMapper::Schroeder::Alpine
178 ->with_roles('Game::TextMapper::Schroeder::Hex')->new()
179 ->generate_map(@params);
180 } else {
181 1 return Game::TextMapper::Schroeder::Alpine
182 ->with_roles('Game::TextMapper::Schroeder::Square')->new()
183 ->generate_map(@params);
184 }
185 }
186  
187 0 ▶get '/alpine' => sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
188 0 my $c = shift;
189 0 my $map = alpine_map($c);
190 0 ▶ if ($c->stash('format') || '' eq 'txt') {
Branch: 1 branch
BranchTrueFalseTotal
if ($c->stash('format') or !1) { } 0 0 0
Condition0%0/2
$c->stash("format") or
l!l
00
MC/DC0%0/1
$c->stash("format") or
$c->stash("format")
Truth table0%0/2
A
A= $c->stash("format")
Aresult
11
00
191 0 $c->render(text => $map);
192 } else {
193 0 $c->render(template => 'edit', map => $map);
194 }
195 11 };
196  
197 2 ▶get '/alpine/random' => sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
198 2 my $c = shift;
199 2 my $map = alpine_map($c);
200 2 ▶ my $type = $c->param('type') // 'hex';
Condition100%2/2
$c->param("type") // "hex"
l!l
11
MC/DC100%1/1
$c->param("type") // "hex"
$c->param("type")
Truth table100%2/2
A
A= $c->param("type")
Aresult
11
00
201 2 my $mapper;
202 2 ▶ if ($type eq 'hex') {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq 'hex') { } 1 1 2
203 1 $mapper = Game::TextMapper::Mapper::Hex->new(dist_dir => $dist_dir);
204 } else {
205 1 $mapper = Game::TextMapper::Mapper::Square->new(dist_dir => $dist_dir);
206 }
207 2 my $svg = $mapper->initialize($map)->svg;
208 2 $c->render(text => $svg, format => 'svg');
209 11 };
210  
211 0 ▶get '/alpine/random/text' => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
212 0 my $c = shift;
213 0 my $map = alpine_map($c);
214 0 $c->render(text => $map, format => 'txt');
215 11 };
216  
217 0 ▶get '/alpine/document' => sub {
Subroutine __ANON__: not called CC=6 SCAR=37.4
218 0 my $c = shift;
219 # prepare a map for every step
220 0 my @maps;
221 0 ▶ my $type = $c->param('type') || 'hex';
Condition0%0/2
$c->param('type') || 'hex'
l!l
00
MC/DC0%0/1
$c->param('type') || 'hex'
$c->param('type')
Truth table0%0/2
A
A= $c->param('type')
Aresult
11
00
222 # use the same seed for all the calls
223 0 my $seed = $c->param('seed');
224 0 ▶ if (not defined $seed) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $seed) 0 0 0
225 0 $seed = int(rand(1000000000));
226 0 $c->param('seed' => $seed);
227 }
228 # We'd like to use a smaller map because it is so slow, so default to height 5.
229 0 ▶ $c->param('height' => 5) unless $c->param('height');
Branch: 1 branch
BranchTrueFalseTotal
unless $c->param("height") 0 0 0
230 # Let's remember the $data so we can query it for the parameters used.
231 0 my ($map, $data);
232 0 for my $step (1 .. 19) {
233 0 ($map, $data) = alpine_map($c, $step);
234 0 my $mapper;
235 0 ▶ if ($type eq 'hex') {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq 'hex') { } 0 0 0
236 0 $mapper = Game::TextMapper::Mapper::Hex->new(dist_dir => $dist_dir);
237 } else {
238 0 $mapper = Game::TextMapper::Mapper::Square->new(dist_dir => $dist_dir);
239 }
240 0 my $svg = $mapper->initialize($map)->svg;
241 0 $svg =~ s/<\?xml version="1.0" encoding="UTF-8" standalone="no"\?>\n//g;
242 0 push(@maps, $svg);
243 };
244 0 $c->stash("maps" => \@maps);
245  
246 # Generate the documentation text based on the stashed maps.
247 0 $c->render(template => 'alpine_document',
248 seed => $seed,
249 width => $data->width,
250 height => $data->height,
251 steepness => $data->steepness,
252 peaks => $data->peaks,
253 peak => $data->peak,
254 peak_min => $data->peak_min,
255 bumps => $data->bumps,
256 bump => $data->bump,
257 bottom => $data->bottom,
258 arid => $data->arid,
259 climate => $data->climate);
260 11 };
261  
262 0 ▶get '/alpine/random/interactive' => sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
263 0 my $c = shift;
264 0 my $map = alpine_map($c);
265 0 ▶ my $type = $c->param('type') // 'hex';
Condition0%0/2
$c->param("type") // "hex"
l!l
00
MC/DC0%0/1
$c->param("type") // "hex"
$c->param("type")
Truth table0%0/2
A
A= $c->param("type")
Aresult
11
00
266 0 my $mapper;
267 0 ▶ if ($type eq 'hex') {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq 'hex') { } 0 0 0
268 0 $mapper = Game::TextMapper::Mapper::Hex->new(dist_dir => $dist_dir);
269 } else {
270 0 $mapper = Game::TextMapper::Mapper::Square->new(dist_dir => $dist_dir);
271 }
272 0 my $svg = $mapper->initialize($map)->svg;
273 0 $c->render(template => 'alpine_interactive',
274 map => $svg);
275 11 };
276  
277 0 ▶get '/alpine/parameters' => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
278 0 my $c = shift;
279 0 $c->render(template => 'alpine_parameters');
280 11 };
281  
282 0 ▶get '/folkesten' => sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
283 0 my $c = shift;
284 0 ▶ if ($c->stash('format')||'' eq 'txt') {
Branch: 1 branch
BranchTrueFalseTotal
if ($c->stash('format') or !1) { } 0 0 0
Condition0%0/2
$c->stash("format") or
l!l
00
MC/DC0%0/1
$c->stash("format") or
$c->stash("format")
Truth table0%0/2
A
A= $c->stash("format")
Aresult
11
00
285 0 $c->render(text => Game::TextMapper::Folkesten->new->generate_map());
286 } else {
287 0 $c->render(template => 'edit',
288 map => Game::TextMapper::Folkesten->new->generate_map());
289 }
290 11 };
291  
292 0 ▶get '/folkesten/random' => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
293 0 my $c = shift;
294 0 my $map = Game::TextMapper::Folkesten->new->generate_map();
295 0 my $svg = Game::TextMapper::Mapper::Hex->new(dist_dir => $dist_dir)
296 ->initialize($map)
297 ->svg();
298 0 $c->render(text => $svg, format => 'svg');
299 11 };
300  
301 0 ▶get '/folkesten/random/text' => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
302 0 my $c = shift;
303 0 my $text = Game::TextMapper::Folkesten->new->generate_map();
304 0 $c->render(text => $text, format => 'txt');
305 11 };
306  
307 0 ▶get '/solo' => sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
308 0 my $c = shift;
309 0 my $mapper = Game::TextMapper::Solo->new($c->req->params->to_hash);
310 0 ▶ if ($c->stash('format')||'' eq 'txt') {
Branch: 1 branch
BranchTrueFalseTotal
if ($c->stash('format') or !1) { } 0 0 0
Condition0%0/2
$c->stash("format") or
l!l
00
MC/DC0%0/1
$c->stash("format") or
$c->stash("format")
Truth table0%0/2
A
A= $c->stash("format")
Aresult
11
00
311 0 $c->render(text => $mapper->generate_map());
312 } else {
313 0 $c->render(template => 'edit', map => $mapper->generate_map());
314 }
315 11 };
316  
317 0 ▶get '/solo/random' => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
318 0 my $c = shift;
319 0 my $mapper = Game::TextMapper::Solo->new($c->req->params->to_hash);
320 0 my $map = $mapper->generate_map();
321 0 my $svg = Game::TextMapper::Mapper::Hex->new(dist_dir => $dist_dir)
322 ->initialize($map)
323 ->svg();
324 0 $c->render(text => $svg, format => 'svg');
325 11 };
326  
327 0 ▶get '/solo/random/text' => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
328 0 my $c = shift;
329 0 my $mapper = Game::TextMapper::Solo->new($c->req->params->to_hash);
330 0 my $text = $mapper->generate_map();
331 0 $c->render(text => $text, format => 'txt');
332 11 };
333  
334 # does not handle z coordinates
335 0 ▶sub border_modification {
Subroutine border_modification: not called CC=38 SCAR=73.0
Pod undocumented
336 0 my ($map, $top, $left, $right, $bottom, $empty) = @_;
337 0 my (@lines, @temp, %seen);
338 0 my ($x, $y, $points, $text);
339 0 my ($minx, $miny, $maxx, $maxy);
340 # shift map around
341 0 foreach (split(/\r?\n/, $map)) {
342 0 ▶ if (($x, $y, $text) = /^(\d\d)(\d\d)\s+(.*)/) {
Branch: 2 branches
BranchTrueFalseTotal
if (() = /^(\d\d)(\d\d)\s+(.*)/u) { } 0 0 0
elsif (() = /^(-?\d\d-?\d\d(?:--?\d\d-?\d\d)+)\s+(.*)/u) { } 0 0 0
343 0 ▶ $minx = $x if not defined $minx or $x < $minx;
Branch: 1 branch
BranchTrueFalseTotal
if not defined $minx or $x < $minx 0 0 0
Condition0%0/3
not defined $minx or $x < $minx
l!l&&r!l&&!r
000
MC/DC0%0/2
not defined $minx or $x < $minx
not defined $minx $x < $minx
Truth table0%0/3
not(A) or B
A= not defined $minxB= $x < $minx
ABresult
1X1
011
000
344 0 ▶ $miny = $y if not defined $miny or $y < $miny;
Branch: 1 branch
BranchTrueFalseTotal
if not defined $miny or $y < $miny 0 0 0
Condition0%0/3
not defined $miny or $y < $miny
l!l&&r!l&&!r
000
MC/DC0%0/2
not defined $miny or $y < $miny
not defined $miny $y < $miny
Truth table0%0/3
not(A) or B
A= not defined $minyB= $y < $miny
ABresult
1X1
011
000
345 0 ▶ $maxx = $x if not defined $maxx or $x > $maxx;
Branch: 1 branch
BranchTrueFalseTotal
if not defined $maxx or $x > $maxx 0 0 0
Condition0%0/3
not defined $maxx or $x > $maxx
l!l&&r!l&&!r
000
MC/DC0%0/2
not defined $maxx or $x > $maxx
not defined $maxx $x > $maxx
Truth table0%0/3
not(A) or B
A= not defined $maxxB= $x > $maxx
ABresult
1X1
011
000
346 0 ▶ $maxy = $y if not defined $maxy or $y > $maxy;
Branch: 1 branch
BranchTrueFalseTotal
if not defined $maxy or $y > $maxy 0 0 0
Condition0%0/3
not defined $maxy or $y > $maxy
l!l&&r!l&&!r
000
MC/DC0%0/2
not defined $maxy or $y > $maxy
not defined $maxy $y > $maxy
Truth table0%0/3
not(A) or B
A= not defined $maxyB= $y > $maxy
ABresult
1X1
011
000
347 0 my $point = Game::TextMapper::Point->new(x => $x + $left, y => $y + $top);
348 0 ▶ $seen{$point->coordinates} = 1 if $empty;
Branch: 1 branch
BranchTrueFalseTotal
if $empty 0 0 0
349 0 push(@lines, [$point, $text]);
350 } elsif (($points, $text) = /^(-?\d\d-?\d\d(?:--?\d\d-?\d\d)+)\s+(.*)/) {
351 0 my @numbers = $points =~ /\G(-?\d\d)(-?\d\d)-?/cg;
352 0 my @points;
353 0 ▶ while (@numbers) {
Branch: 1 branch
BranchTrueFalseTotal
if (@numbers) 0 0 0
354 0 my ($x, $y) = splice(@numbers, 0, 2);
355 0 push(@points, Game::TextMapper::Point->new(x => $x + $left, y => $y + $top));
356 }
357 0 push(@lines, [Game::TextMapper::Line->new(points => \@points), $text]);
358 } else {
359 0 push(@lines, $_);
360 }
361 }
362 # only now do we know the extent of the map
363 0 $maxx += $left + $right;
364 0 $maxy += $top + $bottom;
365 # with that information we can now determine what lies outside the map
366 0 @temp = ();
367 0 foreach (@lines) {
368 0 ▶ if (ref) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $_) { } 0 0 0
369 0 my ($it, $text) = @$_;
370 0 ▶ if (ref($it) eq 'Game::TextMapper::Point') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $it eq 'Game::TextMapper::Point') { } 0 0 0
371 0 ▶ if ($it->x <= $maxx and $it->x >= $minx
Branch: 1 branch
BranchTrueFalseTotal
if ($it->x <= $maxx and $it->x >= $minx and $it->y <= $maxy and $it->y >= $miny) 0 0 0
Condition0%0/9
$it->x <= $maxx and $it->x >= $minx and $it->y <= $maxy and $it->y >= $miny
!ll&&!rl&&r
000
$it->x <= $maxx and $it->x >= $minx and $it->y <= $maxy
!ll&&!rl&&r
000
$it->x <= $maxx and $it->x >= $minx
!ll&&!rl&&r
000
MC/DC0%0/4
$it->x <= $maxx and $it->x >= $minx and $it->y <= $maxy and $it->y >= $miny
$it->x <= $maxx $it->x >= $minx $it->y <= $maxy $it->y >= $miny
Truth table0%0/5
A and B and C and D
A= $it->x <= $maxxB= $it->x >= $minxC= $it->y <= $maxyD= $it->y >= $miny
ABCDresult
0XXX0
10XX0
110X0
11100
11111
372 and $it->y <= $maxy and $it->y >= $miny) {
373 0 push(@temp, $_);
374 }
375 } else { # Game::TextMapper::Line
376 0 ▶ my $outside = none {
Subroutine __ANON__: not called CC=4 SCAR=30.0
377 0 ▶ ($_->x <= $maxx and $_->x >= $minx
Branch: 1 branch
BranchTrueFalseTotal
$_->x <= $maxx and $_->x >= $minx and $_->y <= $maxy and $_->y >= $miny 0 0 0
Condition0%0/6
$_->x <= $maxx and $_->x >= $minx and $_->y <= $maxy
!ll&&!rl&&r
000
$_->x <= $maxx and $_->x >= $minx
!ll&&!rl&&r
000
MC/DC0%0/3
$_->x <= $maxx and $_->x >= $minx and $_->y <= $maxy
$_->x <= $maxx $_->x >= $minx $_->y <= $maxy
Truth table0%0/4
A and B and C
A= $_->x <= $maxxB= $_->x >= $minxC= $_->y <= $maxy
ABCresult
0XX0
10X0
1100
1111
378 and $_->y <= $maxy and $_->y >= $miny)
379 0 } @{$it->points};
380 0 ▶ push(@temp, $_) unless $outside;
Branch: 1 branch
BranchTrueFalseTotal
unless $outside 0 0 0
381 }
382 } else {
383 0 push(@temp, $_);
384 }
385 }
386 0 @lines = @temp;
387 # add missing hexes, if requested
388 0 ▶ if ($empty) {
Branch: 1 branch
BranchTrueFalseTotal
if ($empty) 0 0 0
389 0 for $x ($minx .. $maxx) {
390 0 for $y ($miny .. $maxy) {
391 0 my $point = Game::TextMapper::Point->new(x => $x, y => $y);
392 0 ▶ if (not $seen{$point->coordinates}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($seen{$point->coordinates}) 0 0 0
393 0 push(@lines, [$point, "empty"]);
394 }
395 }
396 }
397 # also, sort regions before trails before others
398 @lines = sort {
399 0 (# arrays before strings
400 0 ▶ ref($b) cmp ref($a)
Condition0%0/29
ref $b cmp ref $a || !(ref $a || ref $b) && $a cmp $b || ref $Game::TextMapper::b->[0] cmp ref $Game::TextMapper::a->[0] || ref $Game::TextMapper::a->[0] eq 'Game::TextMapper::Point' && $Game::TextMapper::a->[0]->cmp($Game::TextMapper::b->[0]) || ref $Game::TextMapper::a->[0] eq 'Game::TextMapper::Line' && ($Game::TextMapper::a->[0]->points->[0]->cmp($Game::TextMapper::b->[0]->points->[0]) || $Game::TextMapper::a->[0]->points->[1]->cmp($Game::TextMapper::b->[0]->points->[1])) || 0
l!l
00
ref $b cmp ref $a or not ref $a || ref $b and $a cmp $b or ref $Game::TextMapper::b->[0] cmp ref $Game::TextMapper::a->[0] or ref $Game::TextMapper::a->[0] eq "Game::TextMapper::Point" and $Game::TextMapper::a->[0]->cmp($Game::TextMapper::b->[0]) or ref $Game::TextMapper::a->[0] eq "Game::TextMapper::Line" and $Game::TextMapper::a->[0]->points->[0]->cmp($Game::TextMapper::b->[0]->points->[0]) || $Game::TextMapper::a->[0]->points->[1]->cmp($Game::TextMapper::b->[0]->points->[1])
l!l&&r!l&&!r
000
ref $b cmp ref $a or not ref $a || ref $b and $a cmp $b or ref $Game::TextMapper::b->[0] cmp ref $Game::TextMapper::a->[0] or ref $Game::TextMapper::a->[0] eq "Game::TextMapper::Point" and $Game::TextMapper::a->[0]->cmp($Game::TextMapper::b->[0])
l!l&&r!l&&!r
000
ref $b cmp ref $a or not ref $a || ref $b and $a cmp $b or ref $Game::TextMapper::b->[0] cmp ref $Game::TextMapper::a->[0]
l!l&&r!l&&!r
000
ref $b cmp ref $a or not ref $a || ref $b and $a cmp $b
l!l&&r!l&&!r
000
not ref $a || ref $b and $a cmp $b
!ll&&!rl&&r
000
ref $a || ref $b
l!l&&r!l&&!r
000
ref $Game::TextMapper::a->[0] eq "Game::TextMapper::Point" and $Game::TextMapper::a->[0]->cmp($Game::TextMapper::b->[0])
!ll&&!rl&&r
000
ref $Game::TextMapper::a->[0] eq "Game::TextMapper::Line" and $Game::TextMapper::a->[0]->points->[0]->cmp($Game::TextMapper::b->[0]->points->[0]) || $Game::TextMapper::a->[0]->points->[1]->cmp($Game::TextMapper::b->[0]->points->[1])
!ll&&!rl&&r
000
$Game::TextMapper::a->[0]->points->[0]->cmp($Game::TextMapper::b->[0]->points->[0]) or $Game::TextMapper::a->[0]->points->[1]->cmp($Game::TextMapper::b->[0]->points->[1])
l!l&&r!l&&!r
000
MC/DC0%0/10
ref $b cmp ref $a || !(ref $a || ref $b) && $a cmp $b || ref $Game::TextMapper::b->[0] cmp ref $Game::TextMapper::a->[0] || ref $Game::TextMapper::a->[0] eq 'Game::TextMapper::Point' && $Game::TextMapper::a->[0]->cmp($Game::TextMapper::b->[0]) || ref $Game::TextMapper::a->[0] eq 'Game::TextMapper::Line' && ($Game::TextMapper::a->[0]->points->[0]->cmp($Game::TextMapper::b->[0]->points->[0]) || $Game::TextMapper::a->[0]->points->[1]->cmp($Game::TextMapper::b->[0]->points->[1])) || 0
ref $b cmp ref $a ref $a ref $b $a cmp $b ref $Game::TextMapper::b->[0] cmp ref $Game::TextMapper::a->[0] ref $Game::TextMapper::a->[0] eq "Game::TextMapper::Point" $Game::TextMapper::a->[0]->cmp($Game::TextMapper::b->[0]) ref $Game::TextMapper::a->[0] eq "Game::TextMapper::Line" $Game::TextMapper::a->[0]->points->[0]->cmp($Game::TextMapper::b->[0]->points->[0]) $Game::TextMapper::a->[0]->points->[1]->cmp($Game::TextMapper::b->[0]->points->[1])
Truth table0%0/32
A or not(B || C) and D or E or F and G or H and I or J
A= ref $b cmp ref $aB= ref $aC= ref $bD= $a cmp $bE= ref $Game::TextMapper::b->[0] cmp ref $Game::TextMapper::a->[0]F= ref $Game::TextMapper::a->[0] eq "Game::TextMapper::Point"G= $Game::TextMapper::a->[0]->cmp($Game::TextMapper::b->[0])H= ref $Game::TextMapper::a->[0] eq "Game::TextMapper::Line"I= $Game::TextMapper::a->[0]->points->[0]->cmp($Game::TextMapper::b->[0]->points->[0])J= $Game::TextMapper::a->[0]->points->[1]->cmp($Game::TextMapper::b->[0]->points->[1])
ABCDEFGHIJresult
1XXXXXXXXX1
0001XXXXXX1
01XX1XXXXX1
001X1XXXXX1
00001XXXXX1
01XX011XXX1
001X011XXX1
0000011XXX1
01XX00X11X1
01XX00X1011
01XX01011X1
01XX0101011
001X00X11X1
001X00X1011
001X01011X1
001X0101011
000000X11X1
000000X1011
000001011X1
00000101011
01XX00X0XX0
01XX00X1000
01XX0100XX0
01XX0101000
001X00X0XX0
001X00X1000
001X0100XX0
001X0101000
000000X0XX0
000000X1000
00000100XX0
00000101000
401 # string comparison if both are strings
402 or not(ref($a)) and not(ref($b)) and $a cmp $b
403 # if we get here, we know both are arrays
404 # points before lines
405 or ref($b->[0]) cmp ref($a->[0])
406 # if both are points, compare the coordinates
407 or ref($a->[0]) eq 'Game::TextMapper::Point' and $a->[0]->cmp($b->[0])
408 # if both are lines, compare the first two coordinates (the minimum line length)
409 or ref($a->[0]) eq 'Game::TextMapper::Line' and ($a->[0]->points->[0]->cmp($b->[0]->points->[0])
410 or $a->[0]->points->[1]->cmp($b->[0]->points->[1]))
411 # if bot are the same point (!) …
412 or 0)
413 } @lines;
414 }
415 $map = join("\n",
416 map {
417 0 ▶ if (ref) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $_) { } 0 0 0
418 0 my ($it, $text) = @$_;
419 0 ▶ if (ref($it) eq 'Game::TextMapper::Point') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $it eq 'Game::TextMapper::Point') { } 0 0 0
420 0 Game::TextMapper::Point::coord($it->x, $it->y) . " " . $text
421 } else {
422 0 my $points = $it->points;
423 join("-",
424 0 map { Game::TextMapper::Point::coord($_->x, $_->y) } @$points)
425 . " " . $text;
426 }
427 } else {
428 0 $_;
429 }
430 } @lines) . "\n";
431 0 return $map;
432 }
433  
434 0 ▶any '/borders' => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
435 0 my $c = shift;
436 0 my $map = border_modification(map { $c->param($_) } qw(map top left right bottom empty));
437 0 $c->param('map', $map);
438 0 $c->render(template => 'edit', map => $map);
439 11 };
440  
441 2 ▶sub island_map {
Subroutine island_map: called CC=5 SCAR=16.6
Pod undocumented
442 2 my $c = shift;
443 # must be able to override this for the documentation
444 2 ▶ my $step = shift // $c->param('step');
Condition33%1/3
shift() // $c->param("step")
l!l&&r!l&&!r
002
MC/DC0%0/2
shift() // $c->param("step")
shift() $c->param("step")
Truth table33%1/3
A // B
A= shift()B= $c->param("step")
ABresult
1X1
011
000
445 # need to compute the seed here so that we can send along the URL
446 2 ▶ my $seed = $c->param('seed') || int(rand(1000000000));
Condition33%1/3
$c->param('seed') || int rand 1000000000
l!l&&r!l&&!r
020
MC/DC0%0/2
$c->param('seed') || int rand 1000000000
$c->param('seed') int rand 1000000000
Truth table33%1/3
A || B
A= $c->param('seed')B= int rand 1000000000
ABresult
1X1
011
000
447 2 my $url = $c->url_with('islanddocument')->query({seed => $seed})->to_abs;
448 2 my @params = ($c->param('width'),
449 $c->param('height'),
450 $c->param('radius'),
451 $seed,
452 $url,
453 $step,
454 );
455 2 ▶ my $type = $c->param('type') // 'hex';
Condition100%2/2
$c->param("type") // "hex"
l!l
11
MC/DC100%1/1
$c->param("type") // "hex"
$c->param("type")
Truth table100%2/2
A
A= $c->param("type")
Aresult
11
00
456 2 ▶ if ($type eq 'hex') {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq 'hex') { } 1 1 2
457 1 return Game::TextMapper::Schroeder::Island
458 ->with_roles('Game::TextMapper::Schroeder::Hex')->new()
459 ->generate_map(@params);
460 } else {
461 1 return Game::TextMapper::Schroeder::Island
462 ->with_roles('Game::TextMapper::Schroeder::Square')->new()
463 ->generate_map(@params);
464 }
465 }
466  
467 0 ▶get '/island' => sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
468 0 my $c = shift;
469 0 my $map = island_map($c);
470 0 ▶ if ($c->stash('format') || '' eq 'txt') {
Branch: 1 branch
BranchTrueFalseTotal
if ($c->stash('format') or !1) { } 0 0 0
Condition0%0/2
$c->stash("format") or
l!l
00
MC/DC0%0/1
$c->stash("format") or
$c->stash("format")
Truth table0%0/2
A
A= $c->stash("format")
Aresult
11
00
471 0 $c->render(text => $map);
472 } else {
473 0 $c->render(template => 'edit', map => $map);
474 }
475 11 };
476  
477 2 ▶get '/island/random' => sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
478 2 my $c = shift;
479 2 my $map = island_map($c);
480 2 ▶ my $type = $c->param('type') // 'hex';
Condition100%2/2
$c->param("type") // "hex"
l!l
11
MC/DC100%1/1
$c->param("type") // "hex"
$c->param("type")
Truth table100%2/2
A
A= $c->param("type")
Aresult
11
00
481 2 my $mapper;
482 2 ▶ if ($type eq 'hex') {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq 'hex') { } 1 1 2
483 1 $mapper = Game::TextMapper::Mapper::Hex->new(dist_dir => $dist_dir);
484 } else {
485 1 $mapper = Game::TextMapper::Mapper::Square->new(dist_dir => $dist_dir);
486 }
487 2 my $svg = $mapper->initialize($map)->svg;
488 2 $c->render(text => $svg, format => 'svg');
489 11 };
490  
491 0 ▶sub archipelago_map {
Subroutine archipelago_map: not called CC=5 SCAR=34.0
Pod undocumented
492 0 my $c = shift;
493 # must be able to override this for the documentation
494 0 ▶ my $step = shift // $c->param('step');
Condition0%0/3
shift() // $c->param("step")
l!l&&r!l&&!r
000
MC/DC0%0/2
shift() // $c->param("step")
shift() $c->param("step")
Truth table0%0/3
A // B
A= shift()B= $c->param("step")
ABresult
1X1
011
000
495 # need to compute the seed here so that we can send along the URL
496 0 ▶ my $seed = $c->param('seed') || int(rand(1000000000));
Condition0%0/3
$c->param('seed') || int rand 1000000000
l!l&&r!l&&!r
000
MC/DC0%0/2
$c->param('seed') || int rand 1000000000
$c->param('seed') int rand 1000000000
Truth table0%0/3
A || B
A= $c->param('seed')B= int rand 1000000000
ABresult
1X1
011
000
497 0 my $url = $c->url_with('archipelagodocument')->query({seed => $seed})->to_abs;
498 0 my @params = ($c->param('width'),
499 $c->param('height'),
500 $c->param('concentration'),
501 $c->param('eruptions'),
502 $c->param('top'),
503 $c->param('bottom'),
504 $seed,
505 $url,
506 $step,
507 );
508 0 ▶ my $type = $c->param('type') // 'hex';
Condition0%0/2
$c->param("type") // "hex"
l!l
00
MC/DC0%0/1
$c->param("type") // "hex"
$c->param("type")
Truth table0%0/2
A
A= $c->param("type")
Aresult
11
00
509 0 ▶ if ($type eq 'hex') {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq 'hex') { } 0 0 0
510 0 return Game::TextMapper::Schroeder::Archipelago
511 ->with_roles('Game::TextMapper::Schroeder::Hex')->new()
512 ->generate_map(@params);
513 } else {
514 0 return Game::TextMapper::Schroeder::Archipelago
515 ->with_roles('Game::TextMapper::Schroeder::Square')->new()
516 ->generate_map(@params);
517 }
518 }
519  
520 0 ▶get '/archipelago' => sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
521 0 my $c = shift;
522 0 my $map = archipelago_map($c);
523 0 ▶ if ($c->stash('format') || '' eq 'txt') {
Branch: 1 branch
BranchTrueFalseTotal
if ($c->stash('format') or !1) { } 0 0 0
Condition0%0/2
$c->stash("format") or
l!l
00
MC/DC0%0/1
$c->stash("format") or
$c->stash("format")
Truth table0%0/2
A
A= $c->stash("format")
Aresult
11
00
524 0 $c->render(text => $map);
525 } else {
526 0 $c->render(template => 'edit', map => $map);
527 }
528 11 };
529  
530 0 ▶get '/archipelago/random' => sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
531 0 my $c = shift;
532 0 my $map = archipelago_map($c);
533 0 ▶ my $type = $c->param('type') // 'hex';
Condition0%0/2
$c->param("type") // "hex"
l!l
00
MC/DC0%0/1
$c->param("type") // "hex"
$c->param("type")
Truth table0%0/2
A
A= $c->param("type")
Aresult
11
00
534 0 my $mapper;
535 0 ▶ if ($type eq 'hex') {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq 'hex') { } 0 0 0
536 0 $mapper = Game::TextMapper::Mapper::Hex->new(dist_dir => $dist_dir);
537 } else {
538 0 $mapper = Game::TextMapper::Mapper::Square->new(dist_dir => $dist_dir);
539 }
540 0 my $svg = $mapper->initialize($map)->svg;
541 0 $c->render(text => $svg, format => 'svg');
542 11 };
543  
544 1 ▶sub gridmapper_map {
Subroutine gridmapper_map: called CC=5 SCAR=17.5
Pod undocumented
545 1 my $c = shift;
546 1 ▶ my $seed = $c->param('seed') || int(rand(1000000000));
Condition33%1/3
$c->param('seed') || int rand 1000000000
l!l&&r!l&&!r
010
MC/DC0%0/2
$c->param('seed') || int rand 1000000000
$c->param('seed') int rand 1000000000
Truth table33%1/3
A || B
A= $c->param('seed')B= int rand 1000000000
ABresult
1X1
011
000
547 1 ▶ my $pillars = $c->param('pillars') // 1;
Condition50%1/2
$c->param("pillars") // 1
l!l
01
MC/DC0%0/1
$c->param("pillars") // 1
$c->param("pillars")
Truth table50%1/2
A
A= $c->param("pillars")
Aresult
11
00
548 1 ▶ my $rooms = $c->param('rooms') // 5;
Condition50%1/2
$c->param("rooms") // 5
l!l
01
MC/DC0%0/1
$c->param("rooms") // 5
$c->param("rooms")
Truth table50%1/2
A
A= $c->param("rooms")
Aresult
11
00
549 1 ▶ my $caves = $c->param('caves') // 0;
Condition50%1/2
$c->param("caves") // 0
l!l
01
MC/DC0%0/1
$c->param("caves") // 0
$c->param("caves")
Truth table50%1/2
A
A= $c->param("caves")
Aresult
11
00
550 1 srand($seed);
551 1 return Game::TextMapper::Gridmapper->new()
552 ->generate_map($pillars, $rooms, $caves);
553 }
554  
555 0 ▶get '/gridmapper' => sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
556 0 my $c = shift;
557 0 my $map = gridmapper_map($c);
558 0 ▶ if ($c->stash('format') || '' eq 'txt') {
Branch: 1 branch
BranchTrueFalseTotal
if ($c->stash('format') or !1) { } 0 0 0
Condition0%0/2
$c->stash("format") or
l!l
00
MC/DC0%0/1
$c->stash("format") or
$c->stash("format")
Truth table0%0/2
A
A= $c->stash("format")
Aresult
11
00
559 0 $c->render(text => $map);
560 } else {
561 0 $c->render(template => 'edit', map => $map);
562 }
563 11 };
564  
565 1 ▶get '/gridmapper/random' => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
566 1 my $c = shift;
567 1 my $map = gridmapper_map($c);
568 1 my $mapper = Game::TextMapper::Mapper::Square->new(dist_dir => $dist_dir);
569 1 my $svg = $mapper->initialize($map)->svg;
570 1 $c->render(text => $svg, format => 'svg');
571 11 };
572  
573 0 ▶get '/gridmapper/random/text' => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
574 0 my $c = shift;
575 0 my $map = gridmapper_map($c);
576 0 $c->render(text => $map, format => 'txt');
577 11 };
578  
579 1 ▶sub apocalypse_map {
Subroutine apocalypse_map: called CC=2 SCAR=7.2
Pod undocumented
580 1 my $c = shift;
581 1 ▶ my $seed = $c->param('seed') || int(rand(1000000000));
Condition33%1/3
$c->param('seed') || int rand 1000000000
l!l&&r!l&&!r
010
MC/DC0%0/2
$c->param('seed') || int rand 1000000000
$c->param('seed') int rand 1000000000
Truth table33%1/3
A || B
A= $c->param('seed')B= int rand 1000000000
ABresult
1X1
011
000
582 1 srand($seed);
583 1 my $hash = $c->req->params->to_hash;
584 1 return Game::TextMapper::Apocalypse->new(%$hash)
585 ->generate_map();
586 }
587  
588 0 ▶get '/apocalypse' => sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
589 0 my $c = shift;
590 0 my $map = apocalypse_map($c);
591 0 ▶ if ($c->stash('format') || '' eq 'txt') {
Branch: 1 branch
BranchTrueFalseTotal
if ($c->stash('format') or !1) { } 0 0 0
Condition0%0/2
$c->stash("format") or
l!l
00
MC/DC0%0/1
$c->stash("format") or
$c->stash("format")
Truth table0%0/2
A
A= $c->stash("format")
Aresult
11
00
592 0 $c->render(text => $map);
593 } else {
594 0 $c->render(template => 'edit', map => $map);
595 }
596 11 };
597  
598 1 ▶get '/apocalypse/random' => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
599 1 my $c = shift;
600 1 my $map = apocalypse_map($c);
601 1 my $mapper = Game::TextMapper::Mapper::Hex->new(dist_dir => $dist_dir);
602 1 my $svg = $mapper->initialize($map)->svg;
603 1 $c->render(text => $svg, format => 'svg');
604 11 };
605  
606 0 ▶get '/apocalypse/random/text' => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
607 0 my $c = shift;
608 0 my $map = apocalypse_map($c);
609 0 $c->render(text => $map, format => 'txt');
610 11 };
611  
612 1 ▶sub star_map {
Subroutine star_map: called CC=2 SCAR=7.2
Pod undocumented
613 1 my $c = shift;
614 1 ▶ my $seed = $c->param('seed') || int(rand(1000000000));
Condition33%1/3
$c->param('seed') || int rand 1000000000
l!l&&r!l&&!r
010
MC/DC0%0/2
$c->param('seed') || int rand 1000000000
$c->param('seed') int rand 1000000000
Truth table33%1/3
A || B
A= $c->param('seed')B= int rand 1000000000
ABresult
1X1
011
000
615 1 srand($seed);
616 1 my $hash = $c->req->params->to_hash;
617 1 return Game::TextMapper::Traveller->new(%$hash)->generate_map();
618 }
619  
620 0 ▶get '/traveller' => sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
621 0 my $c = shift;
622 0 my $map = star_map($c);
623 0 ▶ if ($c->stash('format') || '' eq 'txt') {
Branch: 1 branch
BranchTrueFalseTotal
if ($c->stash('format') or !1) { } 0 0 0
Condition0%0/2
$c->stash("format") or
l!l
00
MC/DC0%0/1
$c->stash("format") or
$c->stash("format")
Truth table0%0/2
A
A= $c->stash("format")
Aresult
11
00
624 0 $c->render(text => $map);
625 } else {
626 0 $c->render(template => 'edit', map => $map);
627 }
628 11 };
629  
630 1 ▶get '/traveller/random' => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
631 1 my $c = shift;
632 1 my $map = star_map($c);
633 1 my $mapper = Game::TextMapper::Mapper::Hex->new(dist_dir => $dist_dir);
634 1 my $svg = $mapper->initialize($map)->svg;
635 1 $c->render(text => $svg, format => 'svg');
636 11 };
637  
638 0 ▶get '/traveller/random/text' => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
639 0 my $c = shift;
640 0 my $map = star_map($c);
641 0 $c->render(text => $map, format => 'txt');
642 11 };
643  
644 0 ▶get '/help' => sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
645 0 my $c = shift;
646  
647 0 seek(DATA,0,0);
648 0 local $/ = undef;
649 0 my $pod = <DATA>;
650 0 $pod =~ s/=head1 NAME\n.*=head1 DESCRIPTION/=head1 Text Mapper/gs;
651 0 my $parser = Pod::Simple::HTML->new;
652 0 $parser->html_header_after_title('');
653 0 $parser->html_header_before_title('');
654 0 $parser->title_prefix('<!--');
655 0 $parser->title_postfix('-->');
656 0 my $html;
657 0 $parser->output_string(\$html);
658 0 $parser->parse_string_document($pod);
659  
660 0 my $dom = Mojo::DOM->new($html);
661 0 for my $pre ($dom->find('pre')->each) {
662 0 my $map = $pre->text;
663 0 $map =~ s/^ //mg;
664 0 ▶ next if $map =~ /^perl/; # how to call it
Branch: 1 branch
BranchTrueFalseTotal
if $map =~ /^perl/u 0 0 0
665 0 my $url = $c->url_for('render')->query(map => $map);
666 0 $pre->replace("<pre>" . xml_escape($map) . "</pre>\n"
667 . qq{<p class="example"><a href="$url">Render this example</a></p>});
668 }
669  
670 0 $c->render(html => $dom);
671 11 };
672  
673 11 app->start;
674  
675 __DATA__
↑ Summary blib/lib/Game/TextMapper/Gridmapper.pm »