| 1 | 14 | ▶ | use 5.10.0; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 2 | 14 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | 14 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | |||||||||||
| 5 | package Map::Metro::Graph::Route; | ||||||||||
| 6 | |||||||||||
| 7 | # ABSTRACT: A sequence of line stations | ||||||||||
| 8 | 14 | our $AUTHORITY = 'cpan:CSSON'; # AUTHORITY | |||||||||
| 9 | 14 | our $VERSION = '0.2405'; | |||||||||
| 10 | |||||||||||
| 11 | 14 | ▶ | use Map::Metro::Elk; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 12 | 14 | ▶ | use Types::Standard qw/ArrayRef Str/; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 13 | 14 | ▶ | use Map::Metro::Types qw/Step LineStation/; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 14 | 14 | ▶ | use List::Util qw/sum/; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 15 | |||||||||||
| 16 | 14 | has steps => ( | |||||||||
| 17 | is => 'ro', | ||||||||||
| 18 | isa => ArrayRef[ Step ], | ||||||||||
| 19 | traits => ['Array'], | ||||||||||
| 20 | predicate => 1, | ||||||||||
| 21 | handles => { | ||||||||||
| 22 | add_step => 'push', | ||||||||||
| 23 | step_count => 'count', | ||||||||||
| 24 | get_step => 'get', | ||||||||||
| 25 | all_steps => 'elements', | ||||||||||
| 26 | filter_steps => 'grep', | ||||||||||
| 27 | } | ||||||||||
| 28 | ); | ||||||||||
| 29 | has id => ( | ||||||||||
| 30 | is => 'ro', | ||||||||||
| 31 | isa => Str, | ||||||||||
| 32 | init_arg => undef, | ||||||||||
| 33 | 1 | ▶ | default => sub { join '' => map { ('a'..'z', 2..9)[int rand 33] } (1..8) }, | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 34 | 14 | ); | |||||||||
| 35 | 14 | has line_stations => ( | |||||||||
| 36 | is => 'ro', | ||||||||||
| 37 | isa => ArrayRef[ LineStation ], | ||||||||||
| 38 | traits => ['Array'], | ||||||||||
| 39 | handles => { | ||||||||||
| 40 | add_line_station => 'push', | ||||||||||
| 41 | all_line_stations => 'elements', | ||||||||||
| 42 | step => 'get', | ||||||||||
| 43 | line_station_count => 'count', | ||||||||||
| 44 | }, | ||||||||||
| 45 | ); | ||||||||||
| 46 | |||||||||||
| 47 | 0 | ▶ | sub weight { | ||||||||
|
Subroutine
weight: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 48 | 0 | my $self = shift; | |||||||||
| 49 | |||||||||||
| 50 | 0 | return sum map { $_->weight } $self->all_steps; | |||||||||
| 51 | } | ||||||||||
| 52 | |||||||||||
| 53 | 1 | ▶ | sub transfer_on_final_station { | ||||||||
|
Subroutine
transfer_on_final_station: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||
| 54 | 1 | my $self = shift; | |||||||||
| 55 | |||||||||||
| 56 | 1 | ▶ | return 0 if $self->step_count < 2; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 57 | 1 | my $final_step = $self->get_step(-1); | |||||||||
| 58 | |||||||||||
| 59 | 1 | return $final_step->origin_line_station->station->id == $final_step->destination_line_station->station->id; | |||||||||
| 60 | } | ||||||||||
| 61 | 1 | ▶ | sub transfer_on_first_station { | ||||||||
|
Subroutine
transfer_on_first_station: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||
| 62 | 1 | my $self = shift; | |||||||||
| 63 | |||||||||||
| 64 | 1 | ▶ | return 0 if $self->step_count < 2; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 65 | 1 | my $first_step = $self->get_step(0); | |||||||||
| 66 | |||||||||||
| 67 | 1 | return $first_step->origin_line_station->station->id == $first_step->destination_line_station->station->id; | |||||||||
| 68 | } | ||||||||||
| 69 | 0 | ▶ | sub longest_line_name_length { | ||||||||
|
Subroutine
longest_line_name_length: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 70 | 0 | my $self = shift; | |||||||||
| 71 | |||||||||||
| 72 | 0 | return length((sort { length $b->origin_line_station->line->name <=> length $a->origin_line_station->line->name } $self->all_steps)[0]->origin_line_station->line->name); | |||||||||
| 73 | } | ||||||||||
| 74 | |||||||||||
| 75 | 1 | ▶ | sub to_hash { | ||||||||
|
Subroutine
to_hash: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 76 | 1 | my $self = shift; | |||||||||
| 77 | |||||||||||
| 78 | return { | ||||||||||
| 79 | id => $self->id, | ||||||||||
| 80 | steps => [ | ||||||||||
| 81 | 3 | map { $_->to_hash } $self->all_steps, | |||||||||
| 82 | ], | ||||||||||
| 83 | line_stations => [ | ||||||||||
| 84 | 1 | map { $_->to_hash } $self->all_line_stations, | |||||||||
| 85 | ], | ||||||||||
| 86 | }; | ||||||||||
| 87 | } | ||||||||||
| 88 | |||||||||||
| 89 | 14 | __PACKAGE__->meta->make_immutable; | |||||||||
| 90 | |||||||||||
| 91 | 14 | 1; | |||||||||
| 92 | |||||||||||
| 93 | __END__ | ||||||||||