| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Map::Tube::Text::Shortest; |
|
2
|
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# Pragmas. |
|
4
|
3
|
|
|
3
|
|
20976
|
use strict; |
|
|
3
|
|
|
|
|
5
|
|
|
|
3
|
|
|
|
|
89
|
|
|
5
|
3
|
|
|
3
|
|
10
|
use warnings; |
|
|
3
|
|
|
|
|
4
|
|
|
|
3
|
|
|
|
|
73
|
|
|
6
|
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
# Modules. |
|
8
|
3
|
|
|
3
|
|
1407
|
use Class::Utils qw(set_params); |
|
|
3
|
|
|
|
|
61083
|
|
|
|
3
|
|
|
|
|
51
|
|
|
9
|
3
|
|
|
3
|
|
168
|
use Error::Pure qw(err); |
|
|
3
|
|
|
|
|
4
|
|
|
|
3
|
|
|
|
|
97
|
|
|
10
|
3
|
|
|
3
|
|
13
|
use List::Util qw(reduce); |
|
|
3
|
|
|
|
|
3
|
|
|
|
3
|
|
|
|
|
202
|
|
|
11
|
3
|
|
|
3
|
|
13
|
use Readonly; |
|
|
3
|
|
|
|
|
3
|
|
|
|
3
|
|
|
|
|
89
|
|
|
12
|
3
|
|
|
3
|
|
12
|
use Scalar::Util qw(blessed); |
|
|
3
|
|
|
|
|
4
|
|
|
|
3
|
|
|
|
|
1312
|
|
|
13
|
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
# Constants. |
|
15
|
|
|
|
|
|
|
Readonly::Scalar our $DOUBLE_SPACE => q{ }; |
|
16
|
|
|
|
|
|
|
Readonly::Scalar our $EMPTY_STR => q{}; |
|
17
|
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
# Version. |
|
19
|
|
|
|
|
|
|
our $VERSION = 0.01; |
|
20
|
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
# Constructor. |
|
22
|
|
|
|
|
|
|
sub new { |
|
23
|
0
|
|
|
0
|
1
|
|
my ($class, @params) = @_; |
|
24
|
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
# Create object. |
|
26
|
0
|
|
|
|
|
|
my $self = bless {}, $class; |
|
27
|
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
# Map::Tube object. |
|
29
|
0
|
|
|
|
|
|
$self->{'tube'} = undef; |
|
30
|
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
# Process params. |
|
32
|
0
|
|
|
|
|
|
set_params($self, @params); |
|
33
|
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
# Check Map::Tube object. |
|
35
|
0
|
0
|
|
|
|
|
if (! defined $self->{'tube'}) { |
|
36
|
0
|
|
|
|
|
|
err "Parameter 'tube' is required."; |
|
37
|
|
|
|
|
|
|
} |
|
38
|
0
|
0
|
0
|
|
|
|
if (! blessed($self->{'tube'}) |
|
39
|
|
|
|
|
|
|
|| ! $self->{'tube'}->does('Map::Tube')) { |
|
40
|
|
|
|
|
|
|
|
|
41
|
0
|
|
|
|
|
|
err "Parameter 'tube' must be 'Map::Tube' object."; |
|
42
|
|
|
|
|
|
|
} |
|
43
|
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
# Object. |
|
45
|
0
|
|
|
|
|
|
return $self; |
|
46
|
|
|
|
|
|
|
} |
|
47
|
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
# Print shortest table. |
|
49
|
|
|
|
|
|
|
sub print { |
|
50
|
0
|
|
|
0
|
1
|
|
my ($self, $from, $to) = @_; |
|
51
|
0
|
|
|
|
|
|
my $route = $self->{'tube'}->get_shortest_route($from, $to); |
|
52
|
0
|
|
|
|
|
|
my $header = sprintf 'From %s to %s', $route->from->name, |
|
53
|
|
|
|
|
|
|
$route->to->name; |
|
54
|
0
|
|
|
|
|
|
my @output = ( |
|
55
|
|
|
|
|
|
|
$EMPTY_STR, |
|
56
|
|
|
|
|
|
|
$header, |
|
57
|
|
|
|
|
|
|
'=' x length $header, |
|
58
|
|
|
|
|
|
|
$EMPTY_STR, |
|
59
|
|
|
|
|
|
|
sprintf '-- Route %d (cost %s) ----------', 1, '?', |
|
60
|
|
|
|
|
|
|
); |
|
61
|
|
|
|
|
|
|
my $line_id_length = length |
|
62
|
0
|
0
|
|
0
|
|
|
reduce { length($a) > length($b) ? $a : $b } |
|
63
|
0
|
0
|
|
|
|
|
map { $_->id || '?'} @{$self->{'tube'}->get_lines}; |
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
64
|
0
|
|
|
|
|
|
foreach my $node (@{$route->nodes}) { |
|
|
0
|
|
|
|
|
|
|
|
65
|
0
|
|
|
|
|
|
my $num = 0; |
|
66
|
0
|
|
|
|
|
|
foreach my $line (@{$node->line}) { |
|
|
0
|
|
|
|
|
|
|
|
67
|
0
|
|
|
|
|
|
$num++; |
|
68
|
0
|
|
0
|
|
|
|
my $line_id = $line->id || '?'; |
|
69
|
0
|
0
|
|
|
|
|
push @output, sprintf "[ %1s %-${line_id_length}s ] %s", |
|
70
|
|
|
|
|
|
|
# TODO + |
|
71
|
|
|
|
|
|
|
$num == 2 ? '*' : $EMPTY_STR, |
|
72
|
|
|
|
|
|
|
$line_id, |
|
73
|
|
|
|
|
|
|
$node->name; |
|
74
|
|
|
|
|
|
|
} |
|
75
|
|
|
|
|
|
|
} |
|
76
|
0
|
|
|
|
|
|
push @output, $EMPTY_STR; |
|
77
|
|
|
|
|
|
|
# TODO Skip lines, which are not in route table. |
|
78
|
0
|
|
|
|
|
|
foreach my $line (@{$self->{'tube'}->get_lines}) { |
|
|
0
|
|
|
|
|
|
|
|
79
|
0
|
|
|
|
|
|
push @output, ( |
|
80
|
|
|
|
|
|
|
$line->id.$DOUBLE_SPACE.$line->name, |
|
81
|
|
|
|
|
|
|
); |
|
82
|
|
|
|
|
|
|
} |
|
83
|
0
|
|
|
|
|
|
push @output, ( |
|
84
|
|
|
|
|
|
|
$EMPTY_STR, |
|
85
|
|
|
|
|
|
|
'*: Transfer to other line', |
|
86
|
|
|
|
|
|
|
'+: Transfer to other station', |
|
87
|
|
|
|
|
|
|
$EMPTY_STR, |
|
88
|
|
|
|
|
|
|
); |
|
89
|
0
|
0
|
|
|
|
|
return wantarray ? @output : join "\n", @output; |
|
90
|
|
|
|
|
|
|
} |
|
91
|
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
1; |
|
93
|
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
__END__ |