| 1 | 3 | ▶ | use 5.10.0; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 2 | 3 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | 3 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | package Map::Metro::Plugin::Hook::PrettyPrinter; | ||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | # ABSTRACT: Prints a routing | ||||||||||||||||||||||||||||
| 8 | 3 | our $AUTHORITY = 'cpan:CSSON'; # AUTHORITY | |||||||||||||||||||||||||||
| 9 | 3 | our $VERSION = '0.2404'; | |||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 3 | ▶ | use Map::Metro::Elk; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | sub register { | ||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | before_add_routing => sub { | ||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=11 SCAR=48.8
| |||||||||||||||||||||||||||||
| 18 | 0 | my $routing = shift; | |||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | 0 | my $header = sprintf q{From %s to %s} => $routing->origin_station->name, $routing->destination_station->name; | |||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | 0 | my @rows = ('', $header, '=' x length $header, ''); | |||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | 0 | my $route_count = 0; | |||||||||||||||||||||||||||
| 25 | 0 | my $longest_length = 0; | |||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | ROUTE: | ||||||||||||||||||||||||||||
| 28 | 0 | foreach my $route ($routing->ordered_routes) { | |||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | 0 | my $line_name_length = $route->longest_line_name_length; | |||||||||||||||||||||||||||
| 31 | 0 | ▶ | $longest_length = $line_name_length if $line_name_length > $longest_length; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | 0 | push @rows => sprintf '-- Route %d (cost %s) ----------', ++$route_count, $route->weight; | |||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | STEP: | ||||||||||||||||||||||||||||
| 36 | 0 | foreach my $step ($route->all_steps) { | |||||||||||||||||||||||||||
| 37 | 0 | ▶ | push @rows => sprintf "[ %1s %-${line_name_length}s ] %s" => ($step->was_line_transfer && !$step->was_station_transfer ? '*' : ''), | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$step->was_line_transfer and not $step->was_station_transfer
MC/DC0%0/2
$step->was_line_transfer and not $step->was_station_transfer
$step->was_line_transfer
not $step->was_station_transfer
Truth table0%0/3
A and not(B)
A= $step->was_line_transferB= not $step->was_station_transfer
| |||||||||||||||||||||||||||||
| 38 | $step->origin_line_station->line->name, | ||||||||||||||||||||||||||||
| 39 | join '/' => $step->origin_line_station->station->name_with_alternative; | ||||||||||||||||||||||||||||
| 40 | 0 | ▶ | if($step->is_station_transfer) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 41 | 0 | ▶ | push @rows => sprintf "[ %1s %-${line_name_length}s ] %s" => ($step->is_station_transfer ? '+' : ''), | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 42 | ' ' x length $step->origin_line_station->line->name, | ||||||||||||||||||||||||||||
| 43 | join '/' => $step->destination_line_station->station->name_with_alternative; | ||||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||
| 45 | 0 | ▶ | if(!$step->has_next_step) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 46 | 0 | push @rows => sprintf "[ %1s %-${line_name_length}s ] %s" => '', | |||||||||||||||||||||||||||
| 47 | $step->destination_line_station->line->name, | ||||||||||||||||||||||||||||
| 48 | join '/' => $step->destination_line_station->station->name_with_alternative; | ||||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||
| 51 | 0 | push @rows => ''; | |||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | 0 | my @lines_in_routing = sort { $a->name cmp $b->name } map { $_->origin_line_station->line } map { $_->all_steps } $routing->all_routes; | |||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | { | ||||||||||||||||||||||||||||
| 57 | 0 | my %seen_lines = (); | |||||||||||||||||||||||||||
| 58 | LINE: | ||||||||||||||||||||||||||||
| 59 | 0 | foreach my $line (@lines_in_routing) { | |||||||||||||||||||||||||||
| 60 | 0 | ▶ | next LINE if exists $seen_lines{ $line }; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 61 | 0 | $seen_lines{ $line } = 1; | |||||||||||||||||||||||||||
| 62 | 0 | push @rows => sprintf "%-${longest_length}s %s", $line->name, $line->description; | |||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | 0 | push @rows => '', '*: Transfer to other line', '+: Transfer to other station', ''; | |||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | 0 | say join "\n" => @rows; | |||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | 0 | ▶ | }; | ||||||||||||||||||||||||||
|
Subroutine
register: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | 3 | __PACKAGE__->meta->make_immutable; | |||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | 3 | 1; | |||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | __END__ | ||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | =pod | ||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | =encoding UTF-8 | ||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | =head1 NAME | ||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | Map::Metro::Plugin::Hook::PrettyPrinter - Prints a routing | ||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | =head1 VERSION | ||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | Version 0.2404, released 2016-04-30. | ||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | =head1 SOURCE | ||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | L<https://github.com/Csson/p5-Map-Metro> | ||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||
| 95 | =head1 HOMEPAGE | ||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | L<https://metacpan.org/release/Map-Metro> | ||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||
| 99 | =head1 AUTHOR | ||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | Erik Carlsson <info@code301.com> | ||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | =head1 COPYRIGHT AND LICENSE | ||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||
| 105 | This software is copyright (c) 2016 by Erik Carlsson. | ||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||
| 107 | This is free software; you can redistribute it and/or modify it under | ||||||||||||||||||||||||||||
| 108 | the same terms as the Perl 5 programming language system itself. | ||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||
| 110 | =cut | ||||||||||||||||||||||||||||