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/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 app->hook(before_dispatch => sub {
37 10 ▶ my $c = shift;
Subroutine __ANON__: called CC=2 SCAR=7.2
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 get '/' => sub {
59 1 ▶ my $c = shift;
Subroutine __ANON__: called CC=4 SCAR=20.8
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 any '/edit' => sub {
78 0 ▶ my $c = shift;
Subroutine __ANON__: not called CC=2 SCAR=17.9
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 any '/render' => sub {
85 1 ▶ my $c = shift;
Subroutine __ANON__: called CC=3 SCAR=12.0
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 get '/:type/redirect' => sub {
97 0 ▶ my $self = shift;
Subroutine __ANON__: not called CC=4 SCAR=30.0
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 get '/random' => sub {
111 0 ▶ my $c = shift;
Subroutine __ANON__: not called CC=1 SCAR=6.9
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 get '/smale' => sub {
119 0 ▶ my $c = shift;
Subroutine __ANON__: not called CC=3 SCAR=24.8
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 get '/smale/random' => sub {
132 1 ▶ my $c = shift;
Subroutine __ANON__: called CC=1 SCAR=0.0
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 get '/smale/random/text' => sub {
144 0 ▶ my $c = shift;
Subroutine __ANON__: not called CC=1 SCAR=6.9
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 sub alpine_map {
153 2 ▶ my $c = shift;
Subroutine alpine_map: called CC=5 SCAR=16.6
Pod undocumented
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('bumps'),
165 $c->param('bump'),
166 $c->param('bottom'),
167 $c->param('arid'),
168 $c->param('climate'),
169 $c->param('wind'),
170 $seed,
171 $url,
172 $step,
173 );
174 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
175 2 ▶ if ($type eq 'hex') {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq 'hex') { } 1 1 2
176 1 return Game::TextMapper::Schroeder::Alpine
177 ->with_roles('Game::TextMapper::Schroeder::Hex')->new()
178 ->generate_map(@params);
179 } else {
180 1 return Game::TextMapper::Schroeder::Alpine
181 ->with_roles('Game::TextMapper::Schroeder::Square')->new()
182 ->generate_map(@params);
183 }
184 }
185  
186 get '/alpine' => sub {
187 0 ▶ my $c = shift;
Subroutine __ANON__: not called CC=3 SCAR=24.8
188 0 my $map = alpine_map($c);
189 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
190 0 $c->render(text => $map);
191 } else {
192 0 $c->render(template => 'edit', map => $map);
193 }
194 11 };
195  
196 get '/alpine/random' => sub {
197 2 ▶ my $c = shift;
Subroutine __ANON__: called CC=3 SCAR=11.0
198 2 my $map = alpine_map($c);
199 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
200 2 my $mapper;
201 2 ▶ if ($type eq 'hex') {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq 'hex') { } 1 1 2
202 1 $mapper = Game::TextMapper::Mapper::Hex->new(dist_dir => $dist_dir);
203 } else {
204 1 $mapper = Game::TextMapper::Mapper::Square->new(dist_dir => $dist_dir);
205 }
206 2 my $svg = $mapper->initialize($map)->svg;
207 2 $c->render(text => $svg, format => 'svg');
208 11 };
209  
210 get '/alpine/random/text' => sub {
211 0 ▶ my $c = shift;
Subroutine __ANON__: not called CC=1 SCAR=6.9
212 0 my $map = alpine_map($c);
213 0 $c->render(text => $map, format => 'txt');
214 11 };
215  
216 get '/alpine/document' => sub {
217 0 ▶ my $c = shift;
Subroutine __ANON__: not called CC=6 SCAR=37.4
218 # prepare a map for every step
219 0 my @maps;
220 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
221 # use the same seed for all the calls
222 0 my $seed = $c->param('seed');
223 0 ▶ if (not defined $seed) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $seed) 0 0 0
224 0 $seed = int(rand(1000000000));
225 0 $c->param('seed' => $seed);
226 }
227 # We'd like to use a smaller map because it is so slow, so default to height 5.
228 0 ▶ $c->param('height' => 5) unless $c->param('height');
Branch: 1 branch
BranchTrueFalseTotal
unless $c->param("height") 0 0 0
229 # Let's remember the $data so we can query it for the parameters used.
230 0 my ($map, $data);
231 0 for my $step (1 .. 19) {
232 0 ($map, $data) = alpine_map($c, $step);
233 0 my $mapper;
234 0 ▶ if ($type eq 'hex') {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq 'hex') { } 0 0 0
235 0 $mapper = Game::TextMapper::Mapper::Hex->new(dist_dir => $dist_dir);
236 } else {
237 0 $mapper = Game::TextMapper::Mapper::Square->new(dist_dir => $dist_dir);
238 }
239 0 my $svg = $mapper->initialize($map)->svg;
240 0 $svg =~ s/<\?xml version="1.0" encoding="UTF-8" standalone="no"\?>\n//g;
241 0 push(@maps, $svg);
242 };
243 0 $c->stash("maps" => \@maps);
244  
245 # Generate the documentation text based on the stashed maps.
246 0 $c->render(template => 'alpine_document',
247 seed => $seed,
248 width => $data->width,
249 height => $data->height,
250 steepness => $data->steepness,
251 peaks => $data->peaks,
252 peak => $data->peak,
253 bumps => $data->bumps,
254 bump => $data->bump,
255 bottom => $data->bottom,
256 arid => $data->arid,
257 climate => $data->climate);
258 11 };
259  
260 get '/alpine/random/interactive' => sub {
261 0 ▶ my $c = shift;
Subroutine __ANON__: not called CC=3 SCAR=24.8
262 0 my $map = alpine_map($c);
263 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
264 0 my $mapper;
265 0 ▶ if ($type eq 'hex') {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq 'hex') { } 0 0 0
266 0 $mapper = Game::TextMapper::Mapper::Hex->new(dist_dir => $dist_dir);
267 } else {
268 0 $mapper = Game::TextMapper::Mapper::Square->new(dist_dir => $dist_dir);
269 }
270 0 my $svg = $mapper->initialize($map)->svg;
271 0 $c->render(template => 'alpine_interactive',
272 map => $svg);
273 11 };
274  
275 get '/alpine/parameters' => sub {
276 0 ▶ my $c = shift;
Subroutine __ANON__: not called CC=1 SCAR=6.9
277 0 $c->render(template => 'alpine_parameters');
278 11 };
279  
280 get '/folkesten' => sub {
281 0 ▶ my $c = shift;
Subroutine __ANON__: not called CC=3 SCAR=24.8
282 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
283 0 $c->render(text => Game::TextMapper::Folkesten->new->generate_map());
284 } else {
285 0 $c->render(template => 'edit',
286 map => Game::TextMapper::Folkesten->new->generate_map());
287 }
288 11 };
289  
290 get '/folkesten/random' => sub {
291 0 ▶ my $c = shift;
Subroutine __ANON__: not called CC=1 SCAR=6.9
292 0 my $map = Game::TextMapper::Folkesten->new->generate_map();
293 0 my $svg = Game::TextMapper::Mapper::Hex->new(dist_dir => $dist_dir)
294 ->initialize($map)
295 ->svg();
296 0 $c->render(text => $svg, format => 'svg');
297 11 };
298  
299 get '/folkesten/random/text' => sub {
300 0 ▶ my $c = shift;
Subroutine __ANON__: not called CC=1 SCAR=6.9
301 0 my $text = Game::TextMapper::Folkesten->new->generate_map();
302 0 $c->render(text => $text, format => 'txt');
303 11 };
304  
305 get '/solo' => sub {
306 0 ▶ my $c = shift;
Subroutine __ANON__: not called CC=3 SCAR=24.8
307 0 my $mapper = Game::TextMapper::Solo->new($c->req->params->to_hash);
308 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
309 0 $c->render(text => $mapper->generate_map());
310 } else {
311 0 $c->render(template => 'edit', map => $mapper->generate_map());
312 }
313 11 };
314  
315 get '/solo/random' => sub {
316 0 ▶ my $c = shift;
Subroutine __ANON__: not called CC=1 SCAR=6.9
317 0 my $mapper = Game::TextMapper::Solo->new($c->req->params->to_hash);
318 0 my $map = $mapper->generate_map();
319 0 my $svg = Game::TextMapper::Mapper::Hex->new(dist_dir => $dist_dir)
320 ->initialize($map)
321 ->svg();
322 0 $c->render(text => $svg, format => 'svg');
323 11 };
324  
325 get '/solo/random/text' => sub {
326 0 ▶ my $c = shift;
Subroutine __ANON__: not called CC=1 SCAR=6.9
327 0 my $mapper = Game::TextMapper::Solo->new($c->req->params->to_hash);
328 0 my $text = $mapper->generate_map();
329 0 $c->render(text => $text, format => 'txt');
330 11 };
331  
332 # does not handle z coordinates
333 sub border_modification {
334 0 ▶ my ($map, $top, $left, $right, $bottom, $empty) = @_;
Subroutine border_modification: not called CC=38 SCAR=73.0
Pod undocumented
335 0 my (@lines, @temp, %seen);
336 0 my ($x, $y, $points, $text);
337 0 my ($minx, $miny, $maxx, $maxy);
338 # shift map around
339 0 foreach (split(/\r?\n/, $map)) {
340 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
341 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
342 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
343 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
344 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
345 0 my $point = Game::TextMapper::Point->new(x => $x + $left, y => $y + $top);
346 0 ▶ $seen{$point->coordinates} = 1 if $empty;
Branch: 1 branch
BranchTrueFalseTotal
if $empty 0 0 0
347 0 push(@lines, [$point, $text]);
348 } elsif (($points, $text) = /^(-?\d\d-?\d\d(?:--?\d\d-?\d\d)+)\s+(.*)/) {
349 0 my @numbers = $points =~ /\G(-?\d\d)(-?\d\d)-?/cg;
350 0 my @points;
351 0 ▶ while (@numbers) {
Branch: 1 branch
BranchTrueFalseTotal
if (@numbers) 0 0 0
352 0 my ($x, $y) = splice(@numbers, 0, 2);
353 0 push(@points, Game::TextMapper::Point->new(x => $x + $left, y => $y + $top));
354 }
355 0 push(@lines, [Game::TextMapper::Line->new(points => \@points), $text]);
356 } else {
357 0 push(@lines, $_);
358 }
359 }
360 # only now do we know the extent of the map
361 0 $maxx += $left + $right;
362 0 $maxy += $top + $bottom;
363 # with that information we can now determine what lies outside the map
364 0 @temp = ();
365 0 foreach (@lines) {
366 0 ▶ if (ref) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $_) { } 0 0 0
367 0 my ($it, $text) = @$_;
368 0 ▶ if (ref($it) eq 'Game::TextMapper::Point') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $it eq 'Game::TextMapper::Point') { } 0 0 0
369 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
370 and $it->y <= $maxy and $it->y >= $miny) {
371 0 push(@temp, $_);
372 }
373 } else { # Game::TextMapper::Line
374 my $outside = none {
375 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
376 and $_->y <= $maxy and $_->y >= $miny)
377 0 } @{$it->points};
378 0 ▶ push(@temp, $_) unless $outside;
Branch: 1 branch
BranchTrueFalseTotal
unless $outside 0 0 0
379 }
380 } else {
381 0 push(@temp, $_);
382 }
383 }
384 0 @lines = @temp;
385 # add missing hexes, if requested
386 0 ▶ if ($empty) {
Branch: 1 branch
BranchTrueFalseTotal
if ($empty) 0 0 0
387 0 for $x ($minx .. $maxx) {
388 0 for $y ($miny .. $maxy) {
389 0 my $point = Game::TextMapper::Point->new(x => $x, y => $y);
390 0 ▶ if (not $seen{$point->coordinates}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($seen{$point->coordinates}) 0 0 0
391 0 push(@lines, [$point, "empty"]);
392 }
393 }
394 }
395 # also, sort regions before trails before others
396 @lines = sort {
397 0 (# arrays before strings
398 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
399 # string comparison if both are strings
400 or not(ref($a)) and not(ref($b)) and $a cmp $b
401 # if we get here, we know both are arrays
402 # points before lines
403 or ref($b->[0]) cmp ref($a->[0])
404 # if both are points, compare the coordinates
405 or ref($a->[0]) eq 'Game::TextMapper::Point' and $a->[0]->cmp($b->[0])
406 # if both are lines, compare the first two coordinates (the minimum line length)
407 or ref($a->[0]) eq 'Game::TextMapper::Line' and ($a->[0]->points->[0]->cmp($b->[0]->points->[0])
408 or $a->[0]->points->[1]->cmp($b->[0]->points->[1]))
409 # if bot are the same point (!) …
410 or 0)
411 } @lines;
412 }
413 $map = join("\n",
414 map {
415 0 ▶ if (ref) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $_) { } 0 0 0
416 0 my ($it, $text) = @$_;
417 0 ▶ if (ref($it) eq 'Game::TextMapper::Point') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $it eq 'Game::TextMapper::Point') { } 0 0 0
418 0 Game::TextMapper::Point::coord($it->x, $it->y) . " " . $text
419 } else {
420 0 my $points = $it->points;
421 join("-",
422 0 map { Game::TextMapper::Point::coord($_->x, $_->y) } @$points)
423 . " " . $text;
424 }
425 } else {
426 0 $_;
427 }
428 } @lines) . "\n";
429 0 return $map;
430 }
431  
432 any '/borders' => sub {
433 0 ▶ my $c = shift;
Subroutine __ANON__: not called CC=1 SCAR=6.9
434 0 my $map = border_modification(map { $c->param($_) } qw(map top left right bottom empty));
435 0 $c->param('map', $map);
436 0 $c->render(template => 'edit', map => $map);
437 11 };
438  
439 sub island_map {
440 2 ▶ my $c = shift;
Subroutine island_map: called CC=5 SCAR=16.6
Pod undocumented
441 # must be able to override this for the documentation
442 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
443 # need to compute the seed here so that we can send along the URL
444 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
445 2 my $url = $c->url_with('islanddocument')->query({seed => $seed})->to_abs;
446 2 my @params = ($c->param('width'),
447 $c->param('height'),
448 $c->param('radius'),
449 $seed,
450 $url,
451 $step,
452 );
453 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
454 2 ▶ if ($type eq 'hex') {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq 'hex') { } 1 1 2
455 1 return Game::TextMapper::Schroeder::Island
456 ->with_roles('Game::TextMapper::Schroeder::Hex')->new()
457 ->generate_map(@params);
458 } else {
459 1 return Game::TextMapper::Schroeder::Island
460 ->with_roles('Game::TextMapper::Schroeder::Square')->new()
461 ->generate_map(@params);
462 }
463 }
464  
465 get '/island' => sub {
466 0 ▶ my $c = shift;
Subroutine __ANON__: not called CC=3 SCAR=24.8
467 0 my $map = island_map($c);
468 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
469 0 $c->render(text => $map);
470 } else {
471 0 $c->render(template => 'edit', map => $map);
472 }
473 11 };
474  
475 get '/island/random' => sub {
476 2 ▶ my $c = shift;
Subroutine __ANON__: called CC=3 SCAR=11.0
477 2 my $map = island_map($c);
478 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
479 2 my $mapper;
480 2 ▶ if ($type eq 'hex') {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq 'hex') { } 1 1 2
481 1 $mapper = Game::TextMapper::Mapper::Hex->new(dist_dir => $dist_dir);
482 } else {
483 1 $mapper = Game::TextMapper::Mapper::Square->new(dist_dir => $dist_dir);
484 }
485 2 my $svg = $mapper->initialize($map)->svg;
486 2 $c->render(text => $svg, format => 'svg');
487 11 };
488  
489 sub archipelago_map {
490 0 ▶ my $c = shift;
Subroutine archipelago_map: not called CC=5 SCAR=34.0
Pod undocumented
491 # must be able to override this for the documentation
492 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
493 # need to compute the seed here so that we can send along the URL
494 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
495 0 my $url = $c->url_with('archipelagodocument')->query({seed => $seed})->to_abs;
496 0 my @params = ($c->param('width'),
497 $c->param('height'),
498 $c->param('concentration'),
499 $c->param('eruptions'),
500 $c->param('top'),
501 $c->param('bottom'),
502 $seed,
503 $url,
504 $step,
505 );
506 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
507 0 ▶ if ($type eq 'hex') {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq 'hex') { } 0 0 0
508 0 return Game::TextMapper::Schroeder::Archipelago
509 ->with_roles('Game::TextMapper::Schroeder::Hex')->new()
510 ->generate_map(@params);
511 } else {
512 0 return Game::TextMapper::Schroeder::Archipelago
513 ->with_roles('Game::TextMapper::Schroeder::Square')->new()
514 ->generate_map(@params);
515 }
516 }
517  
518 get '/archipelago' => sub {
519 0 ▶ my $c = shift;
Subroutine __ANON__: not called CC=3 SCAR=24.8
520 0 my $map = archipelago_map($c);
521 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
522 0 $c->render(text => $map);
523 } else {
524 0 $c->render(template => 'edit', map => $map);
525 }
526 11 };
527  
528 get '/archipelago/random' => sub {
529 0 ▶ my $c = shift;
Subroutine __ANON__: not called CC=3 SCAR=24.8
530 0 my $map = archipelago_map($c);
531 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
532 0 my $mapper;
533 0 ▶ if ($type eq 'hex') {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq 'hex') { } 0 0 0
534 0 $mapper = Game::TextMapper::Mapper::Hex->new(dist_dir => $dist_dir);
535 } else {
536 0 $mapper = Game::TextMapper::Mapper::Square->new(dist_dir => $dist_dir);
537 }
538 0 my $svg = $mapper->initialize($map)->svg;
539 0 $c->render(text => $svg, format => 'svg');
540 11 };
541  
542 sub gridmapper_map {
543 1 ▶ my $c = shift;
Subroutine gridmapper_map: called CC=5 SCAR=17.5
Pod undocumented
544 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
545 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
546 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
547 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
548 1 srand($seed);
549 1 return Game::TextMapper::Gridmapper->new()
550 ->generate_map($pillars, $rooms, $caves);
551 }
552  
553 get '/gridmapper' => sub {
554 0 ▶ my $c = shift;
Subroutine __ANON__: not called CC=3 SCAR=24.8
555 0 my $map = gridmapper_map($c);
556 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
557 0 $c->render(text => $map);
558 } else {
559 0 $c->render(template => 'edit', map => $map);
560 }
561 11 };
562  
563 get '/gridmapper/random' => sub {
564 1 ▶ my $c = shift;
Subroutine __ANON__: called CC=1 SCAR=0.0
565 1 my $map = gridmapper_map($c);
566 1 my $mapper = Game::TextMapper::Mapper::Square->new(dist_dir => $dist_dir);
567 1 my $svg = $mapper->initialize($map)->svg;
568 1 $c->render(text => $svg, format => 'svg');
569 11 };
570  
571 get '/gridmapper/random/text' => sub {
572 0 ▶ my $c = shift;
Subroutine __ANON__: not called CC=1 SCAR=6.9
573 0 my $map = gridmapper_map($c);
574 0 $c->render(text => $map, format => 'txt');
575 11 };
576  
577 sub apocalypse_map {
578 1 ▶ my $c = shift;
Subroutine apocalypse_map: called CC=2 SCAR=7.2
Pod undocumented
579 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
580 1 srand($seed);
581 1 my $hash = $c->req->params->to_hash;
582 1 return Game::TextMapper::Apocalypse->new(%$hash)
583 ->generate_map();
584 }
585  
586 get '/apocalypse' => sub {
587 0 ▶ my $c = shift;
Subroutine __ANON__: not called CC=3 SCAR=24.8
588 0 my $map = apocalypse_map($c);
589 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
590 0 $c->render(text => $map);
591 } else {
592 0 $c->render(template => 'edit', map => $map);
593 }
594 11 };
595  
596 get '/apocalypse/random' => sub {
597 1 ▶ my $c = shift;
Subroutine __ANON__: called CC=1 SCAR=0.0
598 1 my $map = apocalypse_map($c);
599 1 my $mapper = Game::TextMapper::Mapper::Hex->new(dist_dir => $dist_dir);
600 1 my $svg = $mapper->initialize($map)->svg;
601 1 $c->render(text => $svg, format => 'svg');
602 11 };
603  
604 get '/apocalypse/random/text' => sub {
605 0 ▶ my $c = shift;
Subroutine __ANON__: not called CC=1 SCAR=6.9
606 0 my $map = apocalypse_map($c);
607 0 $c->render(text => $map, format => 'txt');
608 11 };
609  
610 sub star_map {
611 1 ▶ my $c = shift;
Subroutine star_map: called CC=2 SCAR=7.2
Pod undocumented
612 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
613 1 srand($seed);
614 1 my $hash = $c->req->params->to_hash;
615 1 return Game::TextMapper::Traveller->new(%$hash)->generate_map();
616 }
617  
618 get '/traveller' => sub {
619 0 ▶ my $c = shift;
Subroutine __ANON__: not called CC=3 SCAR=24.8
620 0 my $map = star_map($c);
621 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
622 0 $c->render(text => $map);
623 } else {
624 0 $c->render(template => 'edit', map => $map);
625 }
626 11 };
627  
628 get '/traveller/random' => sub {
629 1 ▶ my $c = shift;
Subroutine __ANON__: called CC=1 SCAR=0.0
630 1 my $map = star_map($c);
631 1 my $mapper = Game::TextMapper::Mapper::Hex->new(dist_dir => $dist_dir);
632 1 my $svg = $mapper->initialize($map)->svg;
633 1 $c->render(text => $svg, format => 'svg');
634 11 };
635  
636 get '/traveller/random/text' => sub {
637 0 ▶ my $c = shift;
Subroutine __ANON__: not called CC=1 SCAR=6.9
638 0 my $map = star_map($c);
639 0 $c->render(text => $map, format => 'txt');
640 11 };
641  
642 get '/help' => sub {
643 0 ▶ my $c = shift;
Subroutine __ANON__: not called CC=3 SCAR=24.8
644  
645 0 seek(DATA,0,0);
646 0 local $/ = undef;
647 0 my $pod = <DATA>;
648 0 $pod =~ s/=head1 NAME\n.*=head1 DESCRIPTION/=head1 Text Mapper/gs;
649 0 my $parser = Pod::Simple::HTML->new;
650 0 $parser->html_header_after_title('');
651 0 $parser->html_header_before_title('');
652 0 $parser->title_prefix('<!--');
653 0 $parser->title_postfix('-->');
654 0 my $html;
655 0 $parser->output_string(\$html);
656 0 $parser->parse_string_document($pod);
657  
658 0 my $dom = Mojo::DOM->new($html);
659 0 for my $pre ($dom->find('pre')->each) {
660 0 my $map = $pre->text;
661 0 $map =~ s/^ //mg;
662 0 ▶ next if $map =~ /^perl/; # how to call it
Branch: 1 branch
BranchTrueFalseTotal
if $map =~ /^perl/u 0 0 0
663 0 my $url = $c->url_for('render')->query(map => $map);
664 0 $pre->replace("<pre>" . xml_escape($map) . "</pre>\n"
665 . qq{<p class="example"><a href="$url">Render this example</a></p>});
666 }
667  
668 0 $c->render(html => $dom);
669 11 };
670  
671 11 app->start;
672  
673 __DATA__
↑ Summary blib/lib/Game/TextMapper/Gridmapper.pm »