File Coverage

blib/lib/Map/Metro/Graph/LineStation.pm
Criterion Covered Total %
statement 33 33 100.0
branch n/a
condition n/a
subroutine 10 10 100.0
pod 0 3 0.0
total 43 46 93.4


line stmt bran cond sub pod time code
1 2     2   24 use 5.10.0;
  2         4  
2 2     2   8 use strict;
  2         2  
  2         35  
3 2     2   8 use warnings;
  2         2  
  2         97  
4              
5             package Map::Metro::Graph::LineStation;
6              
7             # ABSTRACT: A station on a specific line
8             our $AUTHORITY = 'cpan:CSSON'; # AUTHORITY
9             our $VERSION = '0.2405';
10              
11 2     2   7 use Map::Metro::Elk;
  2         2  
  2         10  
12 2     2   2647 use Types::Standard qw/Int/;
  2         3  
  2         13  
13 2     2   671 use Map::Metro::Types qw/Station Line/;
  2         3  
  2         12  
14 2     2   2163 use List::Compare;
  2         27319  
  2         375  
15              
16             has line_station_id => (
17             is => 'ro',
18             isa => Int,
19             required => 1,
20             );
21             has station => (
22             is => 'ro',
23             isa => Station,
24             required => 1,
25             );
26             has line => (
27             is => 'ro',
28             isa => Line,
29             required => 1,
30             );
31              
32             sub possible_on_same_line {
33 1     1 0 1 my $self = shift;
34 1         2 my $other = shift; # LineStation
35              
36 1         48 my $station_lines = [ map { $_->id } $self->station->all_lines ];
  1         27  
37 1         26 my $other_station_lines = [ map { $_->id } $other->station->all_lines ];
  1         23  
38              
39 1         14 my $is_possible = !!List::Compare->new($station_lines, $other_station_lines)->get_intersection;
40              
41 1         128 return $is_possible;
42             }
43             sub on_same_line {
44 1     1 0 2 my $self = shift;
45 1         2 my $other = shift; # LineStation
46              
47 1         32 return $self->line->id eq $other->line->id;
48             }
49              
50             sub to_hash {
51 10     10 0 9 my $self = shift;
52              
53             return {
54 10         238 line_station_id => $self->line_station_id,
55             station => $self->station->to_hash,
56             line => $self->line->to_hash,
57             };
58             }
59              
60             __PACKAGE__->meta->make_immutable;
61              
62             1;
63              
64             __END__
65              
66             =pod
67              
68             =encoding UTF-8
69              
70             =head1 NAME
71              
72             Map::Metro::Graph::LineStation - A station on a specific line
73              
74             =head1 VERSION
75              
76             Version 0.2405, released 2016-07-23.
77              
78             =head1 DESCRIPTION
79              
80             A line station is the concept of a specific L<Station|Map::Metro::Graph::Station> on a specific L<Line|Map::Metro::Graph::Line>.
81              
82             =head1 METHODS
83              
84             =head2 line_station_id()
85              
86             Returns the internal line station id. Do not depend on this between executions.
87              
88             =head2 station()
89              
90             Returns the L<Station|Map::Metro::Graph::Station> object.
91              
92             =head2 line()
93              
94             Returns the L<Line|Map::Metro::Graph::Line> object.
95              
96             =head1 SOURCE
97              
98             L<https://github.com/Csson/p5-Map-Metro>
99              
100             =head1 HOMEPAGE
101              
102             L<https://metacpan.org/release/Map-Metro>
103              
104             =head1 AUTHOR
105              
106             Erik Carlsson <info@code301.com>
107              
108             =head1 COPYRIGHT AND LICENSE
109              
110             This software is copyright (c) 2016 by Erik Carlsson.
111              
112             This is free software; you can redistribute it and/or modify it under
113             the same terms as the Perl 5 programming language system itself.
114              
115             =cut