Metro/Graph/Route.pm

filter: Statementstmt 87.2% 41 / 47 Branchbran 50.0% 2 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 84.6% 11 / 13 Podpod 20.0% 1 / 5 totaltotal 79.7% 55 / 69 CC 3 SCAR 3.4
CC
3
Cov
84%
transfer_on_final_station
2.0
transfer_on_first_station
2.0
weight
2.0
CRAP 1.4
« Metro/Graph/Routing.pm ↑ Summary Metro/Exceptions.pm »
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.2404';
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 sub weight {
48 0 ▶ my $self = shift;
Subroutine weight: not called CC=1 SCAR=6.9
Pod documented
49  
50 0 return sum map { $_->weight } $self->all_steps;
51 }
52  
53 sub transfer_on_final_station {
54 1 ▶ my $self = shift;
Subroutine transfer_on_final_station: called CC=2 SCAR=7.0
Pod undocumented
55  
56 1 ▶ return 0 if $self->step_count < 2;
Branch: 1 branch
BranchTrueFalseTotal
if $self->step_count < 2 0 1 1
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 sub transfer_on_first_station {
62 1 ▶ my $self = shift;
Subroutine transfer_on_first_station: called CC=2 SCAR=7.0
Pod undocumented
63  
64 1 ▶ return 0 if $self->step_count < 2;
Branch: 1 branch
BranchTrueFalseTotal
if $self->step_count < 2 0 1 1
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 sub longest_line_name_length {
70 0 ▶ my $self = shift;
Subroutine longest_line_name_length: not called CC=1 SCAR=6.9
Pod undocumented
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 sub to_hash {
76 1 ▶ my $self = shift;
Subroutine to_hash: called CC=1 SCAR=0.0
Pod undocumented
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__
94  
95 =pod
96  
97 =encoding UTF-8
98  
99 =head1 NAME
100  
101 Map::Metro::Graph::Route - A sequence of line stations
102  
103 =head1 VERSION
104  
105 Version 0.2404, released 2016-04-30.
106  
107 =head1 DESCRIPTION
108  
109 A route is a specific sequence of L<Steps|Map::Metro::Graph::Step> from one L<LineStation|Map::Metro::Graph::LineStation> to another.
110  
111 =head1 METHODS
112  
113 =head2 all_steps()
114  
115 Returns an array of the L<Steps|Map::Metro::Graph::Step> in the route, in the order they are travelled.
116  
117 =head2 weight()
118  
119 Returns an integer representing the total 'cost' of all L<Connections|Map::Metro::Graph::Connection> on this route.
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
« Metro/Graph/Routing.pm ↑ Summary Metro/Exceptions.pm »