File Coverage

blib/lib/Map/Tube/Route.pm
Criterion Covered Total %
statement 20 49 40.8
branch n/a
condition n/a
subroutine 7 9 77.7
pod 1 2 50.0
total 28 60 46.6


line stmt bran cond sub pod time code
1             package Map::Tube::Route;
2              
3             $Map::Tube::Route::VERSION = '3.42';
4             $Map::Tube::Route::AUTHORITY = 'cpan:MANWAR';
5              
6             =head1 NAME
7              
8             Map::Tube::Route - Class to represent the route in the map.
9              
10             =head1 VERSION
11              
12             Version 3.42
13              
14             =cut
15              
16 1     1   1322 use 5.006;
  1         5  
17 1     1   9 use Data::Dumper;
  1         3  
  1         77  
18 1     1   11 use Map::Tube::Types qw(Node Nodes);
  1         3  
  1         12  
19 1     1   757 use Map::Tube::Utils qw(filter);
  1         3  
  1         61  
20              
21 1     1   9 use Moo;
  1         3  
  1         9  
22 1     1   514 use namespace::autoclean;
  1         3  
  1         11  
23              
24 1     1   105 use overload q{""} => 'as_string', fallback => 1;
  1         3  
  1         14  
25              
26             has [ qw(from to) ] => (is => 'ro', isa => Node, required => 1);
27             has nodes => (is => 'ro', isa => Nodes, required => 1);
28              
29             =head1 DESCRIPTION
30              
31             It provides simple interface to the 'route' of the map.
32              
33             =head1 METHODS
34              
35             =head2 from()
36              
37             Returns an object of type L representing the start station.
38              
39             =head2 to()
40              
41             Returns an object of type L representing the end station.
42              
43             =head2 nodes()
44              
45             Returns ref to a list of objects of type L representing the path
46             from "start" to "end" station.
47              
48             =head2 preferred()
49              
50             Returns an object of type L as preferred route.
51              
52             =cut
53              
54             sub preferred {
55 0     0 1   my ($self) = @_;
56              
57 0           my $index = 0;
58 0           my $nodes = [];
59 0           my $lines = [];
60 0           my $nodes_object = {};
61 0           my $lines_object = {};
62 0           foreach my $node (@{$self->nodes}) {
  0            
63 0           push @$nodes, { name => $node->name };
64 0           $nodes_object->{$node->name} = $node;
65              
66 0           foreach my $line (@{$node->{line}}) {
  0            
67 0           push @{$lines->[$index]}, $line->id;
  0            
68 0           $lines_object->{$line->id} = $line;
69             }
70              
71 0           $index++;
72             }
73              
74 0           my $data = filter($lines);
75 0           my $_nodes = [];
76 0           foreach my $i (0..$#$nodes) {
77             my $_node = {
78             id => $nodes_object->{$nodes->[$i]->{name}}->id,
79             name => $nodes->[$i]->{name},
80             link => $nodes_object->{$nodes->[$i]->{name}}->link,
81 0           };
82              
83 0           foreach (@{$data->[$i]}) {
  0            
84 0           push @{$_node->{line}}, $lines_object->{$_};
  0            
85             }
86              
87 0           push @$_nodes, Map::Tube::Node->new($_node);
88             }
89              
90 0           return Map::Tube::Route->new({
91             from => $self->from,
92             to => $self->to,
93             nodes => $_nodes });
94             }
95              
96             sub as_string {
97 0     0 0   my ($self) = @_;
98              
99 0           return join ", ", @{$self->nodes};
  0            
100             }
101              
102             =head1 AUTHOR
103              
104             Mohammad S Anwar, C<< >>
105              
106             =head1 REPOSITORY
107              
108             L
109              
110             =head1 BUGS
111              
112             Please report any bugs or feature requests to C, or
113             through the web interface at L.
114             I will be notified and then you'll automatically be notified of progress on your
115             bug as I make changes.
116              
117             =head1 SUPPORT
118              
119             You can find documentation for this module with the perldoc command.
120              
121             perldoc Map::Tube::Route
122              
123             You can also look for information at:
124              
125             =over 4
126              
127             =item * RT: CPAN's request tracker (report bugs here)
128              
129             L
130              
131             =item * AnnoCPAN: Annotated CPAN documentation
132              
133             L
134              
135             =item * CPAN Ratings
136              
137             L
138              
139             =item * Search CPAN
140              
141             L
142              
143             =back
144              
145             =head1 LICENSE AND COPYRIGHT
146              
147             Copyright (C) 2010 - 2016 Mohammad S Anwar.
148              
149             This program is free software; you can redistribute it and/or modify it under
150             the terms of the the Artistic License (2.0). You may obtain a copy of the full
151             license at:
152              
153             L
154              
155             Any use, modification, and distribution of the Standard or Modified Versions is
156             governed by this Artistic License.By using, modifying or distributing the Package,
157             you accept this license. Do not use, modify, or distribute the Package, if you do
158             not accept this license.
159              
160             If your Modified Version has been derived from a Modified Version made by someone
161             other than you,you are nevertheless required to ensure that your Modified Version
162             complies with the requirements of this license.
163              
164             This license does not grant you the right to use any trademark, service mark,
165             tradename, or logo of the Copyright Holder.
166              
167             This license includes the non-exclusive, worldwide, free-of-charge patent license
168             to make, have made, use, offer to sell, sell, import and otherwise transfer the
169             Package with respect to any patent claims licensable by the Copyright Holder that
170             are necessarily infringed by the Package. If you institute patent litigation
171             (including a cross-claim or counterclaim) against any party alleging that the
172             Package constitutes direct or contributory patent infringement,then this Artistic
173             License to you shall terminate on the date that such litigation is filed.
174              
175             Disclaimer of Warranty: THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER AND
176             CONTRIBUTORS "AS IS' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES. THE IMPLIED
177             WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR
178             NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY YOUR LOCAL LAW. UNLESS
179             REQUIRED BY LAW, NO COPYRIGHT HOLDER OR CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT,
180             INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE
181             OF THE PACKAGE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
182              
183             =cut
184              
185             1; # End of Map::Tube::Route