File Coverage

blib/lib/Map/Tube/Line.pm
Criterion Covered Total %
statement 23 35 65.7
branch 0 8 0.0
condition n/a
subroutine 8 11 72.7
pod 1 3 33.3
total 32 57 56.1


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