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