CLI.pm

filter: Statementstmt 24.6% 78 / 317 Branchbran 0.0% 0 / 144 Conditioncond 0.0% 0 / 58 MC/DCmcdc 0.0% 0 / 32 Subroutinesub 65.0% 26 / 40 Podpod 66.6% 2 / 3 totaltotal 17.8% 106 / 594 CC 107 SCAR 59.4
CC
107
Cov
15%
run
912.6
_validate_param
650.0
_identify_station
306.0
CRAP 378.4
↑ Summary CLI/Option.pm »
1 package Map::Tube::CLI;
2  
3 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 3 ▶use version;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 3 our $VERSION = qv('v1.1.0');
8 3 our $AUTHORITY = 'cpan:MANWAR';
9  
10 =head1 NAME
11  
12 Map::Tube::CLI - Command Line Interface for Map::Tube::* map.
13  
14 =head1 VERSION
15  
16 Version v1.1.0
17  
18 =cut
19  
20 3 ▶use 5.014;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 3 ▶use utf8::all;
Subroutine BEGIN: called CC=1 SCAR=0.0
22 3 ▶use Map::Tube::Utils qw(is_valid_color);
Subroutine BEGIN: called CC=1 SCAR=0.0
23 3 ▶use Map::Tube::Exception::FoundUnsupportedMap;
Subroutine BEGIN: called CC=1 SCAR=0.0
24 3 ▶use Map::Tube::Exception::InvalidBackgroundColor;
Subroutine BEGIN: called CC=1 SCAR=0.0
25 3 ▶use Map::Tube::Exception::InvalidLineName;
Subroutine BEGIN: called CC=1 SCAR=0.0
26 3 ▶use Map::Tube::Exception::InvalidStationName;
Subroutine BEGIN: called CC=1 SCAR=0.0
27 3 ▶use Map::Tube::Exception::MissingStationName;
Subroutine BEGIN: called CC=1 SCAR=0.0
28 3 ▶use Map::Tube::Exception::MissingMapName;
Subroutine BEGIN: called CC=1 SCAR=0.0
29 3 ▶use Map::Tube::Exception::MissingSupportedMap;
Subroutine BEGIN: called CC=1 SCAR=0.0
30 3 ▶use Map::Tube::CLI::Option;
Subroutine BEGIN: called CC=1 SCAR=0.0
31 # Defined in a BEGIN block because Module::Pluggable's 'only' option below is
32 # evaluated at compile time, i.e. before any ordinary sub further down this file
33 # would exist.
34 3 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
35 3 my %SUPPORTED_MAPS = (
36 'ATHENS' => 'Map::Tube::Athens',
37 'BARCELONA' => 'Map::Tube::Barcelona',
38 'BEIJING' => 'Map::Tube::Beijing',
39 'BERLIN' => 'Map::Tube::Berlin',
40 'BIELEFELD' => 'Map::Tube::Bielefeld',
41 'BUCHAREST' => 'Map::Tube::Bucharest',
42 'BRUSSELS' => 'Map::Tube::Brussels',
43 'BUDAPEST' => 'Map::Tube::Budapest',
44 'CHICAGO' => 'Map::Tube::Chicago',
45 'COPENHAGEN' => 'Map::Tube::Copenhagen',
46 'DELHI' => 'Map::Tube::Delhi',
47 'DNIPROPETROVSK' => 'Map::Tube::Dnipropetrovsk',
48 'FRANKFURT' => 'Map::Tube::Frankfurt',
49 'GLASGOW' => 'Map::Tube::Glasgow',
50 'HAMBURG' => 'Map::Tube::Hamburg',
51 'HANNOVER' => 'Map::Tube::Hannover',
52 'HONGKONG' => 'Map::Tube::Hongkong',
53 'KAZAN' => 'Map::Tube::Kazan',
54 'KHARKIV' => 'Map::Tube::Kharkiv',
55 'KIEV' => 'Map::Tube::Kiev',
56 'KOELNBONN' => 'Map::Tube::KoelnBonn',
57 'KOLKATTA' => 'Map::Tube::Kolkatta',
58 'KUALALUMPUR' => 'Map::Tube::KualaLumpur',
59 'LEIPZIG' => 'Map::Tube::Leipzig',
60 'LONDON' => 'Map::Tube::London',
61 'LYON' => 'Map::Tube::Lyon',
62 'MADRID' => 'Map::Tube::Madrid',
63 'MALAGA' => 'Map::Tube::Malaga',
64 'MILAN' => 'Map::Tube::Milan',
65 'MINSK' => 'Map::Tube::Minsk',
66 'MOSCOW' => 'Map::Tube::Moscow',
67 'MUENCHEN' => 'Map::Tube::Muenchen',
68 'NAPOLI' => 'Map::Tube::Napoli',
69 'NUREMBERG' => 'Map::Tube::Nuremberg',
70 'NYC' => 'Map::Tube::NYC',
71 'NANJING' => 'Map::Tube::Nanjing',
72 'NIZHNYNOVGOROD' => 'Map::Tube::NizhnyNovgorod',
73 'NOVOSIBIRSK' => 'Map::Tube::Novosibirsk',
74 'OSLO' => 'Map::Tube::Oslo',
75 'PARIS' => 'Map::Tube::Paris',
76 'PRAGUE' => 'Map::Tube::Prague',
77 'RHEINRUHR' => 'Map::Tube::RheinRuhr',
78 'ROME' => 'Map::Tube::Rome',
79 'SAINTPETERSBURG' => 'Map::Tube::SaintPetersburg',
80 'SAMARA' => 'Map::Tube::Samara',
81 'SANFRANCISCO' => 'Map::Tube::SanFrancisco',
82 'SINGAPORE' => 'Map::Tube::Singapore',
83 'SOFIA' => 'Map::Tube::Sofia',
84 'STOCKHOLM' => 'Map::Tube::Stockholm',
85 'STUTTGART' => 'Map::Tube::Stuttgart',
86 'SYDNEY' => 'Map::Tube::Sydney',
87 'TBILISI' => 'Map::Tube::Tbilisi',
88 'TOKYO' => 'Map::Tube::Tokyo',
89 'TOULOUSE' => 'Map::Tube::Toulouse',
90 'VIENNA' => 'Map::Tube::Vienna',
91 'WARSAW' => 'Map::Tube::Warsaw',
92 'YEKATERINBURG' => 'Map::Tube::Yekaterinburg',
93 );
94  
95 3 ▶ sub supported_maps { return { %SUPPORTED_MAPS } }
Subroutine supported_maps: called CC=1 SCAR=0.0
Pod documented
96  
97 }
98  
99 # Only the officially supported maps are scanned and loaded. Everything else
100 # under Map::Tube::* (Map::Tube::Server, Map::Tube::Node, ...) is skipped, so a
101 # missing dependency of an unrelated module cannot produce warnings here.
102 use Module::Pluggable
103 3 ▶ search_path => [ 'Map::Tube' ],
Subroutine BEGIN: called CC=1 SCAR=0.0
104 3 only => [ values %{ supported_maps() } ],
105 require => 1,
106 inner => 0,
107 3 max_depth => 3;
108  
109 # use Path::Tiny;
110 3 ▶use Text::ASCIITable;
Subroutine BEGIN: called CC=1 SCAR=0.0
111 3 ▶use Try::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
112 3 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
113 3 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
114 3 ▶use MooX::Options;
Subroutine BEGIN: called CC=1 SCAR=0.0
115 3 with 'Map::Tube::CLI::Option';
116  
117 =head1 DESCRIPTION
118  
119 This module provides a simple command line interface to the package consuming L<Map::Tube>.
120 The distribution also contains a script C<map-tube> for use at the command line which uses this package.
121  
122 =head1 SYNOPSIS
123  
124 You can list all command line options by giving the C<-h> flag.
125  
126 $ map-tube -h
127 USAGE: map-tube [-h] [options...]
128  
129 -m --map=String Map name
130 -s --start=String Start station name
131 -e --end=String End station name
132 -p --preferred Show preferred route
133 -g --generate_map Generate map as image
134 -i --image=String Name of image file or format (optional; default
135 format: PNG)
136 --layout=String Layout strategy for image (default: dot)
137 -b --bgcolor=String Map background color
138 -l --line=String Line name to map
139 --line_mappings Generate line mappings as table
140 --line_notes Generate line notes
141 -M --list_maps List supported maps
142 -L --list_lines List lines in given map
143 -S --list_stations List stations in given map
144 -F --fuzzy Fuzzy station name matching (on by default if
145 needed; switch off with --no-fuzzy)
146 -P --penalty=Real Change hop count penalty for line changes (default: 0.5)
147 -t --tabular Show routes and notes in tabular format
148 -f --force Force unsupported map (map name becomes case sensitive)
149 -D --debug Run in debug mode
150 -V --version Show version information
151  
152 --usage show a short help message
153 -h show a compact help message
154 --help show a long help message
155 --man show the manual
156  
157 =head1 COMMON USAGES
158  
159 =head2 Finding the Shortest Route
160  
161 =head3 Shortest Route
162  
163 You can ask for the shortest route in the London Tube Map as below: (Under Windows use double quotes.)
164  
165 $ map-tube --map London --start 'Baker Street' --end 'Wembley Park'
166  
167 Baker Street (Bakerloo, Circle, Hammersmith & City, Jubilee, Metropolitan), Finchley Road (Jubilee, Metropolitan), Wembley Park (Jubilee, Metropolitan)
168  
169 If any of the station names does not exist literally (up to capitalisation),
170 fuzzy matching will be attempted. If this yields unique stations, they will be
171 used. Otherwise, the candidate stations are displayed and no route will be
172 calculated. You can always force fuzzy matching by adding the "--fuzzy"
173 command line argument.
174  
175 =head3 Preferred Shortest Route
176  
177 Now a request for the preferred route:
178  
179 $ map-tube --map London --start 'Baker Street' --end 'Euston Square' --preferred
180  
181 Baker Street (Circle, Hammersmith & City, Metropolitan), Great Portland Street (Circle, Hammersmith & City, Metropolitan), Euston Square (Circle, Hammersmith & City, Metropolitan)
182  
183 =head3 Preferred Shortest Route in Tabular Form
184  
185 And a request for the preferred route displayed as a table: (This also shows the use of short options.)
186  
187 $ map-tube -m London -s 'Baker Street' -e 'Euston Square' -p -t
188 Metro Map London: Route from Baker Street to Euston Square.
189  
190 .--------------------------------------------------------------------.
191 | Station Name | Lines |
192 +-----------------------+--------------------------------------------+
193 | Baker Street | Circle, Hammersmith and City, Metropolitan |
194 | Great Portland Street | Circle, Hammersmith and City, Metropolitan |
195 | Euston Square | Circle, Hammersmith and City, Metropolitan |
196 '-----------------------+--------------------------------------------'
197  
198 Baker Street (Circle, Hammersmith & City, Metropolitan), Great Portland Street (Circle, Hammersmith & City, Metropolitan), Euston Square (Circle, Hammersmith & City, Metropolitan)
199  
200 =head3 Handling of Tube Line Changes
201  
202 Counting the number of hops is one valid way to measure the distance between two stations.
203 Practically speaking, however, having to change lines will add to the perceived distance.
204 To account for this, Map::Tube puts a penalty of one half hop on each line change required,
205 i.e., routes with fewer line changes are slightly more welcome. You can either switch off
206 this behaviour by
207  
208 $ map-tube -m London -s 'Baker Street' -e 'Euston Square' --penalty 0
209  
210 or put an even heavier penalty on line changes:
211  
212 $ map-tube -m London -s 'Baker Street' -e 'Euston Square' --penalty 2
213  
214 (In this particular case, the output will be identical because there are no line changes involved.)
215  
216 =head3 Station Names
217  
218 Ideally you will know the exact names of the stations, like in the
219 examples above. If you don't, you can always get a full list of station
220 names with the C<--list-stations> argument (cf. below). But Map::Tube
221 tries to help you if it cannot find the exact station name (case never
222 matters anyway). In this case, it will try to find a similar name.
223 (What exactly is meant by "similar" is a bit involved; never mind.) If
224 it finds a unique candidate, it will use that and notify you that it did
225 some guessing:
226  
227 $ map-tube -m London -s Baker -e 'Euston Square'
228 Metro Map London: Route from Baker Street (guessed) to Euston Square.
229  
230 .--------------------------------------------------------------------.
231 | Station Name | Lines |
232 +-----------------------+--------------------------------------------+
233 | Baker Street | Circle, Hammersmith and City, Metropolitan |
234 | Great Portland Street | Circle, Hammersmith and City, Metropolitan |
235 | Euston Square | Circle, Hammersmith and City, Metropolitan |
236 '-----------------------+--------------------------------------------'
237  
238 If no clear best guess can be found, you will be offered with some possibilities:
239  
240 $ map-tube -m London -s "Back Street" -e 'Euston Square'
241 Map::Tube::CLI::run(): ERROR: Invalid Station Name [Back Street]; maybe one of Baker Street
242 (Bakerloo, Circle, Hammersmith and City, Jubilee, Metropolitan), Becontree (District),
243 Bond Street (Central, Elizabeth, Jubilee), Old Street (Northern), Wood Street (Weaver)?
244 (status: 101) file C:/Strawberry/perl/site/lib/Map/Tube/CLI.pm on line 454
245  
246 You can also use regular expressions:
247  
248 $ map-tube -m London -s "Bak.*St.*" -e 'Euston Square'
249 Metro Map London: Route from Baker Street (guessed) to Euston Square.
250  
251 .--------------------------------------------------------------------.
252 | Station Name | Lines |
253 +-----------------------+--------------------------------------------+
254 | Baker Street | Circle, Hammersmith and City, Metropolitan |
255 | Great Portland Street | Circle, Hammersmith and City, Metropolitan |
256 | Euston Square | Circle, Hammersmith and City, Metropolitan |
257 '-----------------------+--------------------------------------------'
258  
259 If you can always force fuzzy matching with the argument C<--fuzzy>, or you can
260 completely disable it with C<--no-fuzzy>.
261  
262  
263 =head2 Images of Maps
264  
265 =head3 Generate an Image of the Full Map
266  
267 To generate a graphical representation of the entire map, follow the command
268 below. This will generate a PNG file named after the map in your current working
269 directory. (It will silently overwrite any pre-existing file of the same name.)
270  
271 $ map-tube --map Delhi --generate_map
272  
273 In case you want a different background color to the map then you can try this:
274  
275 $ map-tube --map Delhi --bgcolor gray --generate_map
276  
277 The output file name is chosen automatically according to the map. It will be displayed
278 on the console. If you want a different file name, do this:
279  
280 $ map-tube --map Delhi --generate_map --image Delhicious.png
281  
282 This allows you also to pick other output formats than PNG. E.g., you might
283 want a vector graphics file:
284  
285 $ map-tube --map Delhi --generate_map --image Delhivector.svg
286  
287 Or if you are happy with the default file name but still want to have a non-standard format:
288  
289 $ map-tube --map Delhi --generate_map --image pdf
290  
291 Which output formats you can choose depends on your particular GraphViz
292 installation, so check the GraphViz documentation.
293  
294 There is a number of different approaches to the layout of such
295 diagrams, and GraphViz offers several (again, consult the GraphvIz
296 documentation). The default is C<dot>, but often C<neato> or C<sfdp>
297 also offer good representations. Which one is "best" is a matter of
298 taste and also depends on the map at hand. Try this:
299  
300 $ map-tube --map Delhi --generate_map --layout neato
301  
302 =head3 Generate Just a Line Map
303  
304 To generate a graphical representation of just a particular line, follow
305 the command below. This will generate a PNG file named after the line in your
306 current working directory. (It will silently overwrite any pre-existing file
307 of the same name.)
308  
309 $ map-tube --map London --line Bakerloo --generate_map
310  
311 In case you want a different background color to the map then you can try this:
312  
313 $ map-tube --map London --line DLR --bgcolor yellow --generate_map
314  
315 =head2 Additional Information on Lines, Stations, and Maps
316  
317 =head3 Generate Line Mappings as a Table
318  
319 This will show all stops on the given lane, as far as possible in the correct order:
320  
321 $ map-tube --map London --line Bakerloo --line_mappings
322  
323 All that has been said above about output file names, image formats and layout algorithms
324 applies also to line maps.
325  
326 =head3 Generate Line Notes
327  
328 This will show which other lines are serving the stations on the given line.
329 Stations are ordered alphabetically. Only stations that are served by at least
330 one additional line are shown.
331  
332 $ map-tube --map London --line Bakerloo --line_notes
333  
334 It can also be displayed in tabular form:
335  
336 $ map-tube --map London --line Bakerloo --line_notes --tabular
337  
338 =head3 List the Lines for the Given Map
339  
340 $ map-tube --map London --list_lines
341  
342 =head3 List the Stations for the Given Map
343  
344 $ map-tube --map London --list_stations
345  
346 =head3 List all Supported Maps
347  
348 This will show you a list of all officially supported maps. It will also show you
349 which of these maps are not currently installed on your machine.
350  
351 $ map-tube --list_maps
352  
353 =head2 Using a Map that is Not Officially Supported
354  
355 It is also possible to use tube maps that are not officially supported, e.g.,
356 privately created maps: (This is also helpful while developing a new map.)
357  
358 $ map-tube --map 'Slippery Rock' --start 'College Park' --end 'Greyhound station' --force
359  
360 =head2 Error Handling
361  
362 If encountering an invalid map or a missing map (i.e not installed), you get an error
363 message like below:
364  
365 $ map-tube --map xYz --start 'Baker Street' --end 'Euston Square'
366 ERROR: Unsupported Map [xYz].
367  
368 The following will produce a similar message if you do not have the tube map of Kazan installed;
369 if you do have it, it will notify you that the starting station does not exist in this map:
370  
371 $ map-tube --map Kazan --start 'Baker Street' --end 'Euston Square'
372 ERROR: Missing Map [Kazan].
373  
374 =head1 SUPPORTED MAPS
375  
376 The command line parameter C<map> can take one of the following map names. It is
377 case insensitive, i.e. 'London' and 'lOndOn' are the same.
378 Use the C<--list_maps> option described above to get an up-to-date version of this list.
379 Use the C<--force> option described above to use locally installed maps that are not on
380 that list.
381  
382 Note that not all officially supported maps might be available at your site. The
383 C<--list-maps> option will show which aren't. You can either install any missing map
384 from CPAN, or you could use L<Task::Map::Tube::Bundle> to install the supported maps.
385 Please make sure you have the latest maps when you install.
386  
387 =over 4
388  
389 =item * L<Athens|Map::Tube::Athens>
390  
391 =item * L<Barcelona|Map::Tube::Barcelona>
392  
393 =item * L<Beijing|Map::Tube::Beijing>
394  
395 =item * L<Berlin|Map::Tube::Berlin>
396  
397 =item * L<Bielefeld|Map::Tube::Bielefeld>
398  
399 =item * L<Brussels|Map::Tube::Brussels>
400  
401 =item * L<Bucharest|Map::Tube::Bucharest>
402  
403 =item * L<Budapest|Map::Tube::Budapest>
404  
405 =item * L<Chicago|Map::Tube::Chicago>
406  
407 =item * L<Copenhagen|Map::Tube::Copenhagen>
408  
409 =item * L<Delhi|Map::Tube::Delhi>
410  
411 =item * L<Dnipropetrovsk|Map::Tube::Dnipropetrovsk>
412  
413 =item * L<Frankfurt|Map::Tube::Frankfurt>
414  
415 =item * L<Glasgow|Map::Tube::Glasgow>
416  
417 =item * L<Hamburg|Map::Tube::Hamburg>
418  
419 =item * L<Hongkong|Map::Tube::Hongkong>
420  
421 =item * L<Kazan|Map::Tube::Kazan>
422  
423 =item * L<Kharkiv|Map::Tube::Kharkiv>
424  
425 =item * L<Kiev|Map::Tube::Kiev>
426  
427 =item * L<KoelnBonn|Map::Tube::KoelnBonn>
428  
429 =item * L<Kolkatta|Map::Tube::Kolkatta>
430  
431 =item * L<KualaLumpur|Map::Tube::KualaLumpur>
432  
433 =item * L<Leipzig|Map::Tube::Leipzig>
434  
435 =item * L<London|Map::Tube::London>
436  
437 =item * L<Lyon|Map::Tube::Lyon>
438  
439 =item * L<Madrid|Map::Tube::Madrid>
440  
441 =item * L<Malaga|Map::Tube::Malaga>
442  
443 =item * L<Milan|Map::Tube::Milan>
444  
445 =item * L<Minsk|Map::Tube::Minsk>
446  
447 =item * L<Moscow|Map::Tube::Moscow>
448  
449 =item * L<Muenchen|Map::Tube::Muenchen>
450  
451 =item * L<Napoli|Map::Tube::Napoli>
452  
453 =item * L<Nuremberg|Map::Tube::Nuremberg>
454  
455 =item * L<NYC|Map::Tube::NYC>
456  
457 =item * L<Nanjing|Map::Tube::Nanjing>
458  
459 =item * L<NizhnyNovgorod|Map::Tube::NizhnyNovgorod>
460  
461 =item * L<Novosibirsk|Map::Tube::Novosibirsk>
462  
463 =item * L<Oslo|Map::Tube::Oslo>
464  
465 =item * L<Paris|Map::Tube::Paris>
466  
467 =item * L<Prague|Map::Tube::Prague>
468  
469 =item * L<RheinRuhr|Map::Tube::RheinRuhr>
470  
471 =item * L<Rome|Map::Tube::Rome>
472  
473 =item * L<SaintPetersburg|Map::Tube::SaintPetersburg>
474  
475 =item * L<Samara|Map::Tube::Samara>
476  
477 =item * L<SanFrancisco|Map::Tube::SanFrancisco>
478  
479 =item * L<Singapore|Map::Tube::Singapore>
480  
481 =item * L<Sofia|Map::Tube::Sofia>
482  
483 =item * L<Stockholm|Map::Tube::Stockholm>
484  
485 =item * L<Stuttgart|Map::Tube::Stuttgart>
486  
487 =item * L<Sydney|Map::Tube::Sydney>
488  
489 =item * L<Tbilisi|Map::Tube::Tbilisi>
490  
491 =item * L<Toulouse|Map::Tube::Toulouse>
492  
493 =item * L<Tokyo|Map::Tube::Tokyo>
494  
495 =item * L<Vienna|Map::Tube::Vienna>
496  
497 =item * L<Warsaw|Map::Tube::Warsaw>
498  
499 =item * L<Yekaterinburg|Map::Tube::Yekaterinburg>
500  
501 =back
502  
503 =cut
504  
505 0 ▶sub BUILD {
Subroutine BUILD: not called CC=12 SCAR=50.5
Pod undocumented
506 0 my ($self) = @_;
507  
508 0 my $plugins = [ plugins ];
509 0 my $map_name = $self->{map};
510 0 ▶ my $map_uc_name = uc($map_name//'');
Condition0%0/2
$map_name // ""
l!l
00
MC/DC0%0/1
$map_name // ""
$map_name
Truth table0%0/2
A
A= $map_name
Aresult
11
00
511 0 my $all_maps = supported_maps();
512 0 ▶ if (defined $map_name && exists $all_maps->{$map_uc_name}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $map_name and exists $all_maps->{$map_uc_name}) 0 0 0
Condition0%0/3
defined $map_name and exists $all_maps->{$map_uc_name}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $map_name and exists $all_maps->{$map_uc_name}
defined $map_name exists $all_maps->{$map_uc_name}
Truth table0%0/3
A and B
A= defined $map_nameB= exists $all_maps->{$map_uc_name}
ABresult
0X0
100
111
513 0 my $map_full_name = $all_maps->{$map_uc_name};
514 0 ▶ $self->{maps}->{$map_uc_name} = $_->new for ( grep { defined($_) && ($_ eq $map_full_name)} @$plugins);
Condition0%0/3
defined $_ && $_ eq $map_full_name
!ll&&!rl&&r
000
MC/DC0%0/2
defined $_ && $_ eq $map_full_name
defined $_ $_ eq $map_full_name
Truth table0%0/3
A && B
A= defined $_B= $_ eq $map_full_name
ABresult
0X0
100
111
515 }
516  
517 0 ▶ if ($self->force) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->force) 0 0 0
518 0 ▶ if ($map_name =~ /^[-_A-Za-z0-9]+$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($map_name =~ /^[-_A-Za-z0-9]+$/u) { } 0 0 0
519 # Unsupported maps are not loaded by Module::Pluggable, so load it here.
520 0 my $class = "Map::Tube::$map_name";
521 0 (my $file = "$class.pm") =~ s{::}{/}g;
522 0 ▶ unless (eval { require $file; 1 }) {
Branch: 1 branch
BranchTrueFalseTotal
unless (eval { do { require $file; 1 } }) 0 0 0
523 0 ▶ my $error = $@ || 'unknown error';
Condition0%0/2
$@ || 'unknown error'
l!l
00
MC/DC0%0/1
$@ || 'unknown error'
$@
Truth table0%0/2
A
A= $@
Aresult
11
00
524 0 $error =~ s/\s+\z//;
525 0 my @caller = caller(0);
526 0 ▶ @caller = caller(2) if $caller[3] eq '(eval)';
Branch: 1 branch
BranchTrueFalseTotal
if $caller[3] eq "(eval)" 0 0 0
527  
528 0 Map::Tube::Exception::FoundUnsupportedMap->throw({
529 method => __PACKAGE__."::BUILD",
530 message => "ERROR: Can't load forced map [$map_name]: $error",
531 filename => $caller[1],
532 line_number => $caller[2] });
533 }
534 0 $self->{maps}->{$map_uc_name} = $class->new;
535 }
536 else {
537 0 my @caller = caller(0);
538 0 ▶ @caller = caller(2) if $caller[3] eq '(eval)';
Branch: 1 branch
BranchTrueFalseTotal
if $caller[3] eq "(eval)" 0 0 0
539  
540 0 Map::Tube::Exception::FoundUnsupportedMap->throw({
541 method => __PACKAGE__."::BUILD",
542 message => "ERROR: Can't force invalid map name [$map_name].",
543 filename => $caller[1],
544 line_number => $caller[2] });
545 }
546 }
547  
548 0 $self->_validate_param;
549  
550 }
551  
552 =head1 METHODS
553  
554 =head2 run()
555  
556 This is the main method provided by the package L<Map::Tube::CLI>. It does not
557 expect any parameter. Here is the code from the supplied C<map-tube> script.
558  
559 use strict; use warnings;
560 use Map::Tube::CLI;
561  
562 Map::Tube::CLI->new_with_options->run;
563  
564 =cut
565  
566 0 ▶sub run {
Subroutine run: not called CC=33 SCAR=68.2
Pod documented
567 0 my ($self) = @_;
568  
569 0 ▶ my $map_obj = $self->map ? $self->{maps}->{uc($self->map)} : undef;
Branch: 1 branch
BranchTrueFalseTotal
$self->map ? : 0 0 0
570  
571 # Handle these options first because map name may not be present and is not needed:
572 0 ▶ if ($self->version) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->version) 0 0 0
573 0 print _prepare_version_info($map_obj, $self->map), "\n";
574 0 return;
575 }
576 0 ▶ if ($self->list_maps) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->list_maps) 0 0 0
577 0 my $map_list = _prepare_map_list();
578 0 ▶ if ($self->tabular) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->tabular) { } 0 0 0
579 0 my $map_table = Text::ASCIITable->new;
580 0 $map_table->setCols('Map Name','Description');
581 0 $map_table->addRow(@$_) for @$map_list;
582 0 print "Supported Metro Maps\n\n";
583 3 ▶ no warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
584 0 print $map_table;
585 } else {
586 3 ▶ no warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
587 0 print join(', ', @$_), "\n" for @$map_list;
588 }
589 0 return;
590 }
591 0 ▶ if (defined $self->penalty) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->penalty) 0 0 0
592 0 ▶ if ($map_obj->can('line_change_penalty')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($map_obj->can('line_change_penalty')) { } 0 0 0
593 0 $map_obj->line_change_penalty($self->penalty)
594 } else {
595 0 warn "Your Map::Tube does not support line change penalties. Please upgrade.\n";
596 }
597 }
598  
599 0 ▶ if ($self->generate_map) {
Branch: 5 branches
BranchTrueFalseTotal
if ($self->generate_map) { } 0 0 0
elsif ($self->line_mappings) { } 0 0 0
elsif ($self->line_notes) { } 0 0 0
elsif ($self->list_lines) { } 0 0 0
elsif ($self->list_stations) { } 0 0 0
600 0 ▶ $map_obj->bgcolor($self->bgcolor) if defined $self->bgcolor;
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->bgcolor 0 0 0
601 0 my %graph_args = ( line_name=>$self->line, output_file=>undef );
602 0 ▶ if ($self->image) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->image) 0 0 0
603 0 my %img_formats = map { lc($_) => 1 } $map_obj->list_formats();
604 0 ▶ if ( exists $img_formats{lc($self->image)} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $img_formats{lc $self->image}) { } 0 0 0
605 0 $graph_args{format} = lc($self->image);
606 }
607 else {
608 0 $graph_args{output_file} = $self->image;
609 0 ▶ if ( $self->image =~ /.([^.]+)$/ && exists $img_formats{lc($1)} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->image =~ /.([^.]+)$/u and exists $img_formats{lc $1}) 0 0 0
Condition0%0/3
$self->image =~ /.([^.]+)$/u and exists $img_formats{lc $1}
!ll&&!rl&&r
000
MC/DC0%0/2
$self->image =~ /.([^.]+)$/u and exists $img_formats{lc $1}
$self->image =~ /.([^.]+)$/u exists $img_formats{lc $1}
Truth table0%0/3
A and B
A= $self->image =~ /.([^.]+)$/uB= exists $img_formats{lc $1}
ABresult
0X0
100
111
610 0 $graph_args{format} = lc($1);
611 }
612 }
613 }
614 0 ▶ $graph_args{driver} = $self->layout if $self->layout;
Branch: 1 branch
BranchTrueFalseTotal
if $self->layout 0 0 0
615 0 ▶ if ($map_obj->can('render')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($map_obj->can('render')) { } 0 0 0
616 0 my (undef, $fname) = $map_obj->render(%graph_args);
617 0 ▶ print "Image written to $fname\n" if $fname;
Branch: 1 branch
BranchTrueFalseTotal
if $fname 0 0 0
618 }
619 else {
620 0 warn "You do not seem to have Map::Tube::Plugin::Graph installed.\n";
621 }
622 }
623 elsif ($self->line_mappings) {
624 0 ▶ printf("\n=head1 DESCRIPTION\n\n%s Metro Map: %s Line.\n\n", $self->map, $self->line) unless $self->tabular;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->tabular 0 0 0
625 0 print _prepare_line_mappings($map_obj, $self->line);
626 }
627 elsif ($self->line_notes) {
628 0 ▶ printf "\n=head1 NOTE\n\n=over 2\n" unless $self->tabular;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->tabular 0 0 0
629 0 print $self->_prepare_line_notes($map_obj);
630 0 ▶ print "\n=back\n" unless $self->tabular;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->tabular 0 0 0
631 }
632 elsif ($self->list_lines) {
633 0 print join(",\n", sort @{$map_obj->get_lines}), "\n";
634 }
635 elsif ($self->list_stations) {
636 0 my $station_list_table = _prepare_station_list($map_obj);
637 0 printf("Metro Map %s: Stations.\n\n", $self->map);
638 0 print $station_list_table;
639 }
640 else {
641 0 my $route = $map_obj->get_shortest_route($self->start, $self->end);
642 0 ▶ $route = $route->preferred if $self->preferred;
Branch: 1 branch
BranchTrueFalseTotal
if $self->preferred 0 0 0
643 0 ▶ if ($self->tabular) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->tabular) { } 0 0 0
644 0 my $route_table = Text::ASCIITable->new;
645 0 $route_table->setCols('Station Name','Lines');
646 0 $route_table->alignCol('Lines','left');
647 0 for my $station(@{$route->nodes()}) {
648 0 $route_table->addRow($station->name, join(', ', @{ $station->line }));
649 }
650 printf("Metro Map %s: Route from %s%s to %s%s.\n\n", $self->map,
651 0 ▶ $self->start, $self->{start_remark}//'', $self->end, $self->{end_remark}//'');
Condition0%0/4
$self->{"start_remark"} // ""
l!l
00
$self->{"end_remark"} // ""
l!l
00
MC/DC0%0/1
$self->{"start_remark"} // ""
$self->{"start_remark"}
MC/DC0%0/1
$self->{"end_remark"} // ""
$self->{"end_remark"}
Truth table0%0/2
A
A= $self->{"start_remark"}
Aresult
11
00
Truth table0%0/2
A
A= $self->{"end_remark"}
Aresult
11
00
652 0 print $route_table;
653 } else {
654 3 ▶ no warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
655 0 print $route, "\n";
656 }
657 0 ▶ if ($self->debug) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->debug) 0 0 0
658 0 print "\n---------DEBUG-----------\n";
659 0 foreach my $id (sort keys %{$map_obj->{tables}}) {
660 0 print "$map_obj->{tables}->{$id}\n";
661 }
662 0 print "-------------------------\n";
663 }
664 0 ▶ print "$@\n" if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
665 }
666 }
667  
668 =head2 supported_maps()
669  
670 This method will produce information on the maps that are generally
671 recognized by the package L<Map::Tube::CLI>. It does not expect any
672 parameter. It will return a reference to a hash whose keys are plain
673 text city names (in ALL-CAPS) and whose values are the names of the
674 modules that implement the maps.
675  
676 Note that "generally recognized" does not imply that the city/module in question
677 is actually available on your machine.
678  
679 =cut
680  
681  
682 #
683 #
684 # PRIVATE METHODS
685  
686 0 ▶sub _prepare_line_mappings {
Subroutine _prepare_line_mappings: not called CC=2 SCAR=17.9
687 0 my ($map, $line_name) = @_;
688  
689 0 my $map_table = Text::ASCIITable->new;
690 0 $map_table->setCols('Station Name','Connected To');
691  
692 0 foreach my $station (map { $_->name } @{ $map->get_stations($line_name) }) {
693 0 $map_table->addRow($station, join(", ", @{$map->get_linked_stations($station, $line_name)}));
694 }
695  
696 0 return $map_table;
697 }
698  
699 0 ▶sub _prepare_line_notes {
Subroutine _prepare_line_notes: not called CC=11 SCAR=48.8
700 0 my ($self, $map) = @_;
701 0 my $map_name = $self->map;
702 0 my $line_name = $self->line;
703  
704 0 my $line_name_uc = uc($line_name);
705 0 my $line_package = { map { $_->{name} => 1 }
706 0 ▶ grep { $line_name_uc ne uc($_->name) && scalar(@{$_->get_stations}) }
Condition0%0/2
$line_name_uc ne uc $_->name && scalar @{$_->get_stations;}
!ll
00
MC/DC0%0/1
$line_name_uc ne uc $_->name && scalar @{$_->get_stations;}
$line_name_uc ne uc $_->name
Truth table0%0/2
A
A= $line_name_uc ne uc $_->name
Aresult
00
11
707 0 @{$map->get_lines}
708 };
709  
710 0 ▶ my $notes = $self->tabular ? Text::ASCIITable->new : "";
Branch: 1 branch
BranchTrueFalseTotal
$self->tabular ? : 0 0 0
711 0 ▶ $notes->setCols("Line $line_name Station",'is also served by line(s)') if $self->tabular;
Branch: 1 branch
BranchTrueFalseTotal
if $self->tabular 0 0 0
712  
713 0 my @stations = map { $_->name } @{ $map->get_stations($line_name) };
714 0 ▶ if ( eval { require Unicode::Collate; 1 } ) {
Branch: 1 branch
BranchTrueFalseTotal
if (eval { do { require Unicode::Collate; 1 } }) { } 0 0 0
715 0 my $collator = Unicode::Collate->new(level => 1);
716 0 @stations = $collator->sort(@stations);
717 } else {
718 0 @stations = sort { lc($a) cmp lc($b) } @stations;
719 }
720  
721 0 foreach my $station (@stations) {
722 0 ▶ my @lines = grep { $_ ne $line_name && exists $line_package->{$_} } map { $_->name } @{ $map->get_node_by_name($station)->line };
Condition0%0/3
$_ ne $line_name && exists $line_package->{$_}
!ll&&!rl&&r
000
MC/DC0%0/2
$_ ne $line_name && exists $line_package->{$_}
$_ ne $line_name exists $line_package->{$_}
Truth table0%0/3
A && B
A= $_ ne $line_nameB= exists $line_package->{$_}
ABresult
0X0
100
111
723 0 ▶ next unless @lines;
Branch: 1 branch
BranchTrueFalseTotal
unless @lines 0 0 0
724 0 ▶ if ($self->tabular) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->tabular) { } 0 0 0
725 0 $notes->addRow($station, join(", ", @lines));
726 }
727 else {
728 0 my $delim = ' ';
729 0 foreach my $line (@lines) {
730 0 ▶ $notes .= sprintf("\n=item * The station \"%s\" is also part of\n", $station) if $delim eq ' ';
Branch: 1 branch
BranchTrueFalseTotal
if $delim eq " " 0 0 0
731 0 $notes .= sprintf(" %s L<%s Line|Map::Tube::%s::Line::%s>\n",
732 $delim, $line, $map_name, _guess_package_name($line));
733 0 $delim = '|';
734 }
735 }
736 }
737  
738 0 return $notes;
739 }
740  
741 0 ▶sub _prepare_version_info {
Subroutine _prepare_version_info: not called CC=6 SCAR=34.4
742 0 my ($map, $map_name) = @_;
743 0 my $msg = "Map::Tube::CLI version $VERSION, Map::Tube version: $Map::Tube::VERSION";
744 0 ▶ if ($map_name) {
Branch: 1 branch
BranchTrueFalseTotal
if ($map_name) 0 0 0
745 0 my $supported_maps = supported_maps();
746 0 ▶ my $map_module_name = $supported_maps->{uc($map_name)} // ( 'Map::Tube::' . $map_name );
Condition0%0/2
$$supported_maps{uc $map_name} // 'Map::Tube::' . $map_name
l!l
00
MC/DC0%0/1
$$supported_maps{uc $map_name} // 'Map::Tube::' . $map_name
$$supported_maps{uc $map_name}
Truth table0%0/2
A
A= $$supported_maps{uc $map_name}
Aresult
11
00
747 0 my $version_ref = $map_module_name . '::VERSION';
748 0 ▶ my $map_desc = $map ? $map->name() // $map_name : '';
Branch: 1 branch
BranchTrueFalseTotal
$map ? : 0 0 0
Condition0%0/3
$map->name // $map_name
l!l&&r!l&&!r
000
MC/DC0%0/2
$map->name // $map_name
$map->name $map_name
Truth table0%0/3
A // B
A= $map->nameB= $map_name
ABresult
1X1
011
000
749 0 my $map_version;
750 {
751 0 ▶ no strict;
Subroutine BEGIN: called CC=1 SCAR=0.2
752 0 ▶ $map_version = ${$version_ref} // 'unknown';
Condition0%0/2
${$version_ref;} // "unknown"
l!l
00
MC/DC0%0/1
${$version_ref;} // "unknown"
${$version_ref;}
Truth table0%0/2
A
A= ${$version_ref;}
Aresult
11
00
753 }
754 0 $msg .= ", map $map_name: $map_desc version: $map_version";
755 }
756 0 return $msg;
757 }
758  
759 0 ▶sub _prepare_map_list {
Subroutine _prepare_map_list: not called CC=3 SCAR=24.8
760 0 my $supported_maps = supported_maps();
761 0 my %plugins = map { $_ => 1 } plugins;
762 0 my @map_list;
763 0 for my $map ( sort values %$supported_maps ) {
764 0 my $map_name = '(not installed or not loadable)';
765 0 ▶ if (exists $plugins{$map}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $plugins{$map}) 0 0 0
766 0 ▶ try {
Subroutine __ANON__: not called CC=1 SCAR=6.9
767 0 $map_name = $map->new->name();
768 0 ▶ } catch {
Subroutine __ANON__: not called CC=1 SCAR=6.9
769 0 $map_name = '(not loadable)';
770 }
771 0 }
772 0 $map =~ s/^.*:://;
773 0 push(@map_list, [$map, $map_name]);
774 }
775  
776 0 return \@map_list;
777 }
778  
779 0 ▶sub _prepare_station_list {
Subroutine _prepare_station_list: not called CC=3 SCAR=24.8
780 0 my ($map) = @_;
781  
782 0 my $station_table = Text::ASCIITable->new;
783 0 $station_table->setCols('Station Name','Served by lines');
784 0 $station_table->alignCol('Served by lines','left');
785  
786 0 my @stations = @{ $map->get_stations() };
787  
788 0 ▶ if ( eval { require Unicode::Collate; 1 } ) {
Branch: 1 branch
BranchTrueFalseTotal
if (eval { do { require Unicode::Collate; 1 } }) { } 0 0 0
789 0 my $collator = Unicode::Collate->new(level => 1);
790 0 @stations = $collator->sort(@stations);
791 } else {
792 0 @stations = sort { lc($a) cmp lc($b) } @stations;
793 }
794  
795 0 foreach my $station (@stations) {
796 0 $station_table->addRow( $station->name, join(', ', @{ $station->line }));
797 }
798  
799 0 return $station_table;
800 }
801  
802 0 ▶sub _guess_package_name {
Subroutine _guess_package_name: not called CC=3 SCAR=24.8
803 0 my ($name) = @_;
804  
805 0 my $_name;
806 0 foreach my $token (split /\s/,$name) {
807 0 ▶ next if ($token =~ /\&/);
Branch: 1 branch
BranchTrueFalseTotal
if $token =~ /\&/u 0 0 0
808 0 $_name .= ucfirst(lc($token));
809 }
810  
811 0 return $_name;
812 }
813  
814 0 ▶sub _identify_station {
Subroutine _identify_station: not called CC=17 SCAR=57.2
815 0 my ($self, $station) = @_;
816 0 my @caller = caller(1);
817 0 ▶ @caller = caller(3) if $caller[3] eq '(eval)';
Branch: 1 branch
BranchTrueFalseTotal
if $caller[3] eq "(eval)" 0 0 0
818 0 my $map_obj = $self->{maps}->{uc($self->map)};
819 0 my $remark = '';
820 0 my $station_node;
821 0 ▶ try {
Subroutine __ANON__: not called CC=2 SCAR=17.9
822 0 ▶ $station_node = $map_obj->get_node_by_name($station) unless $self->fuzzy;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->fuzzy 0 0 0
823 0 ▶ } catch {
Subroutine __ANON__: not called CC=1 SCAR=0.0
824 0 };
825 0 ▶ if (!defined $station_node) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $station_node) 0 0 0
826 0 ▶ if ((!defined $self->fuzzy || $self->fuzzy) && $map_obj->can('fuzzy_find')) {
Branch: 1 branch
BranchTrueFalseTotal
if (!defined($self->fuzzy) || $self->fuzzy and $map_obj->can('fuzzy_find')) { } 0 0 0
Condition0%0/6
!defined($self->fuzzy) || $self->fuzzy and $map_obj->can("fuzzy_find")
!ll&&!rl&&r
000
not defined $self->fuzzy or $self->fuzzy
l!l&&r!l&&!r
000
MC/DC0%0/3
!defined($self->fuzzy) || $self->fuzzy and $map_obj->can("fuzzy_find")
not defined $self->fuzzy $self->fuzzy $map_obj->can("fuzzy_find")
Truth table0%0/5
not(A) or B and C
A= not defined $self->fuzzyB= $self->fuzzyC= $map_obj->can("fuzzy_find")
ABCresult
00X0
1X00
0100
1X11
0111
827 # Try fuzzy matching.
828 # Different strategies depending on whether we have a common regex meta character ( '.', '?', '*', '+', '[' ).
829 0 my @fuzzy_methods;
830 0 ▶ push( @fuzzy_methods, 'start', 'in' ) unless $station =~ /[?*+\[]/;
Branch: 1 branch
BranchTrueFalseTotal
unless $station =~ /[?*+\[]/u 0 0 0
831 0 ▶ push( @fuzzy_methods, 'regex' ) if $station =~ /^[^?*].*[.?*+\[]/;
Branch: 1 branch
BranchTrueFalseTotal
if $station =~ /^[^?*].*[.?*+\[]/u 0 0 0
832 0 ▶ push( @fuzzy_methods, 'levenshtein', 'doublemetaphone', 'ngrams' ) unless $station =~/[?*+\[]/;
Branch: 1 branch
BranchTrueFalseTotal
unless $station =~ /[?*+\[]/u 0 0 0
833 0 my @stations;
834 0 for my $method (@fuzzy_methods) {
835 0 @stations = $map_obj->fuzzy_find(search=>$station, objects=>'stations', method=>$method);
836 0 ▶ last if @stations;
Branch: 1 branch
BranchTrueFalseTotal
if @stations 0 0 0
837 }
838 0 ▶ if (@stations == 1) {
Branch: 2 branches
BranchTrueFalseTotal
if (@stations == 1) { } 0 0 0
elsif (@stations == 0) { } 0 0 0
839 0 $station = $stations[0]->name();
840 0 $remark = ' (guessed)';
841 }
842 elsif (@stations == 0) {
843 0 ▶ Map::Tube::Exception::InvalidStationName->throw({
Branch: 1 branch
BranchTrueFalseTotal
$self->fuzzy ? : 0 0 0
844 method => __PACKAGE__."::run",
845 message => ( $self->fuzzy
846 ? "ERROR: No Fuzzy Match for Station Name [$station]."
847 : "ERROR: Invalid Station Name [$station]."
848 ),
849 filename => $caller[1],
850 line_number => $caller[2] });
851 }
852 else {
853 0 ▶ @stations = ( ( map { $_ ->name() } @stations[0..9] ), '...' ) if @stations > 10;
Branch: 1 branch
BranchTrueFalseTotal
if @stations > 10 0 0 0
854 0 ▶ Map::Tube::Exception::InvalidStationName->throw({
Branch: 1 branch
BranchTrueFalseTotal
$self->fuzzy ? : 0 0 0
855 method => __PACKAGE__."::run",
856 message => ( $self->fuzzy
857 ? ( "ERROR: Station Not Identified; maybe one of " . join(', ', @stations ) . "?" )
858 : ( "ERROR: Invalid Station Name [$station]; maybe one of " . join(', ', @stations ) . "?" )
859 ),
860 filename => $caller[1],
861 line_number => $caller[2] });
862 }
863 }
864 else {
865 0 ▶ warn "You do not seem to have Map::Tube::Plugin::FuzzyFind installed, " .
Branch: 1 branch
BranchTrueFalseTotal
unless $map_obj->can("fuzzy_find") 0 0 0
866 "so you must enter station names correctly.\n" unless $map_obj->can('fuzzy_find');
867 0 Map::Tube::Exception::InvalidStationName->throw({
868 method => __PACKAGE__."::run",
869 message => "ERROR: Invalid Station Name [$station].",
870 filename => $caller[1],
871 line_number => $caller[2] });
872 }
873 }
874  
875 0 return ( $station, $remark );
876 }
877  
878 0 ▶sub _validate_param {
Subroutine _validate_param: not called CC=25 SCAR=64.8
879 0 my ($self) = @_;
880  
881 0 my @caller = caller(0);
882 0 ▶ @caller = caller(2) if $caller[3] eq '(eval)';
Branch: 1 branch
BranchTrueFalseTotal
if $caller[3] eq "(eval)" 0 0 0
883  
884 0 my $start = $self->start;
885 0 my $end = $self->end;
886 0 my $map = $self->map;
887 0 my $line = $self->line;
888 0 my $bgcolor = $self->bgcolor;
889  
890 0 ▶ return if $self->version || $self->list_maps;
Branch: 1 branch
BranchTrueFalseTotal
if $self->version or $self->list_maps 0 0 0
Condition0%0/3
$self->version or $self->list_maps
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->version or $self->list_maps
$self->version $self->list_maps
Truth table0%0/3
A or B
A= $self->versionB= $self->list_maps
ABresult
1X1
011
000
891  
892 0 ▶ Map::Tube::Exception::MissingMapName->throw({
Branch: 1 branch
BranchTrueFalseTotal
unless defined $map 0 0 0
893 method => __PACKAGE__."::_validate_param",
894 message => "ERROR: Missing Map Name.",
895 filename => $caller[1],
896 line_number => $caller[2] })
897 unless (defined $map);
898  
899 0 my $supported_maps = supported_maps();
900 0 ▶ $supported_maps->{uc($map)} //= 'Map::Tube::'. $map if $self->force;
Branch: 1 branch
BranchTrueFalseTotal
if $self->force 0 0 0
Condition0%0/2
$$supported_maps{uc $map} //= 'Map::Tube::' . $map
l!l
00
MC/DC0%0/1
$$supported_maps{uc $map} //= 'Map::Tube::' . $map
$$supported_maps{uc $map}
Truth table0%0/2
A
A= $$supported_maps{uc $map}
Aresult
11
00
901  
902 Map::Tube::Exception::FoundUnsupportedMap->throw({
903 method => __PACKAGE__."::_validate_param",
904 message => "ERROR: Unsupported Map [$map].",
905 filename => $caller[1],
906 line_number => $caller[2] })
907 0 ▶ unless (exists $supported_maps->{uc($map)});
Branch: 1 branch
BranchTrueFalseTotal
unless exists $$supported_maps{uc $map} 0 0 0
908  
909 Map::Tube::Exception::MissingSupportedMap->throw({
910 method => __PACKAGE__."::_validate_param",
911 message => "ERROR: Missing Map [$map].",
912 filename => $caller[1],
913 line_number => $caller[2] })
914 0 ▶ unless (exists $self->{maps}->{uc($map)});
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"maps"}{uc $map} 0 0 0
915  
916 0 ▶ if ($self->generate_map) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->generate_map) 0 0 0
917 0 ▶ if (defined $bgcolor && !(is_valid_color($bgcolor))) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $bgcolor and not is_valid_color($bgcolor)) 0 0 0
Condition0%0/3
defined $bgcolor and not is_valid_color($bgcolor)
!ll&&!rl&&r
000
MC/DC0%0/2
defined $bgcolor and not is_valid_color($bgcolor)
defined $bgcolor not is_valid_color($bgcolor)
Truth table0%0/3
A and not(B)
A= defined $bgcolorB= not is_valid_color($bgcolor)
ABresult
0X0
100
111
918 0 Map::Tube::Exception::InvalidBackgroundColor->throw({
919 method => __PACKAGE__."::_validate_param",
920 message => "ERROR: Invalid background Color [$bgcolor].",
921 filename => $caller[1],
922 line_number => $caller[2] });
923 }
924  
925 0 ▶ if (defined $line) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $line) 0 0 0
926 Map::Tube::Exception::InvalidLineName->throw({
927 method => __PACKAGE__."::_validate_param",
928 message => "ERROR: Invalid Line Name [$line].",
929 filename => $caller[1],
930 line_number => $caller[2] })
931 0 ▶ unless defined $self->{maps}->{uc($map)}->get_line_by_name($line);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"maps"}{uc $map}->get_line_by_name($line) 0 0 0
932 }
933 }
934  
935 0 ▶ if ($self->line_mappings || $self->line_notes) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->line_mappings or $self->line_notes) 0 0 0
Condition0%0/3
$self->line_mappings or $self->line_notes
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->line_mappings or $self->line_notes
$self->line_mappings $self->line_notes
Truth table0%0/3
A or B
A= $self->line_mappingsB= $self->line_notes
ABresult
1X1
011
000
936  
937 Map::Tube::Exception::InvalidLineName->throw({
938 method => __PACKAGE__."::_validate_param",
939 message => "ERROR: Invalid Line Name [$line].",
940 filename => $caller[1],
941 line_number => $caller[2] })
942 0 ▶ unless defined $self->{maps}->{uc($map)}->get_line_by_name($line);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"maps"}{uc $map}->get_line_by_name($line) 0 0 0
943 }
944  
945 0 ▶ unless ( $self->generate_map
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->generate_map or $self->line_mappings or $self->line_notes or $self->list_lines or $self->list_stations) 0 0 0
Condition0%0/12
$self->generate_map or $self->line_mappings or $self->line_notes or $self->list_lines or $self->list_stations
l!l&&r!l&&!r
000
$self->generate_map or $self->line_mappings or $self->line_notes or $self->list_lines
l!l&&r!l&&!r
000
$self->generate_map or $self->line_mappings or $self->line_notes
l!l&&r!l&&!r
000
$self->generate_map or $self->line_mappings
l!l&&r!l&&!r
000
MC/DC0%0/5
$self->generate_map or $self->line_mappings or $self->line_notes or $self->list_lines or $self->list_stations
$self->generate_map $self->line_mappings $self->line_notes $self->list_lines $self->list_stations
Truth table0%0/6
A or B or C or D or E
A= $self->generate_mapB= $self->line_mappingsC= $self->line_notesD= $self->list_linesE= $self->list_stations
ABCDEresult
1XXXX1
01XXX1
001XX1
0001X1
000011
000000
946 || $self->line_mappings
947 || $self->line_notes
948 || $self->list_lines
949 || $self->list_stations) {
950  
951 0 ▶ warn "--line option will be ignored" if defined $line; # --line option has been used for no good
Branch: 1 branch
BranchTrueFalseTotal
if defined $line 0 0 0
952  
953 0 ▶ Map::Tube::Exception::MissingStationName->throw({
Branch: 1 branch
BranchTrueFalseTotal
unless defined $start 0 0 0
954 method => __PACKAGE__."::_validate_param",
955 message => "ERROR: Missing Station Name [start].",
956 filename => $caller[1],
957 line_number => $caller[2] })
958 unless defined $start;
959 0 ($self->{start}, $self->{start_remark}) = $self->_identify_station($start);
960  
961 0 ▶ Map::Tube::Exception::MissingStationName->throw({
Branch: 1 branch
BranchTrueFalseTotal
unless defined $end 0 0 0
962 method => __PACKAGE__."::_validate_param",
963 message => "ERROR: Missing Station Name [end].",
964 filename => $caller[1],
965 line_number => $caller[2] })
966 unless defined $end;
967 0 ($self->{end}, $self->{end_remark}) = $self->_identify_station($end);
968  
969 }
970  
971 }
972  
973 =head1 AUTHOR
974  
975 Mohammad Sajid Anwar, C<< <mohammad.anwar at yahoo.com> >>
976  
977 =head1 CONTRIBUTORS
978  
979 Gisbert W. Selke, C<< <gws at cpan.org> >>
980  
981 =head1 REPOSITORY
982  
983 L<https://github.com/manwar/Map-Tube-CLI>
984  
985 =head1 BUGS
986  
987 Please report any bugs or feature requests through the web interface at L<https://github.com/manwar/Map-Tube-CLI/issues>.
988 I will be notified and then you'll automatically be notified of progress on your bug as I make changes.
989  
990 =head1 SUPPORT
991  
992 You can find documentation for this module with the perldoc command.
993  
994 perldoc Map::Tube::CLI
995  
996 You can also look for information at:
997  
998 =over 4
999  
1000 =item * BUG Report
1001  
1002 L<https://github.com/manwar/Map-Tube-CLI/issues>
1003  
1004 =item * Search MetaCPAN
1005  
1006 L<http://metacpan.org/dist/Map-Tube-CLI/>
1007  
1008 =back
1009  
1010 =head1 LICENSE AND COPYRIGHT
1011  
1012 Copyright (C) 2015 - 2026 Mohammad Sajid Anwar.
1013  
1014 This program is free software; you can redistribute it and / or modify it under
1015 the terms of the the Artistic License (2.0). You may obtain a copy of the full
1016 license at:
1017  
1018 L<http://www.perlfoundation.org/artistic_license_2_0>
1019  
1020 Any use, modification, and distribution of the Standard or Modified Versions is
1021 governed by this Artistic License.By using, modifying or distributing the Package,
1022 you accept this license. Do not use, modify, or distribute the Package, if you do
1023 not accept this license.
1024  
1025 If your Modified Version has been derived from a Modified Version made by someone
1026 other than you,you are nevertheless required to ensure that your Modified Version
1027 complies with the requirements of this license.
1028  
1029 This license does not grant you the right to use any trademark, service mark,
1030 tradename, or logo of the Copyright Holder.
1031  
1032 This license includes the non-exclusive, worldwide, free-of-charge patent license
1033 to make, have made, use, offer to sell, sell, import and otherwise transfer the
1034 Package with respect to any patent claims licensable by the Copyright Holder that
1035 are necessarily infringed by the Package. If you institute patent litigation
1036 (including a cross-claim or counterclaim) against any party alleging that the
1037 Package constitutes direct or contributory patent infringement,then this Artistic
1038 License to you shall terminate on the date that such litigation is filed.
1039  
1040 Disclaimer of Warranty: THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER AND
1041 CONTRIBUTORS "AS IS' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES. THE IMPLIED
1042 WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR
1043 NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY YOUR LOCAL LAW. UNLESS
1044 REQUIRED BY LAW, NO COPYRIGHT HOLDER OR CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT,
1045 INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE
1046 OF THE PACKAGE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
1047  
1048 =cut
1049  
1050 3 1; # End of Map::Tube::CLI
↑ Summary CLI/Option.pm »