| 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::Routing; | ||||||||||
| 6 | |||||||||||
| 7 | # ABSTRACT: A collection of routes between two stations | ||||||||||
| 8 | 14 | our $AUTHORITY = 'cpan:CSSON'; # AUTHORITY | |||||||||
| 9 | 14 | our $VERSION = '0.2404'; | |||||||||
| 10 | |||||||||||
| 11 | 14 | ▶ | use Map::Metro::Elk; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 12 | 14 | ▶ | use Types::Standard qw/ArrayRef/; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 13 | 14 | ▶ | use Map::Metro::Types qw/Station LineStation Route/; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 14 | |||||||||||
| 15 | 14 | has origin_station => ( | |||||||||
| 16 | is => 'ro', | ||||||||||
| 17 | isa => Station, | ||||||||||
| 18 | required => 1, | ||||||||||
| 19 | ); | ||||||||||
| 20 | 14 | has destination_station => ( | |||||||||
| 21 | is => 'ro', | ||||||||||
| 22 | isa => Station, | ||||||||||
| 23 | required => 1, | ||||||||||
| 24 | ); | ||||||||||
| 25 | has line_stations => ( | ||||||||||
| 26 | is => 'ro', | ||||||||||
| 27 | isa => ArrayRef[ LineStation ], | ||||||||||
| 28 | traits => ['Array'], | ||||||||||
| 29 | 1 | ▶ | default => sub {[]}, | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 30 | 14 | handles => { | |||||||||
| 31 | add_line_station => 'push', | ||||||||||
| 32 | find_line_station => 'first', | ||||||||||
| 33 | all_line_stations => 'elements', | ||||||||||
| 34 | } | ||||||||||
| 35 | ); | ||||||||||
| 36 | 14 | has routes => ( | |||||||||
| 37 | is => 'ro', | ||||||||||
| 38 | isa => ArrayRef[ Route ], | ||||||||||
| 39 | traits => ['Array'], | ||||||||||
| 40 | handles => { | ||||||||||
| 41 | get_route => 'get', | ||||||||||
| 42 | add_route => 'push', | ||||||||||
| 43 | all_routes => 'elements', | ||||||||||
| 44 | sort_routes => 'sort', | ||||||||||
| 45 | route_count => 'count', | ||||||||||
| 46 | find_route => 'first', | ||||||||||
| 47 | }, | ||||||||||
| 48 | ); | ||||||||||
| 49 | |||||||||||
| 50 | around add_line_station => sub { | ||||||||||
| 51 | 0 | ▶ | my $next = shift; | ||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||
| 52 | 0 | my $self = shift; | |||||||||
| 53 | 0 | my $ls = shift; # LineStation | |||||||||
| 54 | |||||||||||
| 55 | 0 | ▶ | my $exists = $self->find_line_station(sub { $ls->line_station_id == $_->line_station_id }); | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 56 | 0 | ▶ | return if $exists; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 57 | 0 | $self->$next($ls); | |||||||||
| 58 | 14 | }; | |||||||||
| 59 | |||||||||||
| 60 | sub ordered_routes { | ||||||||||
| 61 | 0 | ▶ | my $self = shift; | ||||||||
|
Subroutine
ordered_routes: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 62 | |||||||||||
| 63 | 0 | ▶ | $self->sort_routes(sub { $_[0]->weight <=> $_[1]->weight }); | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 64 | } | ||||||||||
| 65 | |||||||||||
| 66 | sub to_hash { | ||||||||||
| 67 | 1 | ▶ | my $self = shift; | ||||||||
|
Subroutine
to_hash: called CC=1 SCAR=0.2
Pod
undocumented
| |||||||||||
| 68 | |||||||||||
| 69 | return { | ||||||||||
| 70 | origin_station => $self->origin_station->to_hash, | ||||||||||
| 71 | destination_station => $self->destination_station->to_hash, | ||||||||||
| 72 | line_stations => [ | ||||||||||
| 73 | 0 | map { $_->to_hash } $self->all_line_stations, | |||||||||
| 74 | ], | ||||||||||
| 75 | routes => [ | ||||||||||
| 76 | 1 | map { $_->to_hash } $self->all_routes, | |||||||||
| 77 | ], | ||||||||||
| 78 | }; | ||||||||||
| 79 | } | ||||||||||
| 80 | |||||||||||
| 81 | 14 | __PACKAGE__->meta->make_immutable; | |||||||||
| 82 | |||||||||||
| 83 | 14 | 1; | |||||||||
| 84 | |||||||||||
| 85 | __END__ | ||||||||||
| 86 | |||||||||||
| 87 | =pod | ||||||||||
| 88 | |||||||||||
| 89 | =encoding UTF-8 | ||||||||||
| 90 | |||||||||||
| 91 | =head1 NAME | ||||||||||
| 92 | |||||||||||
| 93 | Map::Metro::Graph::Routing - A collection of routes between two stations | ||||||||||
| 94 | |||||||||||
| 95 | =head1 VERSION | ||||||||||
| 96 | |||||||||||
| 97 | Version 0.2404, released 2016-04-30. | ||||||||||
| 98 | |||||||||||
| 99 | =head1 DESCRIPTION | ||||||||||
| 100 | |||||||||||
| 101 | A routing is the collection of L<Routes|Map::Metro::Graph::Route> possible between two L<Stations|Map::Metro::Graph::Station>. | ||||||||||
| 102 | |||||||||||
| 103 | =head1 METHODS | ||||||||||
| 104 | |||||||||||
| 105 | =head2 origin_station() | ||||||||||
| 106 | |||||||||||
| 107 | Returns the L<Station|Map::Metro::Graph::Station> object representing the starting station of the route. | ||||||||||
| 108 | |||||||||||
| 109 | =head2 destination_station() | ||||||||||
| 110 | |||||||||||
| 111 | Returns the L<Station|Map::Metro::Graph::Station> object representing the final station of the route. | ||||||||||
| 112 | |||||||||||
| 113 | =head2 line_stations() | ||||||||||
| 114 | |||||||||||
| 115 | Returns an array of all L<LineStation|Map::Metro::Graph::LineStations> possible in the routing. | ||||||||||
| 116 | |||||||||||
| 117 | =head2 routes() | ||||||||||
| 118 | |||||||||||
| 119 | Returns an array of all L<Route|Map::Metro::Graph::Routes> in the routing. | ||||||||||
| 120 | |||||||||||
| 121 | =head1 SOURCE | ||||||||||
| 122 | |||||||||||
| 123 | L<https://github.com/Csson/p5-Map-Metro> | ||||||||||
| 124 | |||||||||||
| 125 | =head1 HOMEPAGE | ||||||||||
| 126 | |||||||||||
| 127 | L<https://metacpan.org/release/Map-Metro> | ||||||||||
| 128 | |||||||||||
| 129 | =head1 AUTHOR | ||||||||||
| 130 | |||||||||||
| 131 | Erik Carlsson <info@code301.com> | ||||||||||
| 132 | |||||||||||
| 133 | =head1 COPYRIGHT AND LICENSE | ||||||||||
| 134 | |||||||||||
| 135 | This software is copyright (c) 2016 by Erik Carlsson. | ||||||||||
| 136 | |||||||||||
| 137 | This is free software; you can redistribute it and/or modify it under | ||||||||||
| 138 | the same terms as the Perl 5 programming language system itself. | ||||||||||
| 139 | |||||||||||
| 140 | =cut | ||||||||||