blib/lib/Game/TextMapper.pm

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