| 1 | 13 | ▶ | use 5.10.0; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 2 | 13 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 3 | 13 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||||||
| 5 | package Map::Metro::Graph; | ||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||
| 7 | # ABSTRACT: An entire graph | ||||||||||||||||||||||||||||||||||||||||||
| 8 | 13 | our $AUTHORITY = 'cpan:CSSON'; # AUTHORITY | |||||||||||||||||||||||||||||||||||||||||
| 9 | 13 | our $VERSION = '0.2405'; | |||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||
| 11 | 13 | ▶ | use if $] >= 5.016000, feature => 'fc'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||
| 13 | 13 | ▶ | use Map::Metro::Elk; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 14 | 13 | ▶ | use Types::Standard qw/ArrayRef Bool Int Maybe Object Str/; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 15 | 13 | ▶ | use Map::Metro::Types qw/Connection Line LineStation Routing Segment Station Step Transfer/; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 16 | 13 | ▶ | use Types::Path::Tiny qw/AbsFile/; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 17 | 13 | ▶ | use Graph; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 18 | 13 | ▶ | use List::Util qw/any none/; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 19 | 13 | ▶ | use String::Trim qw/trim/; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 20 | 13 | ▶ | use Eponymous::Hash qw/eh/; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 21 | 13 | ▶ | use Try::Tiny; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 22 | 13 | ▶ | use Safe::Isa qw/$_call_if_object/; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||
| 24 | 13 | ▶ | use Map::Metro::Exceptions; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||
| 26 | 13 | ▶ | use Map::Metro::Graph::Connection; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 27 | 13 | ▶ | use Map::Metro::Graph::Line; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 28 | 13 | ▶ | use Map::Metro::Graph::LineStation; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 29 | 13 | ▶ | use Map::Metro::Graph::Route; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 30 | 13 | ▶ | use Map::Metro::Graph::Routing; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 31 | 13 | ▶ | use Map::Metro::Graph::Segment; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 32 | 13 | ▶ | use Map::Metro::Graph::Station; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 33 | 13 | ▶ | use Map::Metro::Graph::Step; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 34 | 13 | ▶ | use Map::Metro::Graph::Transfer; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 35 | 13 | ▶ | use Map::Metro::Emitter; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||||||
| 37 | 13 | has filepath => ( | |||||||||||||||||||||||||||||||||||||||||
| 38 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||
| 39 | isa => AbsFile, | ||||||||||||||||||||||||||||||||||||||||||
| 40 | required => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 41 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 42 | has wanted_hook_plugins => ( | ||||||||||||||||||||||||||||||||||||||||||
| 43 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||
| 44 | isa => ArrayRef[Str], | ||||||||||||||||||||||||||||||||||||||||||
| 45 | 0 | ▶ | default => sub { [] }, | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 46 | 13 | traits => ['Array'], | |||||||||||||||||||||||||||||||||||||||||
| 47 | predicate => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 48 | handles => { | ||||||||||||||||||||||||||||||||||||||||||
| 49 | all_wanted_hook_plugins => 'elements', | ||||||||||||||||||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||||||||||||||||
| 51 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 52 | 13 | has do_undiacritic => ( | |||||||||||||||||||||||||||||||||||||||||
| 53 | is => 'rw', | ||||||||||||||||||||||||||||||||||||||||||
| 54 | isa => Bool, | ||||||||||||||||||||||||||||||||||||||||||
| 55 | default => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 56 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 57 | 13 | has default_line_change_weight => ( | |||||||||||||||||||||||||||||||||||||||||
| 58 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||
| 59 | isa => Int, | ||||||||||||||||||||||||||||||||||||||||||
| 60 | default => 3, | ||||||||||||||||||||||||||||||||||||||||||
| 61 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 62 | 13 | has override_line_change_weight => ( | |||||||||||||||||||||||||||||||||||||||||
| 63 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||
| 64 | isa => Maybe[Int], | ||||||||||||||||||||||||||||||||||||||||||
| 65 | predicate => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 66 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 67 | has emit => ( | ||||||||||||||||||||||||||||||||||||||||||
| 68 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||
| 69 | isa => Object, | ||||||||||||||||||||||||||||||||||||||||||
| 70 | init_arg => undef, | ||||||||||||||||||||||||||||||||||||||||||
| 71 | lazy => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 72 | 4 | ▶ | default => sub { Map::Metro::Emitter->new(wanted_hook_plugins => [shift->all_wanted_hook_plugins]) }, | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 73 | 13 | handles => [qw/get_plugin all_plugins plugin_names/], | |||||||||||||||||||||||||||||||||||||||||
| 74 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||||||||||
| 76 | has stations => ( | ||||||||||||||||||||||||||||||||||||||||||
| 77 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||
| 78 | traits => ['Array'], | ||||||||||||||||||||||||||||||||||||||||||
| 79 | isa => ArrayRef[ Station ], | ||||||||||||||||||||||||||||||||||||||||||
| 80 | predicate => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 81 | 4 | ▶ | default => sub { [] }, | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 82 | 13 | init_arg => undef, | |||||||||||||||||||||||||||||||||||||||||
| 83 | handles => { | ||||||||||||||||||||||||||||||||||||||||||
| 84 | add_station => 'push', | ||||||||||||||||||||||||||||||||||||||||||
| 85 | get_station => 'get', | ||||||||||||||||||||||||||||||||||||||||||
| 86 | find_station => 'first', | ||||||||||||||||||||||||||||||||||||||||||
| 87 | filter_stations => 'grep', | ||||||||||||||||||||||||||||||||||||||||||
| 88 | all_stations => 'elements', | ||||||||||||||||||||||||||||||||||||||||||
| 89 | station_count => 'count', | ||||||||||||||||||||||||||||||||||||||||||
| 90 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 91 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 92 | has lines => ( | ||||||||||||||||||||||||||||||||||||||||||
| 93 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||
| 94 | traits => ['Array'], | ||||||||||||||||||||||||||||||||||||||||||
| 95 | isa => ArrayRef[ Line ], | ||||||||||||||||||||||||||||||||||||||||||
| 96 | predicate => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 97 | 4 | ▶ | default => sub { [] }, | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 98 | 13 | init_arg => undef, | |||||||||||||||||||||||||||||||||||||||||
| 99 | handles => { | ||||||||||||||||||||||||||||||||||||||||||
| 100 | add_line => 'push', | ||||||||||||||||||||||||||||||||||||||||||
| 101 | find_line => 'first', | ||||||||||||||||||||||||||||||||||||||||||
| 102 | all_lines => 'elements', | ||||||||||||||||||||||||||||||||||||||||||
| 103 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 104 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 105 | has segments => ( | ||||||||||||||||||||||||||||||||||||||||||
| 106 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||
| 107 | traits => ['Array'], | ||||||||||||||||||||||||||||||||||||||||||
| 108 | isa => ArrayRef[ Segment ], | ||||||||||||||||||||||||||||||||||||||||||
| 109 | predicate => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 110 | 4 | ▶ | default => sub { [] }, | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 111 | 13 | init_arg => undef, | |||||||||||||||||||||||||||||||||||||||||
| 112 | handles => { | ||||||||||||||||||||||||||||||||||||||||||
| 113 | add_segment => 'push', | ||||||||||||||||||||||||||||||||||||||||||
| 114 | all_segments => 'elements', | ||||||||||||||||||||||||||||||||||||||||||
| 115 | filter_segments => 'grep', | ||||||||||||||||||||||||||||||||||||||||||
| 116 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 117 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 118 | has line_stations => ( | ||||||||||||||||||||||||||||||||||||||||||
| 119 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||
| 120 | traits => ['Array'], | ||||||||||||||||||||||||||||||||||||||||||
| 121 | isa => ArrayRef[ LineStation ], | ||||||||||||||||||||||||||||||||||||||||||
| 122 | predicate => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 123 | 4 | ▶ | default => sub { [] }, | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 124 | 13 | init_arg => undef, | |||||||||||||||||||||||||||||||||||||||||
| 125 | handles => { | ||||||||||||||||||||||||||||||||||||||||||
| 126 | add_line_station => 'push', | ||||||||||||||||||||||||||||||||||||||||||
| 127 | all_line_stations => 'elements', | ||||||||||||||||||||||||||||||||||||||||||
| 128 | line_station_count => 'count', | ||||||||||||||||||||||||||||||||||||||||||
| 129 | find_line_stations => 'grep', | ||||||||||||||||||||||||||||||||||||||||||
| 130 | find_line_station => 'first', | ||||||||||||||||||||||||||||||||||||||||||
| 131 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 132 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 133 | has connections => ( | ||||||||||||||||||||||||||||||||||||||||||
| 134 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||
| 135 | traits => ['Array'], | ||||||||||||||||||||||||||||||||||||||||||
| 136 | isa => ArrayRef[ Connection ], | ||||||||||||||||||||||||||||||||||||||||||
| 137 | predicate => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 138 | 4 | ▶ | default => sub { [] }, | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 139 | 13 | init_arg => undef, | |||||||||||||||||||||||||||||||||||||||||
| 140 | handles => { | ||||||||||||||||||||||||||||||||||||||||||
| 141 | add_connection => 'push', | ||||||||||||||||||||||||||||||||||||||||||
| 142 | all_connections => 'elements', | ||||||||||||||||||||||||||||||||||||||||||
| 143 | connection_count => 'count', | ||||||||||||||||||||||||||||||||||||||||||
| 144 | find_connection => 'first', | ||||||||||||||||||||||||||||||||||||||||||
| 145 | filter_connections => 'grep', | ||||||||||||||||||||||||||||||||||||||||||
| 146 | get_connection => 'get', | ||||||||||||||||||||||||||||||||||||||||||
| 147 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 148 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 149 | has transfers => ( | ||||||||||||||||||||||||||||||||||||||||||
| 150 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||
| 151 | traits => ['Array'], | ||||||||||||||||||||||||||||||||||||||||||
| 152 | isa => ArrayRef[ Transfer ], | ||||||||||||||||||||||||||||||||||||||||||
| 153 | predicate => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 154 | 4 | ▶ | default => sub { [] }, | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 155 | 13 | init_arg => undef, | |||||||||||||||||||||||||||||||||||||||||
| 156 | handles => { | ||||||||||||||||||||||||||||||||||||||||||
| 157 | add_transfer => 'push', | ||||||||||||||||||||||||||||||||||||||||||
| 158 | all_transfers => 'elements', | ||||||||||||||||||||||||||||||||||||||||||
| 159 | transfer_count => 'count', | ||||||||||||||||||||||||||||||||||||||||||
| 160 | get_transfer => 'get', | ||||||||||||||||||||||||||||||||||||||||||
| 161 | filter_transfers => 'grep', | ||||||||||||||||||||||||||||||||||||||||||
| 162 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 163 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 164 | has routings => ( | ||||||||||||||||||||||||||||||||||||||||||
| 165 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||
| 166 | traits => ['Array'], | ||||||||||||||||||||||||||||||||||||||||||
| 167 | isa => ArrayRef[ Routing ], | ||||||||||||||||||||||||||||||||||||||||||
| 168 | predicate => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 169 | 4 | ▶ | default => sub { [] }, | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 170 | 13 | init_arg => undef, | |||||||||||||||||||||||||||||||||||||||||
| 171 | handles => { | ||||||||||||||||||||||||||||||||||||||||||
| 172 | add_routing => 'push', | ||||||||||||||||||||||||||||||||||||||||||
| 173 | all_routings => 'elements', | ||||||||||||||||||||||||||||||||||||||||||
| 174 | routing_count => 'count', | ||||||||||||||||||||||||||||||||||||||||||
| 175 | find_routing => 'first', | ||||||||||||||||||||||||||||||||||||||||||
| 176 | filter_routings => 'grep', | ||||||||||||||||||||||||||||||||||||||||||
| 177 | get_routing => 'get', | ||||||||||||||||||||||||||||||||||||||||||
| 178 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 179 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||||||||||||||||
| 181 | 13 | has full_graph => ( | |||||||||||||||||||||||||||||||||||||||||
| 182 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||
| 183 | lazy => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 184 | predicate => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 185 | builder => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 186 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||||||||||||||||
| 188 | 13 | has asps => ( | |||||||||||||||||||||||||||||||||||||||||
| 189 | is => 'rw', | ||||||||||||||||||||||||||||||||||||||||||
| 190 | lazy => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 191 | builder => 'calculate_shortest_paths', | ||||||||||||||||||||||||||||||||||||||||||
| 192 | predicate => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 193 | init_arg => undef, | ||||||||||||||||||||||||||||||||||||||||||
| 194 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||||||||||||||||
| 196 | 1 | ▶ | sub _build_full_graph { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_build_full_graph: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 197 | 1 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||||||||||||||||
| 199 | 1 | my $graph = Graph->new; | |||||||||||||||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||||||||||||||||
| 201 | 1 | foreach my $conn ($self->all_connections) { | |||||||||||||||||||||||||||||||||||||||||
| 202 | 60 | $graph->add_weighted_edge($conn->origin_line_station->line_station_id, | |||||||||||||||||||||||||||||||||||||||||
| 203 | $conn->destination_line_station->line_station_id, | ||||||||||||||||||||||||||||||||||||||||||
| 204 | $conn->weight); | ||||||||||||||||||||||||||||||||||||||||||
| 205 | } | ||||||||||||||||||||||||||||||||||||||||||
| 206 | 1 | return $graph; | |||||||||||||||||||||||||||||||||||||||||
| 207 | } | ||||||||||||||||||||||||||||||||||||||||||
| 208 | 0 | ▶ | sub calculate_shortest_paths { shift->full_graph->APSP_Floyd_Warshall } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
calculate_shortest_paths: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||||||||||||||||
| 210 | 4800 | ▶ | sub nocase { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
nocase: called CC=2 SCAR=7.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 211 | 4800 | my $text = shift; | |||||||||||||||||||||||||||||||||||||||||
| 212 | 4800 | ▶ | if($] >= 5.016000) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 213 | 4800 | $text = fc $text; | |||||||||||||||||||||||||||||||||||||||||
| 214 | } | ||||||||||||||||||||||||||||||||||||||||||
| 215 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 216 | 0 | $text = lc $text; | |||||||||||||||||||||||||||||||||||||||||
| 217 | } | ||||||||||||||||||||||||||||||||||||||||||
| 218 | 4800 | return $text; | |||||||||||||||||||||||||||||||||||||||||
| 219 | } | ||||||||||||||||||||||||||||||||||||||||||
| 220 | |||||||||||||||||||||||||||||||||||||||||||
| 221 | 4 | ▶ | sub parse { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
parse: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 222 | 4 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||||||||||||||||
| 224 | 4 | $self->build_network; | |||||||||||||||||||||||||||||||||||||||||
| 225 | 4 | $self->construct_connections; | |||||||||||||||||||||||||||||||||||||||||
| 226 | |||||||||||||||||||||||||||||||||||||||||||
| 227 | 4 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 228 | } | ||||||||||||||||||||||||||||||||||||||||||
| 229 | |||||||||||||||||||||||||||||||||||||||||||
| 230 | 4 | ▶ | sub build_network { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
build_network: called CC=10 SCAR=23.3
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 231 | 4 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 232 | |||||||||||||||||||||||||||||||||||||||||||
| 233 | 4 | my @rows = split /\r?\n/ => $self->filepath->slurp_utf8; | |||||||||||||||||||||||||||||||||||||||||
| 234 | 4 | my $context = undef; | |||||||||||||||||||||||||||||||||||||||||
| 235 | |||||||||||||||||||||||||||||||||||||||||||
| 236 | ROW: | ||||||||||||||||||||||||||||||||||||||||||
| 237 | 4 | foreach my $row (@rows) { | |||||||||||||||||||||||||||||||||||||||||
| 238 | 196 | ▶ | next ROW if !length $row || $row =~ m{^[ \t]*#}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
not length $row or $row =~ /^[ \t]*#/
MC/DC50%1/2
not length $row or $row =~ /^[ \t]*#/
not length $row
$row =~ /^[ \t]*#/
Truth table66%2/3
not(A) or B
A= not length $rowB= $row =~ /^[ \t]*#/
| |||||||||||||||||||||||||||||||||||||||||||
| 239 | |||||||||||||||||||||||||||||||||||||||||||
| 240 | 176 | ▶ | if($row =~ m{^--(\w+)} && (any { $_ eq $1 } qw/stations transfers lines segments/)) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
Condition66%2/3
$row =~ /^--(\w+)/ and &any(sub {
$_ eq $1;
}
, "stations", "transfers", "lines", "segments")
MC/DC50%1/2
$row =~ /^--(\w+)/ and &any(sub {
$_ eq $1;
}
, "stations", "transfers", "lines", "segments")
$row =~ /^--(\w+)/
&any(sub {
$_ eq $1;
}
, "stations", "transfers", "lines", "segments")
Truth table66%2/3
A and B
A= $row =~ /^--(\w+)/B= &any(sub {
$_ eq $1;
}
, "stations", "transfers", "lines", "segments")
| |||||||||||||||||||||||||||||||||||||||||||
| 241 | 12 | $context = $1; | |||||||||||||||||||||||||||||||||||||||||
| 242 | 12 | next ROW; | |||||||||||||||||||||||||||||||||||||||||
| 243 | } | ||||||||||||||||||||||||||||||||||||||||||
| 244 | |||||||||||||||||||||||||||||||||||||||||||
| 245 | 164 | ▶ | $context eq 'stations' ? $self->add_station($row) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 246 | : $context eq 'transfers' ? $self->add_transfer($row) | ||||||||||||||||||||||||||||||||||||||||||
| 247 | : $context eq 'lines' ? $self->add_line($row) | ||||||||||||||||||||||||||||||||||||||||||
| 248 | : $context eq 'segments' ? $self->add_segment($row) | ||||||||||||||||||||||||||||||||||||||||||
| 249 | : () | ||||||||||||||||||||||||||||||||||||||||||
| 250 | ; | ||||||||||||||||||||||||||||||||||||||||||
| 251 | } | ||||||||||||||||||||||||||||||||||||||||||
| 252 | } | ||||||||||||||||||||||||||||||||||||||||||
| 253 | |||||||||||||||||||||||||||||||||||||||||||
| 254 | 80 | ▶ | around add_station => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=4 SCAR=15.4
| |||||||||||||||||||||||||||||||||||||||||||
| 255 | 80 | my $next = shift; | |||||||||||||||||||||||||||||||||||||||||
| 256 | 80 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 257 | 80 | my $text = shift; | |||||||||||||||||||||||||||||||||||||||||
| 258 | |||||||||||||||||||||||||||||||||||||||||||
| 259 | 80 | $text = trim $text; | |||||||||||||||||||||||||||||||||||||||||
| 260 | 80 | my @names = split m{\h*%\h*} => $text; | |||||||||||||||||||||||||||||||||||||||||
| 261 | 80 | my $name = shift @names; | |||||||||||||||||||||||||||||||||||||||||
| 262 | |||||||||||||||||||||||||||||||||||||||||||
| 263 | 80 | ▶ | if(my $station = $self->get_station_by_name($name, check => 0)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 264 | 0 | return $station; | |||||||||||||||||||||||||||||||||||||||||
| 265 | } | ||||||||||||||||||||||||||||||||||||||||||
| 266 | |||||||||||||||||||||||||||||||||||||||||||
| 267 | 80 | my $id = $self->station_count + 1; | |||||||||||||||||||||||||||||||||||||||||
| 268 | 80 | my $station = Map::Metro::Graph::Station->new(original_name => $name, do_undiacritic => $self->do_undiacritic, eh $name, $id); | |||||||||||||||||||||||||||||||||||||||||
| 269 | |||||||||||||||||||||||||||||||||||||||||||
| 270 | 80 | foreach my $another_name (@names) { | |||||||||||||||||||||||||||||||||||||||||
| 271 | 0 | ▶ | if($another_name =~ m{^:(.+)}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 272 | 0 | $station->add_search_name($1); | |||||||||||||||||||||||||||||||||||||||||
| 273 | } | ||||||||||||||||||||||||||||||||||||||||||
| 274 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 275 | 0 | $station->add_alternative_name($another_name); | |||||||||||||||||||||||||||||||||||||||||
| 276 | } | ||||||||||||||||||||||||||||||||||||||||||
| 277 | } | ||||||||||||||||||||||||||||||||||||||||||
| 278 | 80 | $self->emit->before_add_station($station); | |||||||||||||||||||||||||||||||||||||||||
| 279 | 80 | $self->$next($station); | |||||||||||||||||||||||||||||||||||||||||
| 280 | 13 | }; | |||||||||||||||||||||||||||||||||||||||||
| 281 | |||||||||||||||||||||||||||||||||||||||||||
| 282 | 0 | ▶ | around add_transfer => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||
| 283 | 0 | my $next = shift; | |||||||||||||||||||||||||||||||||||||||||
| 284 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 285 | 0 | my $text = shift; | |||||||||||||||||||||||||||||||||||||||||
| 286 | |||||||||||||||||||||||||||||||||||||||||||
| 287 | 0 | $text = trim $text; | |||||||||||||||||||||||||||||||||||||||||
| 288 | |||||||||||||||||||||||||||||||||||||||||||
| 289 | 0 | my($origin_station_name, $destination_station_name, $option_string) = split /\|/ => $text; | |||||||||||||||||||||||||||||||||||||||||
| 290 | 0 | my $origin_station = $self->get_station_by_name($origin_station_name); | |||||||||||||||||||||||||||||||||||||||||
| 291 | 0 | my $destination_station = $self->get_station_by_name($destination_station_name); | |||||||||||||||||||||||||||||||||||||||||
| 292 | |||||||||||||||||||||||||||||||||||||||||||
| 293 | 0 | ▶ | my $options = defined $option_string ? $self->make_options($option_string, keys => [qw/weight/]) : {}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 294 | |||||||||||||||||||||||||||||||||||||||||||
| 295 | 0 | my $transfer = Map::Metro::Graph::Transfer->new(origin_station => $origin_station, | |||||||||||||||||||||||||||||||||||||||||
| 296 | destination_station => $destination_station, | ||||||||||||||||||||||||||||||||||||||||||
| 297 | %$options); | ||||||||||||||||||||||||||||||||||||||||||
| 298 | |||||||||||||||||||||||||||||||||||||||||||
| 299 | 0 | $self->$next($transfer); | |||||||||||||||||||||||||||||||||||||||||
| 300 | 13 | }; | |||||||||||||||||||||||||||||||||||||||||
| 301 | |||||||||||||||||||||||||||||||||||||||||||
| 302 | 8 | ▶ | around add_line => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 303 | 8 | my $next = shift; | |||||||||||||||||||||||||||||||||||||||||
| 304 | 8 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 305 | 8 | my $text = shift; | |||||||||||||||||||||||||||||||||||||||||
| 306 | |||||||||||||||||||||||||||||||||||||||||||
| 307 | 8 | $text = trim $text; | |||||||||||||||||||||||||||||||||||||||||
| 308 | 8 | my($id, $name, $description, $option_string) = split /\|/ => $text; | |||||||||||||||||||||||||||||||||||||||||
| 309 | |||||||||||||||||||||||||||||||||||||||||||
| 310 | 8 | ▶ | my $options = defined $option_string ? $self->make_options($option_string, keys => [qw/color width/]) : {}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 311 | 8 | my $line = Map::Metro::Graph::Line->new(%{ $options }, id => $id, name => $name, description => $description); | |||||||||||||||||||||||||||||||||||||||||
| 312 | |||||||||||||||||||||||||||||||||||||||||||
| 313 | 8 | $self->$next($line); | |||||||||||||||||||||||||||||||||||||||||
| 314 | 13 | }; | |||||||||||||||||||||||||||||||||||||||||
| 315 | |||||||||||||||||||||||||||||||||||||||||||
| 316 | 76 | ▶ | around add_segment => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=9 SCAR=25.2
| |||||||||||||||||||||||||||||||||||||||||||
| 317 | 76 | my $next = shift; | |||||||||||||||||||||||||||||||||||||||||
| 318 | 76 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 319 | 76 | my $text = shift; | |||||||||||||||||||||||||||||||||||||||||
| 320 | |||||||||||||||||||||||||||||||||||||||||||
| 321 | 76 | $text = trim $text; | |||||||||||||||||||||||||||||||||||||||||
| 322 | 76 | my($linestring, $start, $end, $option_string) = split /\|/ => $text; | |||||||||||||||||||||||||||||||||||||||||
| 323 | 76 | my @line_ids_with_dir = split m/,/ => $linestring; | |||||||||||||||||||||||||||||||||||||||||
| 324 | 76 | my @clean_line_ids = map { (my $clean = $_) =~ s{[^a-z0-9]}{}gi; $clean } @line_ids_with_dir; | |||||||||||||||||||||||||||||||||||||||||
| 325 | |||||||||||||||||||||||||||||||||||||||||||
| 326 | 76 | ▶ | my $options = defined $option_string ? $self->make_options($option_string, keys => [qw/dir/]) : {}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 327 | |||||||||||||||||||||||||||||||||||||||||||
| 328 | #* Check that lines and stations in segments exist in the other lists | ||||||||||||||||||||||||||||||||||||||||||
| 329 | 76 | my($origin_station, $destination_station); | |||||||||||||||||||||||||||||||||||||||||
| 330 | |||||||||||||||||||||||||||||||||||||||||||
| 331 | 76 | ▶ | try { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 332 | 76 | $self->get_line_by_id($_) foreach @clean_line_ids; | |||||||||||||||||||||||||||||||||||||||||
| 333 | 76 | $origin_station = $self->get_station_by_name($start); | |||||||||||||||||||||||||||||||||||||||||
| 334 | 76 | $destination_station = $self->get_station_by_name($end); | |||||||||||||||||||||||||||||||||||||||||
| 335 | } | ||||||||||||||||||||||||||||||||||||||||||
| 336 | 0 | ▶ | catch { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||
| 337 | 0 | ▶ | die($_->$_call_if_object('desc') || $_); | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$_->$Map::Metro::Graph::_call_if_object('desc') || $_
MC/DC0%0/2
$_->$Map::Metro::Graph::_call_if_object('desc') || $_
$_->$Map::Metro::Graph::_call_if_object('desc')
$_
Truth table0%0/3
A || B
A= $_->$Map::Metro::Graph::_call_if_object('desc')B= $_
| |||||||||||||||||||||||||||||||||||||||||||
| 338 | 76 | }; | |||||||||||||||||||||||||||||||||||||||||
| 339 | 76 | my @both_dir = (); | |||||||||||||||||||||||||||||||||||||||||
| 340 | 76 | my @forward = (); | |||||||||||||||||||||||||||||||||||||||||
| 341 | 76 | my @backward = (); | |||||||||||||||||||||||||||||||||||||||||
| 342 | 76 | my @segments = (); | |||||||||||||||||||||||||||||||||||||||||
| 343 | |||||||||||||||||||||||||||||||||||||||||||
| 344 | 76 | foreach my $line_info (@line_ids_with_dir) { | |||||||||||||||||||||||||||||||||||||||||
| 345 | 96 | ▶ | if($line_info =~ m{^[a-z0-9]+$}i) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 346 | 96 | push @both_dir => $line_info; | |||||||||||||||||||||||||||||||||||||||||
| 347 | } | ||||||||||||||||||||||||||||||||||||||||||
| 348 | elsif($line_info =~ m{^([a-z0-9]+)->$}i) { | ||||||||||||||||||||||||||||||||||||||||||
| 349 | 0 | push @forward => $1; | |||||||||||||||||||||||||||||||||||||||||
| 350 | } | ||||||||||||||||||||||||||||||||||||||||||
| 351 | elsif($line_info =~ m{^([a-z0-9]+)<-$}i) { | ||||||||||||||||||||||||||||||||||||||||||
| 352 | 0 | push @backward => $1; | |||||||||||||||||||||||||||||||||||||||||
| 353 | } | ||||||||||||||||||||||||||||||||||||||||||
| 354 | } | ||||||||||||||||||||||||||||||||||||||||||
| 355 | |||||||||||||||||||||||||||||||||||||||||||
| 356 | 76 | ▶ | if(scalar @both_dir) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 357 | 76 | push @segments => Map::Metro::Graph::Segment->new(line_ids => \@both_dir, origin_station => $origin_station, destination_station => $destination_station); | |||||||||||||||||||||||||||||||||||||||||
| 358 | } | ||||||||||||||||||||||||||||||||||||||||||
| 359 | 76 | ▶ | if(scalar @forward) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 360 | 0 | push @segments => Map::Metro::Graph::Segment->new(line_ids => \@forward, is_one_way => 1, origin_station => $origin_station, destination_station => $destination_station); | |||||||||||||||||||||||||||||||||||||||||
| 361 | } | ||||||||||||||||||||||||||||||||||||||||||
| 362 | 76 | ▶ | if(scalar @backward) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 363 | 0 | push @segments => Map::Metro::Graph::Segment->new(line_ids => \@backward, is_one_way => 1, origin_station => $destination_station, destination_station => $origin_station); | |||||||||||||||||||||||||||||||||||||||||
| 364 | } | ||||||||||||||||||||||||||||||||||||||||||
| 365 | |||||||||||||||||||||||||||||||||||||||||||
| 366 | 76 | $self->$next(@segments); | |||||||||||||||||||||||||||||||||||||||||
| 367 | 13 | }; | |||||||||||||||||||||||||||||||||||||||||
| 368 | |||||||||||||||||||||||||||||||||||||||||||
| 369 | 192 | ▶ | around add_line_station => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 370 | 192 | my $next = shift; | |||||||||||||||||||||||||||||||||||||||||
| 371 | 192 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 372 | 192 | my $line_station = shift; | |||||||||||||||||||||||||||||||||||||||||
| 373 | |||||||||||||||||||||||||||||||||||||||||||
| 374 | 192 | my $exists = $self->get_line_station_by_line_and_station_id($line_station->line->id, $line_station->station->id); | |||||||||||||||||||||||||||||||||||||||||
| 375 | 192 | ▶ | return $exists if $exists; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 376 | |||||||||||||||||||||||||||||||||||||||||||
| 377 | 104 | $self->$next($line_station); | |||||||||||||||||||||||||||||||||||||||||
| 378 | 104 | return $line_station; | |||||||||||||||||||||||||||||||||||||||||
| 379 | 13 | }; | |||||||||||||||||||||||||||||||||||||||||
| 380 | |||||||||||||||||||||||||||||||||||||||||||
| 381 | 193 | ▶ | sub get_line_by_id { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_line_by_id: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 382 | 193 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 383 | 193 | my $line_id = shift; # Str | |||||||||||||||||||||||||||||||||||||||||
| 384 | 193 | ▶ | return $self->find_line(sub { $_->id eq $line_id }) || die lineid_does_not_exist_in_line_list line_id => $line_id; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
Condition100%2/2
$self->find_line(sub {
$_->id eq $line_id;
}
) || die(lineid_does_not_exist_in_line_list('line_id', $line_id))
MC/DC100%1/1
$self->find_line(sub {
$_->id eq $line_id;
}
) || die(lineid_does_not_exist_in_line_list('line_id', $line_id))
$self->find_line(sub {
$_->id eq $line_id;
}
)
Truth table100%2/2
A
A= $self->find_line(sub {
$_->id eq $line_id;
}
)
| |||||||||||||||||||||||||||||||||||||||||||
| 385 | } | ||||||||||||||||||||||||||||||||||||||||||
| 386 | |||||||||||||||||||||||||||||||||||||||||||
| 387 | 233 | ▶ | sub get_station_by_name { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_station_by_name: called CC=7 SCAR=20.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 388 | 233 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 389 | 233 | my $station_name = shift; # Str | |||||||||||||||||||||||||||||||||||||||||
| 390 | 233 | my %args = @_; | |||||||||||||||||||||||||||||||||||||||||
| 391 | 233 | ▶ | my $check = exists $args{'check'} ? $args{'check'} : 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 392 | |||||||||||||||||||||||||||||||||||||||||||
| 393 | 233 | ▶ | my $station = $self->find_station(sub { nocase($_->name) eq nocase($station_name) }); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 394 | 233 | ▶ | return $station if Station->check($station); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 395 | |||||||||||||||||||||||||||||||||||||||||||
| 396 | 81 | ▶ | if($check) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 397 | 1 | ▶ | $station = $self->find_station(sub { nocase($_->original_name) eq nocase($station_name) }); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 398 | 1 | ▶ | return $station if Station->check($station); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 399 | |||||||||||||||||||||||||||||||||||||||||||
| 400 | 20 | ▶ | $station = $self->find_station(sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=9.2
| |||||||||||||||||||||||||||||||||||||||||||
| 401 | 20 | my $current_station = $_; | |||||||||||||||||||||||||||||||||||||||||
| 402 | 0 | ▶ | if(any { nocase($station_name) eq nocase($_) } $current_station->all_alternative_names) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 403 | 0 | return $current_station; | |||||||||||||||||||||||||||||||||||||||||
| 404 | } | ||||||||||||||||||||||||||||||||||||||||||
| 405 | 1 | }); | |||||||||||||||||||||||||||||||||||||||||
| 406 | 1 | ▶ | return $station if Station->check($station); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 407 | |||||||||||||||||||||||||||||||||||||||||||
| 408 | 20 | ▶ | $station = $self->find_station(sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.6
| |||||||||||||||||||||||||||||||||||||||||||
| 409 | 20 | my $current_station = $_; | |||||||||||||||||||||||||||||||||||||||||
| 410 | 20 | ▶ | if(any { nocase($station_name) eq nocase($_) } $current_station->all_search_names) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.2
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 411 | 0 | return $current_station; | |||||||||||||||||||||||||||||||||||||||||
| 412 | } | ||||||||||||||||||||||||||||||||||||||||||
| 413 | 1 | }); | |||||||||||||||||||||||||||||||||||||||||
| 414 | 1 | ▶ | return $station if Station->check($station); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 415 | |||||||||||||||||||||||||||||||||||||||||||
| 416 | 1 | die station_name_does_not_exist_in_station_list station_name => $station_name; | |||||||||||||||||||||||||||||||||||||||||
| 417 | } | ||||||||||||||||||||||||||||||||||||||||||
| 418 | } | ||||||||||||||||||||||||||||||||||||||||||
| 419 | |||||||||||||||||||||||||||||||||||||||||||
| 420 | 2 | ▶ | sub get_station_by_id { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_station_by_id: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 421 | 2 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 422 | 2 | my $id = shift; # Int | |||||||||||||||||||||||||||||||||||||||||
| 423 | |||||||||||||||||||||||||||||||||||||||||||
| 424 | 2 | ▶ | return $self->find_station(sub { $_->id == $id }) || die stationid_does_not_exist station_id => $id; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.2
Condition50%1/2
$self->find_station(sub {
$_->id == $id;
}
) || die(stationid_does_not_exist('station_id', $id))
MC/DC0%0/1
$self->find_station(sub {
$_->id == $id;
}
) || die(stationid_does_not_exist('station_id', $id))
$self->find_station(sub {
$_->id == $id;
}
)
Truth table50%1/2
A
A= $self->find_station(sub {
$_->id == $id;
}
)
| |||||||||||||||||||||||||||||||||||||||||||
| 425 | } | ||||||||||||||||||||||||||||||||||||||||||
| 426 | |||||||||||||||||||||||||||||||||||||||||||
| 427 | 82 | ▶ | sub get_line_stations_by_station { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_line_stations_by_station: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 428 | 82 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 429 | 82 | my $station = shift; # Station | |||||||||||||||||||||||||||||||||||||||||
| 430 | 82 | ▶ | return $self->find_line_stations(sub { $_->station->id == $station->id }); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 431 | } | ||||||||||||||||||||||||||||||||||||||||||
| 432 | |||||||||||||||||||||||||||||||||||||||||||
| 433 | 384 | ▶ | sub get_line_station_by_line_and_station_id { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_line_station_by_line_and_station_id: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 434 | 384 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 435 | 384 | my $line_id = shift; | |||||||||||||||||||||||||||||||||||||||||
| 436 | 384 | my $station_id = shift; | |||||||||||||||||||||||||||||||||||||||||
| 437 | |||||||||||||||||||||||||||||||||||||||||||
| 438 | 384 | ▶ | return $self->find_line_station(sub { $_->line->id eq $line_id && $_->station->id == $station_id }); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 439 | } | ||||||||||||||||||||||||||||||||||||||||||
| 440 | |||||||||||||||||||||||||||||||||||||||||||
| 441 | 16 | ▶ | sub get_line_station_by_id { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_line_station_by_id: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 442 | 16 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 443 | 16 | my $line_station_id = shift; # Int | |||||||||||||||||||||||||||||||||||||||||
| 444 | |||||||||||||||||||||||||||||||||||||||||||
| 445 | 16 | ▶ | return $self->find_line_station(sub { $_->line_station_id == $line_station_id }); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 446 | } | ||||||||||||||||||||||||||||||||||||||||||
| 447 | |||||||||||||||||||||||||||||||||||||||||||
| 448 | 5 | ▶ | sub get_connection_by_line_station_ids { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_connection_by_line_station_ids: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 449 | 5 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 450 | 5 | my $first_ls_id = shift; # Int | |||||||||||||||||||||||||||||||||||||||||
| 451 | 5 | my $second_ls_id = shift; # Int | |||||||||||||||||||||||||||||||||||||||||
| 452 | |||||||||||||||||||||||||||||||||||||||||||
| 453 | 5 | my $first_ls = $self->get_line_station_by_id($first_ls_id); | |||||||||||||||||||||||||||||||||||||||||
| 454 | 5 | my $second_ls = $self->get_line_station_by_id($second_ls_id); | |||||||||||||||||||||||||||||||||||||||||
| 455 | |||||||||||||||||||||||||||||||||||||||||||
| 456 | return $self->find_connection( | ||||||||||||||||||||||||||||||||||||||||||
| 457 | 13 | ▶ | sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 458 | 13 | ▶ | $_->origin_line_station->line_station_id == $first_ls->line_station_id | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 459 | && $_->destination_line_station->line_station_id == $second_ls->line_station_id | ||||||||||||||||||||||||||||||||||||||||||
| 460 | } | ||||||||||||||||||||||||||||||||||||||||||
| 461 | 5 | ); | |||||||||||||||||||||||||||||||||||||||||
| 462 | } | ||||||||||||||||||||||||||||||||||||||||||
| 463 | |||||||||||||||||||||||||||||||||||||||||||
| 464 | 0 | ▶ | sub next_line_station_id { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
next_line_station_id: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 465 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 466 | |||||||||||||||||||||||||||||||||||||||||||
| 467 | 0 | return $self->line_station_count + 1; | |||||||||||||||||||||||||||||||||||||||||
| 468 | } | ||||||||||||||||||||||||||||||||||||||||||
| 469 | |||||||||||||||||||||||||||||||||||||||||||
| 470 | 0 | ▶ | sub make_options { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
make_options: not called CC=5 SCAR=34.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 471 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 472 | 0 | my $string = shift; | |||||||||||||||||||||||||||||||||||||||||
| 473 | 0 | my %args = @_; | |||||||||||||||||||||||||||||||||||||||||
| 474 | 0 | ▶ | my $keys = exists $args{'keys'} ? $args{'keys'} : []; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 475 | |||||||||||||||||||||||||||||||||||||||||||
| 476 | 0 | my $options = {}; | |||||||||||||||||||||||||||||||||||||||||
| 477 | 0 | my @options = split /, ?/ => $string; | |||||||||||||||||||||||||||||||||||||||||
| 478 | |||||||||||||||||||||||||||||||||||||||||||
| 479 | OPTION: | ||||||||||||||||||||||||||||||||||||||||||
| 480 | 0 | foreach my $option (@options) { | |||||||||||||||||||||||||||||||||||||||||
| 481 | 0 | my($key, $value) = split /:/ => $option; | |||||||||||||||||||||||||||||||||||||||||
| 482 | |||||||||||||||||||||||||||||||||||||||||||
| 483 | 0 | ▶ | next OPTION if scalar @$keys && (none { $key eq $_ } @$keys); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
Condition0%0/3
scalar @$keys and &none(sub {
$key eq $_;
}
, @$keys)
MC/DC0%0/2
scalar @$keys and &none(sub {
$key eq $_;
}
, @$keys)
scalar @$keys
&none(sub {
$key eq $_;
}
, @$keys)
Truth table0%0/3
A and B
A= scalar @$keysB= &none(sub {
$key eq $_;
}
, @$keys)
| |||||||||||||||||||||||||||||||||||||||||||
| 484 | 0 | $options->{ $key } = $value; | |||||||||||||||||||||||||||||||||||||||||
| 485 | } | ||||||||||||||||||||||||||||||||||||||||||
| 486 | 0 | return $options; | |||||||||||||||||||||||||||||||||||||||||
| 487 | } | ||||||||||||||||||||||||||||||||||||||||||
| 488 | |||||||||||||||||||||||||||||||||||||||||||
| 489 | 4 | ▶ | sub construct_connections { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
construct_connections: called CC=17 SCAR=34.6
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 490 | 4 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 491 | |||||||||||||||||||||||||||||||||||||||||||
| 492 | 4 | ▶ | if(!($self->has_stations && $self->has_lines && $self->has_segments)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
$self->has_stations and $self->has_lines and $self->has_segments
$self->has_stations and $self->has_lines
MC/DC0%0/3
$self->has_stations and $self->has_lines and $self->has_segments
$self->has_stations
$self->has_lines
$self->has_segments
Truth table25%1/4
A and B and C
A= $self->has_stationsB= $self->has_linesC= $self->has_segments
| |||||||||||||||||||||||||||||||||||||||||||
| 493 | 0 | die incomplete_parse mapfile => $self->filepath; | |||||||||||||||||||||||||||||||||||||||||
| 494 | } | ||||||||||||||||||||||||||||||||||||||||||
| 495 | |||||||||||||||||||||||||||||||||||||||||||
| 496 | #* Walk through all segments, and all lines for | ||||||||||||||||||||||||||||||||||||||||||
| 497 | #* that segment. Add pairwise connections between | ||||||||||||||||||||||||||||||||||||||||||
| 498 | #* all pair of stations on the same line | ||||||||||||||||||||||||||||||||||||||||||
| 499 | 4 | my $next_line_station_id = 0; | |||||||||||||||||||||||||||||||||||||||||
| 500 | SEGMENT: | ||||||||||||||||||||||||||||||||||||||||||
| 501 | 4 | foreach my $segment ($self->all_segments) { | |||||||||||||||||||||||||||||||||||||||||
| 502 | |||||||||||||||||||||||||||||||||||||||||||
| 503 | LINE: | ||||||||||||||||||||||||||||||||||||||||||
| 504 | 76 | foreach my $line_id ($segment->all_line_ids) { | |||||||||||||||||||||||||||||||||||||||||
| 505 | 96 | my $line = $self->get_line_by_id($line_id); | |||||||||||||||||||||||||||||||||||||||||
| 506 | |||||||||||||||||||||||||||||||||||||||||||
| 507 | 96 | ▶ | my $origin_line_station = $self->get_line_station_by_line_and_station_id($line_id, $segment->origin_station->id) | ||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$self->get_line_station_by_line_and_station_id($line_id, $segment->origin_station->id) || &LineStation()->new('line_station_id', ++$next_line_station_id, 'station', $segment->origin_station, 'line', $line)
MC/DC0%0/2
$self->get_line_station_by_line_and_station_id($line_id, $segment->origin_station->id) || &LineStation()->new('line_station_id', ++$next_line_station_id, 'station', $segment->origin_station, 'line', $line)
$self->get_line_station_by_line_and_station_id($line_id, $segment->origin_station->id)
&LineStation()->new('line_station_id', ++$next_line_station_id, 'station', $segment->origin_station, 'line', $line)
Truth table66%2/3
A || B
A= $self->get_line_station_by_line_and_station_id($line_id, $segment->origin_station->id)B= &LineStation()->new('line_station_id', ++$next_line_station_id, 'station', $segment->origin_station, 'line', $line)
| |||||||||||||||||||||||||||||||||||||||||||
| 508 | || | ||||||||||||||||||||||||||||||||||||||||||
| 509 | Map::Metro::Graph::LineStation->new( | ||||||||||||||||||||||||||||||||||||||||||
| 510 | line_station_id => ++$next_line_station_id, | ||||||||||||||||||||||||||||||||||||||||||
| 511 | station => $segment->origin_station, | ||||||||||||||||||||||||||||||||||||||||||
| 512 | line => $line, | ||||||||||||||||||||||||||||||||||||||||||
| 513 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 514 | 96 | $origin_line_station = $self->add_line_station($origin_line_station); | |||||||||||||||||||||||||||||||||||||||||
| 515 | 96 | $segment->origin_station->add_line($line); | |||||||||||||||||||||||||||||||||||||||||
| 516 | |||||||||||||||||||||||||||||||||||||||||||
| 517 | 96 | ▶ | my $destination_line_station = $self->get_line_station_by_line_and_station_id($line_id, $segment->destination_station->id) | ||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$self->get_line_station_by_line_and_station_id($line_id, $segment->destination_station->id) || &LineStation()->new('line_station_id', ++$next_line_station_id, 'station', $segment->destination_station, 'line', $line)
MC/DC0%0/2
$self->get_line_station_by_line_and_station_id($line_id, $segment->destination_station->id) || &LineStation()->new('line_station_id', ++$next_line_station_id, 'station', $segment->destination_station, 'line', $line)
$self->get_line_station_by_line_and_station_id($line_id, $segment->destination_station->id)
&LineStation()->new('line_station_id', ++$next_line_station_id, 'station', $segment->destination_station, 'line', $line)
Truth table66%2/3
A || B
A= $self->get_line_station_by_line_and_station_id($line_id, $segment->destination_station->id)B= &LineStation()->new('line_station_id', ++$next_line_station_id, 'station', $segment->destination_station, 'line', $line)
| |||||||||||||||||||||||||||||||||||||||||||
| 518 | || | ||||||||||||||||||||||||||||||||||||||||||
| 519 | Map::Metro::Graph::LineStation->new( | ||||||||||||||||||||||||||||||||||||||||||
| 520 | line_station_id => ++$next_line_station_id, | ||||||||||||||||||||||||||||||||||||||||||
| 521 | station => $segment->destination_station, | ||||||||||||||||||||||||||||||||||||||||||
| 522 | line => $line, | ||||||||||||||||||||||||||||||||||||||||||
| 523 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 524 | 96 | $destination_line_station = $self->add_line_station($destination_line_station); | |||||||||||||||||||||||||||||||||||||||||
| 525 | 96 | $segment->destination_station->add_line($line); | |||||||||||||||||||||||||||||||||||||||||
| 526 | |||||||||||||||||||||||||||||||||||||||||||
| 527 | 96 | my $weight = 1; | |||||||||||||||||||||||||||||||||||||||||
| 528 | |||||||||||||||||||||||||||||||||||||||||||
| 529 | 96 | my $conn = Map::Metro::Graph::Connection->new(origin_line_station => $origin_line_station, | |||||||||||||||||||||||||||||||||||||||||
| 530 | destination_line_station => $destination_line_station, | ||||||||||||||||||||||||||||||||||||||||||
| 531 | weight => $weight); | ||||||||||||||||||||||||||||||||||||||||||
| 532 | |||||||||||||||||||||||||||||||||||||||||||
| 533 | 96 | my $inv_conn = Map::Metro::Graph::Connection->new(origin_line_station => $destination_line_station, | |||||||||||||||||||||||||||||||||||||||||
| 534 | destination_line_station => $origin_line_station, | ||||||||||||||||||||||||||||||||||||||||||
| 535 | weight => $weight); | ||||||||||||||||||||||||||||||||||||||||||
| 536 | |||||||||||||||||||||||||||||||||||||||||||
| 537 | 96 | $origin_line_station->station->add_connecting_station($destination_line_station->station); | |||||||||||||||||||||||||||||||||||||||||
| 538 | 96 | ▶ | $destination_line_station->station->add_connecting_station($origin_line_station->station) if !$segment->is_one_way; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 539 | |||||||||||||||||||||||||||||||||||||||||||
| 540 | 96 | $self->add_connection($conn); | |||||||||||||||||||||||||||||||||||||||||
| 541 | 96 | ▶ | $self->add_connection($inv_conn) if !$segment->is_one_way; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 542 | } | ||||||||||||||||||||||||||||||||||||||||||
| 543 | } | ||||||||||||||||||||||||||||||||||||||||||
| 544 | |||||||||||||||||||||||||||||||||||||||||||
| 545 | #* Walk through all stations, and fetch all line_stations per station | ||||||||||||||||||||||||||||||||||||||||||
| 546 | #* Then add a connection between all line_stations of every station | ||||||||||||||||||||||||||||||||||||||||||
| 547 | STATION: | ||||||||||||||||||||||||||||||||||||||||||
| 548 | 4 | foreach my $station ($self->all_stations) { | |||||||||||||||||||||||||||||||||||||||||
| 549 | 80 | my @line_stations_at_station = $self->get_line_stations_by_station($station); | |||||||||||||||||||||||||||||||||||||||||
| 550 | |||||||||||||||||||||||||||||||||||||||||||
| 551 | LINE_STATION: | ||||||||||||||||||||||||||||||||||||||||||
| 552 | 80 | foreach my $line_station (@line_stations_at_station) { | |||||||||||||||||||||||||||||||||||||||||
| 553 | 104 | my @other_line_stations = grep { $_->line_station_id != $line_station->line_station_id } @line_stations_at_station; | |||||||||||||||||||||||||||||||||||||||||
| 554 | |||||||||||||||||||||||||||||||||||||||||||
| 555 | OTHER_LINE_STATION: | ||||||||||||||||||||||||||||||||||||||||||
| 556 | 104 | foreach my $other_line_station (@other_line_stations) { | |||||||||||||||||||||||||||||||||||||||||
| 557 | |||||||||||||||||||||||||||||||||||||||||||
| 558 | 48 | ▶ | my $weight = $self->has_override_line_change_weight ? $self->override_line_change_weight : $self->default_line_change_weight; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 559 | 48 | my $conn = Map::Metro::Graph::Connection->new(origin_line_station => $line_station, | |||||||||||||||||||||||||||||||||||||||||
| 560 | destination_line_station => $other_line_station, | ||||||||||||||||||||||||||||||||||||||||||
| 561 | weight => $weight); | ||||||||||||||||||||||||||||||||||||||||||
| 562 | 48 | $self->add_connection($conn); | |||||||||||||||||||||||||||||||||||||||||
| 563 | } | ||||||||||||||||||||||||||||||||||||||||||
| 564 | } | ||||||||||||||||||||||||||||||||||||||||||
| 565 | } | ||||||||||||||||||||||||||||||||||||||||||
| 566 | |||||||||||||||||||||||||||||||||||||||||||
| 567 | #* Walk through all transfers, and add connections between all line stations of the two stations | ||||||||||||||||||||||||||||||||||||||||||
| 568 | TRANSFER: | ||||||||||||||||||||||||||||||||||||||||||
| 569 | 4 | foreach my $transfer ($self->all_transfers) { | |||||||||||||||||||||||||||||||||||||||||
| 570 | 0 | my $origin_station = $transfer->origin_station; | |||||||||||||||||||||||||||||||||||||||||
| 571 | 0 | my $destination_station = $transfer->destination_station; | |||||||||||||||||||||||||||||||||||||||||
| 572 | 0 | my @line_stations_at_origin = $self->get_line_stations_by_station($origin_station); | |||||||||||||||||||||||||||||||||||||||||
| 573 | |||||||||||||||||||||||||||||||||||||||||||
| 574 | ORIGIN_LINE_STATION: | ||||||||||||||||||||||||||||||||||||||||||
| 575 | 0 | foreach my $origin_line_station (@line_stations_at_origin) { | |||||||||||||||||||||||||||||||||||||||||
| 576 | 0 | my @line_stations_at_destination = $self->get_line_stations_by_station($destination_station); | |||||||||||||||||||||||||||||||||||||||||
| 577 | |||||||||||||||||||||||||||||||||||||||||||
| 578 | DESTINATION_LINE_STATION: | ||||||||||||||||||||||||||||||||||||||||||
| 579 | 0 | foreach my $destination_line_station (@line_stations_at_destination) { | |||||||||||||||||||||||||||||||||||||||||
| 580 | |||||||||||||||||||||||||||||||||||||||||||
| 581 | 0 | my $conn = Map::Metro::Graph::Connection->new(origin_line_station => $origin_line_station, | |||||||||||||||||||||||||||||||||||||||||
| 582 | destination_line_station => $destination_line_station, | ||||||||||||||||||||||||||||||||||||||||||
| 583 | weight => $transfer->weight); | ||||||||||||||||||||||||||||||||||||||||||
| 584 | |||||||||||||||||||||||||||||||||||||||||||
| 585 | 0 | my $inv_conn = Map::Metro::Graph::Connection->new(origin_line_station => $destination_line_station, | |||||||||||||||||||||||||||||||||||||||||
| 586 | destination_line_station => $origin_line_station, | ||||||||||||||||||||||||||||||||||||||||||
| 587 | weight => $transfer->weight); | ||||||||||||||||||||||||||||||||||||||||||
| 588 | |||||||||||||||||||||||||||||||||||||||||||
| 589 | 0 | $origin_line_station->station->add_connecting_station($destination_line_station->station); | |||||||||||||||||||||||||||||||||||||||||
| 590 | 0 | $destination_line_station->station->add_connecting_station($origin_line_station->station); | |||||||||||||||||||||||||||||||||||||||||
| 591 | |||||||||||||||||||||||||||||||||||||||||||
| 592 | 0 | $self->add_connection($conn); | |||||||||||||||||||||||||||||||||||||||||
| 593 | 0 | $self->add_connection($inv_conn); | |||||||||||||||||||||||||||||||||||||||||
| 594 | } | ||||||||||||||||||||||||||||||||||||||||||
| 595 | } | ||||||||||||||||||||||||||||||||||||||||||
| 596 | |||||||||||||||||||||||||||||||||||||||||||
| 597 | } | ||||||||||||||||||||||||||||||||||||||||||
| 598 | } | ||||||||||||||||||||||||||||||||||||||||||
| 599 | |||||||||||||||||||||||||||||||||||||||||||
| 600 | # --> Station | ||||||||||||||||||||||||||||||||||||||||||
| 601 | 2 | ▶ | sub ensure_station { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
ensure_station: called CC=2 SCAR=8.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 602 | 2 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 603 | 2 | my $place = shift; # Int|Str|Station | |||||||||||||||||||||||||||||||||||||||||
| 604 | |||||||||||||||||||||||||||||||||||||||||||
| 605 | 2 | ▶ | return $place if Station->check($place); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 606 | |||||||||||||||||||||||||||||||||||||||||||
| 607 | 2 | ▶ | try { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=8.1
| |||||||||||||||||||||||||||||||||||||||||||
| 608 | 2 | ▶ | if(Int->check($place)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 609 | 2 | $place = $self->get_station_by_id($place); | |||||||||||||||||||||||||||||||||||||||||
| 610 | } | ||||||||||||||||||||||||||||||||||||||||||
| 611 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 612 | 0 | $place = $self->get_station_by_name($place); | |||||||||||||||||||||||||||||||||||||||||
| 613 | } | ||||||||||||||||||||||||||||||||||||||||||
| 614 | } | ||||||||||||||||||||||||||||||||||||||||||
| 615 | 0 | ▶ | catch { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||
| 616 | 0 | my $error = $_; | |||||||||||||||||||||||||||||||||||||||||
| 617 | 0 | ▶ | die ($error->$_call_if_object('desc') || $error); | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$error->$Map::Metro::Graph::_call_if_object('desc') || $error
MC/DC0%0/2
$error->$Map::Metro::Graph::_call_if_object('desc') || $error
$error->$Map::Metro::Graph::_call_if_object('desc')
$error
Truth table0%0/3
A || B
A= $error->$Map::Metro::Graph::_call_if_object('desc')B= $error
| |||||||||||||||||||||||||||||||||||||||||||
| 618 | 2 | }; | |||||||||||||||||||||||||||||||||||||||||
| 619 | 2 | return $place; | |||||||||||||||||||||||||||||||||||||||||
| 620 | } | ||||||||||||||||||||||||||||||||||||||||||
| 621 | |||||||||||||||||||||||||||||||||||||||||||
| 622 | # --> Routing | ||||||||||||||||||||||||||||||||||||||||||
| 623 | 1 | ▶ | sub routing_for { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
routing_for: called CC=20 SCAR=31.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 624 | 1 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 625 | 1 | my $origin = shift; # Int|Str|Station The first station. Station id, name or object. | |||||||||||||||||||||||||||||||||||||||||
| 626 | 1 | my $destination = shift; # Int|Str|Station The final station. Station id, name or object. | |||||||||||||||||||||||||||||||||||||||||
| 627 | |||||||||||||||||||||||||||||||||||||||||||
| 628 | 1 | my $origin_station = $self->ensure_station($origin); | |||||||||||||||||||||||||||||||||||||||||
| 629 | 1 | my $destination_station = $self->ensure_station($destination); | |||||||||||||||||||||||||||||||||||||||||
| 630 | |||||||||||||||||||||||||||||||||||||||||||
| 631 | 1 | my @origin_line_station_ids = map { $_->line_station_id } $self->get_line_stations_by_station($origin_station); | |||||||||||||||||||||||||||||||||||||||||
| 632 | 1 | my @destination_line_station_ids = map { $_->line_station_id } $self->get_line_stations_by_station($destination_station); | |||||||||||||||||||||||||||||||||||||||||
| 633 | |||||||||||||||||||||||||||||||||||||||||||
| 634 | 1 | ▶ | if($self->has_routings) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 635 | 0 | ▶ | my $existing_routing = $self->find_routing(sub { $_->origin_station->id == $origin_station->id && $_->destination_station->id == $destination_station->id }); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=13.0
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 636 | 1 | ▶ | return $existing_routing if $existing_routing; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 637 | } | ||||||||||||||||||||||||||||||||||||||||||
| 638 | 1 | $self->emit->before_start_routing; | |||||||||||||||||||||||||||||||||||||||||
| 639 | 1 | my $routing = Map::Metro::Graph::Routing->new(origin_station => $origin_station, destination_station => $destination_station); | |||||||||||||||||||||||||||||||||||||||||
| 640 | |||||||||||||||||||||||||||||||||||||||||||
| 641 | #* Find all lines going from origin station | ||||||||||||||||||||||||||||||||||||||||||
| 642 | #* Find all lines going to destination station | ||||||||||||||||||||||||||||||||||||||||||
| 643 | #* Get all routes between them | ||||||||||||||||||||||||||||||||||||||||||
| 644 | #* and then, in the third and fourth for, loop over the | ||||||||||||||||||||||||||||||||||||||||||
| 645 | #* found routes and add info about all stations on all lines | ||||||||||||||||||||||||||||||||||||||||||
| 646 | ORIGIN_LINE_STATION: | ||||||||||||||||||||||||||||||||||||||||||
| 647 | 1 | foreach my $origin_id (@origin_line_station_ids) { | |||||||||||||||||||||||||||||||||||||||||
| 648 | 1 | my $origin = $self->get_line_station_by_id($origin_id); | |||||||||||||||||||||||||||||||||||||||||
| 649 | |||||||||||||||||||||||||||||||||||||||||||
| 650 | DESTINATION_LINE_STATION: | ||||||||||||||||||||||||||||||||||||||||||
| 651 | 1 | foreach my $dest_id (@destination_line_station_ids) { | |||||||||||||||||||||||||||||||||||||||||
| 652 | 1 | my $dest = $self->get_line_station_by_id($dest_id); | |||||||||||||||||||||||||||||||||||||||||
| 653 | |||||||||||||||||||||||||||||||||||||||||||
| 654 | 1 | ▶ | my $graphroute = [ $self->has_asps ? $self->asps->path_vertices($origin_id, $dest_id) : $self->full_graph->SP_Dijkstra($origin_id, $dest_id) ]; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 655 | |||||||||||||||||||||||||||||||||||||||||||
| 656 | 1 | ▶ | if($origin->possible_on_same_line($dest) && !$origin->on_same_line($dest)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$origin->possible_on_same_line($dest) and not $origin->on_same_line($dest)
MC/DC0%0/2
$origin->possible_on_same_line($dest) and not $origin->on_same_line($dest)
$origin->possible_on_same_line($dest)
not $origin->on_same_line($dest)
Truth table33%1/3
A and not(B)
A= $origin->possible_on_same_line($dest)B= not $origin->on_same_line($dest)
| |||||||||||||||||||||||||||||||||||||||||||
| 657 | 0 | next DESTINATION_LINE_STATION; | |||||||||||||||||||||||||||||||||||||||||
| 658 | } | ||||||||||||||||||||||||||||||||||||||||||
| 659 | |||||||||||||||||||||||||||||||||||||||||||
| 660 | 1 | my $route = Map::Metro::Graph::Route->new; | |||||||||||||||||||||||||||||||||||||||||
| 661 | |||||||||||||||||||||||||||||||||||||||||||
| 662 | 1 | my($prev_step, $prev_conn, $next_step, $next_conn); | |||||||||||||||||||||||||||||||||||||||||
| 663 | |||||||||||||||||||||||||||||||||||||||||||
| 664 | LINE_STATION: | ||||||||||||||||||||||||||||||||||||||||||
| 665 | 1 | foreach my $index (0 .. scalar @$graphroute - 2) { | |||||||||||||||||||||||||||||||||||||||||
| 666 | 3 | my $this_line_station_id = $graphroute->[ $index ]; | |||||||||||||||||||||||||||||||||||||||||
| 667 | 3 | my $next_line_station_id = $graphroute->[ $index + 1 ]; | |||||||||||||||||||||||||||||||||||||||||
| 668 | 3 | ▶ | my $next_next_line_station_id = $graphroute->[ $index + 2 ] // undef; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$$graphroute[$index + 2] // undef
MC/DC100%1/1
$$graphroute[$index + 2] // undef
$$graphroute[$index + 2]
Truth table100%2/2
A
A= $$graphroute[$index + 2]
| |||||||||||||||||||||||||||||||||||||||||||
| 669 | |||||||||||||||||||||||||||||||||||||||||||
| 670 | |||||||||||||||||||||||||||||||||||||||||||
| 671 | |||||||||||||||||||||||||||||||||||||||||||
| 672 | 3 | my $conn = $self->get_connection_by_line_station_ids($this_line_station_id, $next_line_station_id); | |||||||||||||||||||||||||||||||||||||||||
| 673 | |||||||||||||||||||||||||||||||||||||||||||
| 674 | #* Don't continue beyond this route, even it connections exist. | ||||||||||||||||||||||||||||||||||||||||||
| 675 | 3 | ▶ | if($index + 2 < scalar @$graphroute) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 676 | 2 | ▶ | $next_conn = defined $next_next_line_station_id ? $self->get_connection_by_line_station_ids($this_line_station_id, $next_line_station_id) : undef; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 677 | 2 | ▶ | $next_step = Map::Metro::Graph::Step->new(from_connection => $next_conn) if defined $next_conn; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 678 | } | ||||||||||||||||||||||||||||||||||||||||||
| 679 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 680 | 1 | $next_conn = $next_step = undef; | |||||||||||||||||||||||||||||||||||||||||
| 681 | } | ||||||||||||||||||||||||||||||||||||||||||
| 682 | |||||||||||||||||||||||||||||||||||||||||||
| 683 | 3 | my $step = Map::Metro::Graph::Step->new(from_connection => $conn); | |||||||||||||||||||||||||||||||||||||||||
| 684 | 3 | ▶ | $step->previous_step($prev_step) if $prev_step; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 685 | 3 | ▶ | $step->next_step($next_step) if $next_step; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 686 | |||||||||||||||||||||||||||||||||||||||||||
| 687 | 3 | ▶ | $next_step->previous_step($step) if defined $next_step; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 688 | |||||||||||||||||||||||||||||||||||||||||||
| 689 | 3 | $route->add_step($step); | |||||||||||||||||||||||||||||||||||||||||
| 690 | 3 | $prev_step = $step; | |||||||||||||||||||||||||||||||||||||||||
| 691 | 3 | $step = $next_step; | |||||||||||||||||||||||||||||||||||||||||
| 692 | |||||||||||||||||||||||||||||||||||||||||||
| 693 | } | ||||||||||||||||||||||||||||||||||||||||||
| 694 | |||||||||||||||||||||||||||||||||||||||||||
| 695 | LINE_STATION: | ||||||||||||||||||||||||||||||||||||||||||
| 696 | 1 | foreach my $index (0 .. scalar @$graphroute - 1) { | |||||||||||||||||||||||||||||||||||||||||
| 697 | 4 | my $line_station = $self->get_line_station_by_id($graphroute->[$index]); | |||||||||||||||||||||||||||||||||||||||||
| 698 | |||||||||||||||||||||||||||||||||||||||||||
| 699 | 4 | $route->add_line_station($line_station); | |||||||||||||||||||||||||||||||||||||||||
| 700 | } | ||||||||||||||||||||||||||||||||||||||||||
| 701 | |||||||||||||||||||||||||||||||||||||||||||
| 702 | 1 | ▶ | next DESTINATION_LINE_STATION if $route->transfer_on_first_station; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 703 | 1 | ▶ | next DESTINATION_LINE_STATION if $route->transfer_on_final_station; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 704 | |||||||||||||||||||||||||||||||||||||||||||
| 705 | 1 | $routing->add_route($route); | |||||||||||||||||||||||||||||||||||||||||
| 706 | } | ||||||||||||||||||||||||||||||||||||||||||
| 707 | } | ||||||||||||||||||||||||||||||||||||||||||
| 708 | 1 | ▶ | $self->emit->before_add_routing($routing) if $self->has_wanted_hook_plugins; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 709 | 1 | $self->add_routing($routing); | |||||||||||||||||||||||||||||||||||||||||
| 710 | |||||||||||||||||||||||||||||||||||||||||||
| 711 | 1 | return $routing; | |||||||||||||||||||||||||||||||||||||||||
| 712 | } | ||||||||||||||||||||||||||||||||||||||||||
| 713 | |||||||||||||||||||||||||||||||||||||||||||
| 714 | # --> ArrayRef[Routing] Routings between every pair of Stations | ||||||||||||||||||||||||||||||||||||||||||
| 715 | 0 | ▶ | sub all_pairs { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
all_pairs: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 716 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 717 | |||||||||||||||||||||||||||||||||||||||||||
| 718 | 0 | my $routings = []; | |||||||||||||||||||||||||||||||||||||||||
| 719 | 0 | $self->calculate_shortest_paths; | |||||||||||||||||||||||||||||||||||||||||
| 720 | |||||||||||||||||||||||||||||||||||||||||||
| 721 | STATION: | ||||||||||||||||||||||||||||||||||||||||||
| 722 | 0 | foreach my $station ($self->all_stations) { | |||||||||||||||||||||||||||||||||||||||||
| 723 | 0 | my @other_stations = grep { $_->id != $station->id } $self->all_stations; | |||||||||||||||||||||||||||||||||||||||||
| 724 | |||||||||||||||||||||||||||||||||||||||||||
| 725 | OTHER_STATION: | ||||||||||||||||||||||||||||||||||||||||||
| 726 | 0 | foreach my $other_station (@other_stations) { | |||||||||||||||||||||||||||||||||||||||||
| 727 | 0 | push @$routings => $self->routing_for($station, $other_station); | |||||||||||||||||||||||||||||||||||||||||
| 728 | } | ||||||||||||||||||||||||||||||||||||||||||
| 729 | } | ||||||||||||||||||||||||||||||||||||||||||
| 730 | 0 | return $routings; | |||||||||||||||||||||||||||||||||||||||||
| 731 | } | ||||||||||||||||||||||||||||||||||||||||||
| 732 | |||||||||||||||||||||||||||||||||||||||||||
| 733 | 0 | ▶ | sub to_hash { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
to_hash: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 734 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 735 | |||||||||||||||||||||||||||||||||||||||||||
| 736 | return { | ||||||||||||||||||||||||||||||||||||||||||
| 737 | routings => [ | ||||||||||||||||||||||||||||||||||||||||||
| 738 | 0 | map { $_->to_hash } $self->all_routings | |||||||||||||||||||||||||||||||||||||||||
| 739 | ], | ||||||||||||||||||||||||||||||||||||||||||
| 740 | } | ||||||||||||||||||||||||||||||||||||||||||
| 741 | } | ||||||||||||||||||||||||||||||||||||||||||
| 742 | |||||||||||||||||||||||||||||||||||||||||||
| 743 | 13 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 744 | |||||||||||||||||||||||||||||||||||||||||||
| 745 | __END__ | ||||||||||||||||||||||||||||||||||||||||||