| 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.2405'; | |||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 3 | ▶ | use Map::Metro::Elk; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | 0 | ▶ | sub register { | ||||||||||||||||||||||||||
|
Subroutine
register: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | 0 | ▶ | before_add_routing => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=11 SCAR=48.8
| |||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 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 | }; | |||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | 3 | __PACKAGE__->meta->make_immutable; | |||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | 3 | 1; | |||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | __END__ | ||||||||||||||||||||||||||||