script/traveller

filter: Statementstmt 42.7% 71 / 166 Branchbran 6.2% 1 / 16 Conditioncond 7.1% 1 / 14 MC/DCmcdc 0.0% 0 / 8 Subroutinesub 53.3% 16 / 30 Podpod n/a totaltotal 38.0% 89 / 234 CC 15 SCAR 24.2
CC
15
Cov
37%
__ANON__
42.0
__ANON__
30.0
mapper
12.0
CRAP 11.2
« lib/Traveller/System.pm ↑ Summary lib/Traveller/Subsector.pm »
1 #!/usr/bin/perl
2 # Copyright (C) 2009-2021 Alex Schroeder <alex@gnu.org>
3 # Copyright (C) 2020 Christian Carey
4 #
5 # This program is free software: you can redistribute it and/or modify it under
6 # the terms of the GNU General Public License as published by the Free Software
7 # Foundation, either version 3 of the License, or (at your option) any later
8 # version.
9 #
10 # This program is distributed in the hope that it will be useful, but WITHOUT
11 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License along with
15 # this program. If not, see <http://www.gnu.org/licenses/>.
16  
17 # Use the library matching the installation location of the script being called.
18 2 ▶use FindBin;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 2 ▶use lib "$FindBin::Bin/../lib";
Subroutine BEGIN: called CC=1 SCAR=0.0
20  
21 package Traveller;
22 2 ▶use Traveller::Subsector;
Subroutine BEGIN: called CC=1 SCAR=0.0
23 2 ▶use Traveller::Mapper::Classic::MPTS;
Subroutine BEGIN: called CC=1 SCAR=0.0
24 2 ▶use Traveller::Mapper::Classic;
Subroutine BEGIN: called CC=1 SCAR=0.0
25 2 ▶use Traveller::Mapper;
Subroutine BEGIN: called CC=1 SCAR=0.0
26 2 ▶use Traveller::Util qw(flush);
Subroutine BEGIN: called CC=1 SCAR=0.0
27 2 ▶use Modern::Perl;
Subroutine BEGIN: called CC=1 SCAR=0.0
28 2 ▶use Mojolicious::Lite;
Subroutine BEGIN: called CC=1 SCAR=0.0
29 2 ▶use POSIX qw(INT_MAX);
Subroutine BEGIN: called CC=1 SCAR=0.0
30 2 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
31  
32 1 ▶get '/' => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
33 1 my $c = shift;
34 1 $c->redirect_to('main');
35 2 };
36  
37 0 ▶get '/random' => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
38 0 my $c = shift;
39 0 my $id = int(rand(INT_MAX));
40 0 $c->redirect_to($c->url_for('uwp', size => 'subsector', rules => 'mgp', id => $id));
41 2 };
42  
43 1 ▶get '/random/:size' => [size => ['subsector', 'sector']] => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
44 1 my $c = shift;
45 1 my $size = $c->param('size');
46 1 my $id = int(rand(INT_MAX));
47 1 $c->redirect_to($c->url_for('uwp', size => $size, rules => 'mgp', id => $id));
48 2 };
49  
50 0 ▶get '/random/:size/:rules' => [size => ['subsector', 'sector']] => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
51 0 my $c = shift;
52 0 my $size = $c->param('size');
53 0 my $rules = $c->param('rules');
54 0 my $density = $c->param('density');
55 0 my $id = int(rand(INT_MAX));
56 0 $c->redirect_to($c->url_for('uwp', size => $size, rules => $rules, id => $id)->query(density => $density));
57 2 } => 'random';
58  
59 0 ▶get '/:id' => [id => qr/\d+/] => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
60 0 my $c = shift;
61 0 my $id = $c->param('id');
62 0 $c->redirect_to($c->url_for('uwp', size => 'subsector', rules => 'mgp', id => $id));
63 2 };
64  
65 0 ▶get '/uwp/:id' => [id => qr/\d+/] => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
66 0 my $c = shift;
67 0 my $id = $c->param('id');
68 0 $c->redirect_to($c->url_for('uwp', size => 'subsector', rules => 'mgp', id => $id));
69 2 };
70  
71 0 ▶get '/uwp/:size/:id' => [size => ['subsector', 'sector']] => [id => qr/\d+/] => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
72 0 my $c = shift;
73 0 my $size = $c->param('size');
74 0 my $id = $c->param('id');
75 0 $c->redirect_to($c->url_for('uwp', size => $size, rules => 'mgp', id => $id));
76 2 };
77  
78 1 ▶get '/uwp/:size/:rules/:id' => [size => ['subsector', 'sector']] => [id => qr/\d+/] => sub {
Subroutine __ANON__: called CC=3 SCAR=11.4
79 1 my $c = shift;
80 1 my $size = $c->param('size');
81 1 my $rules = $c->param('rules');
82 1 my $id = $c->param('id');
83 1 ▶ my $density = $c->param('density') || 50;
Condition50%1/2
$c->param('density') || 50
l!l
01
MC/DC0%0/1
$c->param('density') || 50
$c->param('density')
Truth table50%1/2
A
A= $c->param('density')
Aresult
11
00
84 1 srand($id);
85 1 ▶ if ($size eq 'sector') {
Branch: 1 branch
BranchTrueFalseTotal
if ($size eq 'sector') { } 0 1 1
86 0 my $uwp = subsector()->init(32, 40, $rules, $density/100)->str;
87 0 $c->render(template => 'uwp-sector', id => $id, rules => $rules, uwp => $uwp, density => $density);
88 } else {
89 1 my $uwp = subsector()->init(8, 10, $rules, $density/100)->str;
90 1 $c->render(template => 'uwp', id => $id, rules => $rules, uwp => $uwp, density => $density);
91 }
92 1 flush();
93 2 } => 'uwp';
94  
95 1 ▶any '/edit' => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
96 1 my $c = shift;
97 1 my $uwp = $c->param('map');
98 1 $c->render(template => 'edit', uwp => Traveller::Mapper::example(), size => 'subsector', rules => 'mgp', id => '');
99 2 } => 'main';
100  
101 0 ▶get '/edit/:id' => [id => qr/\d+/] => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
102 0 my $c = shift;
103 0 my $id = $c->param('id');
104 0 $c->redirect_to($c->url_for('edit', size => 'subsector', rules => 'mgp', id => $id));
105 2 };
106  
107 0 ▶get '/edit/:size/:id' => [size => ['subsector', 'sector']] => [id => qr/\d+/] => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
108 0 my $c = shift;
109 0 my $size = $c->param('size');
110 0 my $id = $c->param('id');
111 0 $c->redirect_to($c->url_for('edit', size => $size, rules => 'mgp', id => $id));
112 2 };
113  
114 0 ▶get '/edit/:size/:rules/:id' => [size => ['subsector', 'sector']] => [id => qr/\d+/] => sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
115 0 my $c = shift;
116 0 my $size = $c->param('size');
117 0 my $rules = $c->param('rules');
118 0 my $id = $c->param('id');
119 0 my $density = $c->param('density');
120 0 srand($id);
121 0 ▶ if ($size eq 'sector') {
Branch: 1 branch
BranchTrueFalseTotal
if ($size eq 'sector') { } 0 0 0
122 0 my $uwp = subsector()->init(32, 40, $rules, $density)->str;
123 0 $c->render(template => 'edit-sector', id => $id, rules => $rules, uwp => $uwp);
124 } else {
125 0 my $uwp = subsector()->init(8, 10, $rules, $density)->str;
126 0 $c->render(template => 'edit', id => $id, rules => $rules, uwp => $uwp);
127 }
128 0 flush();
129 2 } => 'edit';
130  
131 # → see any '/map' below!
132 # get '/map' => sub {
133 # my $c = shift;
134 # $c->render(template => 'map_all', uwp => Traveller::Mapper::example(), size => 'subsector', rules => 'mgp');
135 # };
136  
137 0 ▶get '/map/:id' => [id => qr/\d+/] => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
138 0 my $c = shift;
139 0 my $id = $c->param('id');
140 0 $c->redirect_to($c->url_for('map_all', size => 'subsector', rules => 'mgp', id => $id));
141 2 };
142  
143 0 ▶get '/map/:size/:id' => [size => ['subsector', 'sector']] => [id => qr/\d+/] => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
144 0 my $c = shift;
145 0 my $size = $c->param('size');
146 0 my $id = $c->param('id');
147 0 $c->redirect_to($c->url_for('map_all', size => $size, rules => 'mgp', id => $id));
148 2 };
149  
150 0 ▶get '/map/:size/:rules/:id' => [size => ['subsector', 'sector']] => [id => qr/\d+/] => sub {
Subroutine __ANON__: not called CC=5 SCAR=34.0
151 0 my $c = shift;
152 0 my $size = $c->param('size');
153 0 my $rules = $c->param('rules');
154 0 my $id = $c->param('id');
155 0 my $wiki = $c->param('wiki');
156 0 ▶ my $density = $c->param('density') || 50;
Condition0%0/2
$c->param('density') || 50
l!l
00
MC/DC0%0/1
$c->param('density') || 50
$c->param('density')
Truth table0%0/2
A
A= $c->param('density')
Aresult
11
00
157 0 srand($id);
158 0 my $map = mapper($rules);
159 0 my $uwp;
160 0 ▶ if ($size eq 'sector') {
Branch: 1 branch
BranchTrueFalseTotal
if ($size eq 'sector') { } 0 0 0
161 0 $uwp = subsector()->init(32, 40, $rules, $density/100)->str;
162 } else {
163 0 $uwp = subsector()->init(8, 10, $rules, $density/100)->str;
164 }
165 0 my $url = $c->url_for('uwp', size => $size, rules => $rules, id => $id);
166 0 ▶ $url = $url->query(density => $density) if $density and $density != 50;
Branch: 1 branch
BranchTrueFalseTotal
if $density and $density != 50 0 0 0
Condition0%0/3
$density and $density != 50
!ll&&!rl&&r
000
MC/DC0%0/2
$density and $density != 50
$density $density != 50
Truth table0%0/3
A and B
A= $densityB= $density != 50
ABresult
0X0
100
111
167 0 $map->initialize($uwp, $wiki, $url);
168 0 $map->communications();
169 0 $map->trade();
170 0 flush();
171 0 $c->render(text => $map->svg, format => 'svg');
172 2 } => 'map_all';
173  
174 0 ▶any '/map' => sub {
Subroutine __ANON__: not called CC=6 SCAR=37.4
175 0 my $c = shift;
176 0 my $wiki = $c->param('wiki');
177 0 my $trade = $c->param('trade');
178 0 ▶ my $uwp = $c->param('map') || Traveller::Mapper::example();
Condition0%0/3
$c->param('map') || Traveller::Mapper::example()
l!l&&r!l&&!r
000
MC/DC0%0/2
$c->param('map') || Traveller::Mapper::example()
$c->param('map') Traveller::Mapper::example()
Truth table0%0/3
A || B
A= $c->param('map')B= Traveller::Mapper::example()
ABresult
1X1
011
000
179 0 ▶ my $size = $c->param('size') || 'subsector';
Condition0%0/2
$c->param('size') || 'subsector'
l!l
00
MC/DC0%0/1
$c->param('size') || 'subsector'
$c->param('size')
Truth table0%0/2
A
A= $c->param('size')
Aresult
11
00
180 0 ▶ my $rules = $c->param('rules') || 'mgp';
Condition0%0/2
$c->param('rules') || 'mgp'
l!l
00
MC/DC0%0/1
$c->param('rules') || 'mgp'
$c->param('rules')
Truth table0%0/2
A
A= $c->param('rules')
Aresult
11
00
181 0 my $source;
182 0 ▶ if (!$uwp) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($uwp) 0 0 0
183 0 my $id = int(rand(INT_MAX));
184 0 srand($id);
185 0 $uwp = subsector()->init(8, 10, $rules)->str;
186 0 $source = $c->url_for('uwp', id => $id);
187 }
188 0 my $map = mapper($rules);
189 0 $map->initialize($uwp, $wiki, $source);
190 0 $map->communications();
191 0 $map->trade();
192 0 flush();
193 0 ▶ if ($trade) {
Branch: 1 branch
BranchTrueFalseTotal
if ($trade) { } 0 0 0
194 0 $c->render(text => $map->text, format => 'txt');
195 } else {
196 0 $c->render(text => $map->svg, format => 'svg');
197 }
198 2 } => 'map';
199  
200 0 ▶get '/help' => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
201 0 my $c = shift;
202 0 my $classic = $c->param('classic');
203 0 my $mpts = $c->param('mpts');
204 0 $c->render(classic => $classic, mpts => $mpts);
205 2 };
206  
207 1 ▶sub subsector {
Subroutine subsector: called CC=1 SCAR=0.0
208 1 return Traveller::Subsector->new;
209 }
210  
211 0 ▶sub mapper {
Subroutine mapper: not called CC=3 SCAR=24.8
212 0 my $rules = shift;
213 0 ▶ if ($rules eq 'mpts') {
Branch: 2 branches
BranchTrueFalseTotal
if ($rules eq 'mpts') { } 0 0 0
elsif ($rules eq 'ct') { } 0 0 0
214 0 return Traveller::Mapper::Classic::MPTS->new;
215 } elsif ($rules eq 'ct') {
216 0 return Traveller::Mapper::Classic->new;
217 } else {
218 0 return Traveller::Mapper->new;
219 }
220 }
221  
222 2 app->start;
223  
224 __DATA__
« lib/Traveller/System.pm ↑ Summary lib/Traveller/Subsector.pm »