| 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::Step; | ||||||||||
| 6 | |||||||||||
| 7 | # ABSTRACT: The movement from one station to the next in a route | ||||||||||
| 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/Maybe Int/; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 13 | 14 | ▶ | use Map::Metro::Types qw/LineStation Step/; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 14 | 14 | ▶ | use PerlX::Maybe qw/maybe/; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 15 | |||||||||||
| 16 | 14 | has origin_line_station => ( | |||||||||
| 17 | is => 'ro', | ||||||||||
| 18 | isa => LineStation, | ||||||||||
| 19 | required => 1, | ||||||||||
| 20 | ); | ||||||||||
| 21 | 14 | has destination_line_station => ( | |||||||||
| 22 | is => 'ro', | ||||||||||
| 23 | isa => LineStation, | ||||||||||
| 24 | required => 1, | ||||||||||
| 25 | ); | ||||||||||
| 26 | 14 | has previous_step => ( | |||||||||
| 27 | is => 'rw', | ||||||||||
| 28 | isa => Maybe[ Step ], | ||||||||||
| 29 | predicate => 1, | ||||||||||
| 30 | ); | ||||||||||
| 31 | 14 | has next_step => ( | |||||||||
| 32 | is => 'rw', | ||||||||||
| 33 | isa => Maybe[ Step ], | ||||||||||
| 34 | predicate => 1, | ||||||||||
| 35 | ); | ||||||||||
| 36 | 14 | has weight => ( | |||||||||
| 37 | is => 'ro', | ||||||||||
| 38 | isa => Int, | ||||||||||
| 39 | required => 1, | ||||||||||
| 40 | default => 1, | ||||||||||
| 41 | ); | ||||||||||
| 42 | |||||||||||
| 43 | 5 | ▶ | around BUILDARGS => sub { | ||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.2
| |||||||||||
| 44 | 5 | my $orig = shift; | |||||||||
| 45 | 5 | my $class = shift; | |||||||||
| 46 | 5 | my %args = @_; | |||||||||
| 47 | |||||||||||
| 48 | 5 | ▶ | return $class->$orig(%args) if !exists $args{'from_connection'}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 49 | |||||||||||
| 50 | 5 | my $conn = $args{'from_connection'}; | |||||||||
| 51 | 5 | ▶ | return if !defined $conn; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 52 | |||||||||||
| 53 | 5 | return $class->$orig( | |||||||||
| 54 | origin_line_station => $conn->origin_line_station, | ||||||||||
| 55 | destination_line_station => $conn->destination_line_station, | ||||||||||
| 56 | weight => $conn->weight, | ||||||||||
| 57 | ); | ||||||||||
| 58 | 14 | }; | |||||||||
| 59 | |||||||||||
| 60 | 0 | ▶ | sub is_line_transfer { | ||||||||
|
Subroutine
is_line_transfer: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 61 | 0 | my $self = shift; | |||||||||
| 62 | |||||||||||
| 63 | 0 | return $self->origin_line_station->station->id == $self->destination_line_station->station->id; | |||||||||
| 64 | 0 | return $self->origin_line_station->line->id ne $self->destination_line_station->line->id; | |||||||||
| 65 | } | ||||||||||
| 66 | 0 | ▶ | sub is_station_transfer { | ||||||||
|
Subroutine
is_station_transfer: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 67 | 0 | my $self = shift; | |||||||||
| 68 | |||||||||||
| 69 | 0 | my $origin_station_line_ids = [ map { $_->id } $self->origin_line_station->station->all_lines ]; | |||||||||
| 70 | 0 | my $destination_station_line_ids = [ map { $_->id } $self->destination_line_station->station->all_lines ]; | |||||||||
| 71 | |||||||||||
| 72 | 0 | my $are_on_same_line = List::Compare->new($origin_station_line_ids, $destination_station_line_ids)->get_intersection; | |||||||||
| 73 | |||||||||||
| 74 | 0 | return !$are_on_same_line; | |||||||||
| 75 | } | ||||||||||
| 76 | 0 | ▶ | sub was_line_transfer { | ||||||||
|
Subroutine
was_line_transfer: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||
| 77 | 0 | my $self = shift; | |||||||||
| 78 | |||||||||||
| 79 | 0 | ▶ | return if !$self->has_previous_step; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 80 | 0 | return $self->previous_step->is_line_transfer; | |||||||||
| 81 | } | ||||||||||
| 82 | 0 | ▶ | sub was_station_transfer { | ||||||||
|
Subroutine
was_station_transfer: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||
| 83 | 0 | my $self = shift; | |||||||||
| 84 | |||||||||||
| 85 | 0 | ▶ | return if !$self->has_previous_step; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 86 | 0 | return $self->previous_step->is_station_transfer; | |||||||||
| 87 | } | ||||||||||
| 88 | |||||||||||
| 89 | 3 | ▶ | sub to_hash { | ||||||||
|
Subroutine
to_hash: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 90 | 3 | my $self = shift; | |||||||||
| 91 | |||||||||||
| 92 | return { | ||||||||||
| 93 | 3 | origin_line_station => $self->origin_line_station->to_hash, | |||||||||
| 94 | destination_line_station => $self->destination_line_station->to_hash, | ||||||||||
| 95 | # maybe previous_step => $self->has_previous_step ? $self->previous_step->to_hash : undef, | ||||||||||
| 96 | # maybe next_step => $self->has_next_step ? $self->next_step->to_hash : undef, | ||||||||||
| 97 | weight => $self->weight, | ||||||||||
| 98 | }; | ||||||||||
| 99 | } | ||||||||||
| 100 | |||||||||||
| 101 | 14 | __PACKAGE__->meta->make_immutable; | |||||||||
| 102 | |||||||||||
| 103 | 14 | 1; | |||||||||
| 104 | |||||||||||
| 105 | __END__ | ||||||||||