Metro/Graph/Step.pm

filter: Statementstmt 70.9% 39 / 55 Branchbran 25.0% 2 / 8 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 69.2% 9 / 13 Podpod 0.0% 0 / 5 totaltotal 61.7% 50 / 81 CC 5 SCAR 9.8
CC
5
Cov
65%
was_line_transfer
6.0
was_station_transfer
6.0
__ANON__
3.1
CRAP 2.7
« Metro/Plugin/Map.pm ↑ Summary Metro/Cmd/Route.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::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.2404';
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 around BUILDARGS => sub {
44 5 ▶ my $orig = shift;
Subroutine __ANON__: called CC=3 SCAR=11.2
45 5 my $class = shift;
46 5 my %args = @_;
47  
48 5 ▶ return $class->$orig(%args) if !exists $args{'from_connection'};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $args{"from_connection"} 0 5 5
49  
50 5 my $conn = $args{'from_connection'};
51 5 ▶ return if !defined $conn;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $conn 0 5 5
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 sub is_line_transfer {
61 0 ▶ my $self = shift;
Subroutine is_line_transfer: not called CC=1 SCAR=6.9
Pod undocumented
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 sub is_station_transfer {
67 0 ▶ my $self = shift;
Subroutine is_station_transfer: not called CC=1 SCAR=6.9
Pod undocumented
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 sub was_line_transfer {
77 0 ▶ my $self = shift;
Subroutine was_line_transfer: not called CC=2 SCAR=17.9
Pod undocumented
78  
79 0 ▶ return if !$self->has_previous_step;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->has_previous_step 0 0 0
80 0 return $self->previous_step->is_line_transfer;
81 }
82 sub was_station_transfer {
83 0 ▶ my $self = shift;
Subroutine was_station_transfer: not called CC=2 SCAR=17.9
Pod undocumented
84  
85 0 ▶ return if !$self->has_previous_step;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->has_previous_step 0 0 0
86 0 return $self->previous_step->is_station_transfer;
87 }
88  
89 sub to_hash {
90 3 ▶ my $self = shift;
Subroutine to_hash: called CC=1 SCAR=0.0
Pod undocumented
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__
106  
107 =pod
108  
109 =encoding UTF-8
110  
111 =head1 NAME
112  
113 Map::Metro::Graph::Step - The movement from one station to the next in a route
114  
115 =head1 VERSION
116  
117 Version 0.2404, released 2016-04-30.
118  
119 =head1 DESCRIPTION
120  
121 Steps are exactly like L<Connections::Map::Metro::Graph::Connection>, in that they describe the combination of two
122 specific L<LineStations|Map::Metro::Graph::LineStation>, and the 'cost' of travelling between them, but with an important
123 difference: A Step is part of a specific L<Route|Map::Metro::Graph::Route>.
124  
125 =head1 SOURCE
126  
127 L<https://github.com/Csson/p5-Map-Metro>
128  
129 =head1 HOMEPAGE
130  
131 L<https://metacpan.org/release/Map-Metro>
132  
133 =head1 AUTHOR
134  
135 Erik Carlsson <info@code301.com>
136  
137 =head1 COPYRIGHT AND LICENSE
138  
139 This software is copyright (c) 2016 by Erik Carlsson.
140  
141 This is free software; you can redistribute it and/or modify it under
142 the same terms as the Perl 5 programming language system itself.
143  
144 =cut
« Metro/Plugin/Map.pm ↑ Summary Metro/Cmd/Route.pm »