line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
2
|
|
|
2
|
|
1422
|
use 5.10.0; |
|
2
|
|
|
|
|
5
|
|
2
|
2
|
|
|
2
|
|
6
|
use strict; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
40
|
|
3
|
2
|
|
|
2
|
|
5
|
use warnings; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
107
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
package Map::Metro::Plugin::Hook::PrettyPrinter; |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
# ABSTRACT: Prints a routing |
8
|
|
|
|
|
|
|
our $AUTHORITY = 'cpan:CSSON'; # AUTHORITY |
9
|
|
|
|
|
|
|
our $VERSION = '0.2404'; |
10
|
|
|
|
|
|
|
|
11
|
2
|
|
|
2
|
|
7
|
use Map::Metro::Elk; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
13
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub register { |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
before_add_routing => sub { |
16
|
|
|
|
|
|
|
|
17
|
0
|
|
|
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
|
0
|
|
|
|
|
$longest_length = $line_name_length if $line_name_length > $longest_length; |
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
|
0
|
0
|
|
|
|
push @rows => sprintf "[ %1s %-${line_name_length}s ] %s" => ($step->was_line_transfer && !$step->was_station_transfer ? '*' : ''), |
38
|
|
|
|
|
|
|
$step->origin_line_station->line->name, |
39
|
|
|
|
|
|
|
join '/' => $step->origin_line_station->station->name_with_alternative; |
40
|
0
|
0
|
|
|
|
|
if($step->is_station_transfer) { |
41
|
0
|
0
|
|
|
|
|
push @rows => sprintf "[ %1s %-${line_name_length}s ] %s" => ($step->is_station_transfer ? '+' : ''), |
42
|
|
|
|
|
|
|
' ' x length $step->origin_line_station->line->name, |
43
|
|
|
|
|
|
|
join '/' => $step->destination_line_station->station->name_with_alternative; |
44
|
|
|
|
|
|
|
} |
45
|
0
|
0
|
|
|
|
|
if(!$step->has_next_step) { |
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; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
{ |
57
|
0
|
|
|
|
|
|
my %seen_lines = (); |
|
0
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
LINE: |
59
|
0
|
|
|
|
|
|
foreach my $line (@lines_in_routing) { |
60
|
0
|
0
|
|
|
|
|
next LINE if exists $seen_lines{ $line }; |
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
|
|
|
0
|
0
|
|
}; |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
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 |