Metro/Plugin/Map.pm

filter: Statementstmt 74.4% 35 / 47 Branchbran 0.0% 0 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 71.4% 10 / 14 Podpod 0.0% 0 / 3 totaltotal 64.2% 45 / 70 CC 4 SCAR 10.4
CC
4
Cov
66%
mapdir
6.0
maplocation
6.0
version
6.0
CRAP 2.8
« Metro/Shim.pm ↑ Summary Metro/Graph/Step.pm »
1 1 ▶use 5.10.0;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 package Map::Metro::Plugin::Map;
6  
7 # ABSTRACT: How to make your own map
8 1 our $AUTHORITY = 'cpan:CSSON'; # AUTHORITY
9 1 our $VERSION = '0.2404';
10  
11 1 ▶use Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 ▶use MooseX::AttributeShortcuts;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 1 ▶use File::ShareDir 'dist_dir';
Subroutine BEGIN: called CC=1 SCAR=0.0
15 1 ▶use Path::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 1 ▶use Types::Standard qw/Bool ArrayRef Str/;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 1 ▶use Types::Path::Tiny qw/Path/;
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 1 has mapfile => (
20 is => 'ro',
21 isa => Path,
22 predicate => 1,
23 coerce => 1,
24 );
25 1 has do_undiacritic => (
26 is => 'rw',
27 isa => Bool,
28 default => 1,
29 );
30 has hooks => (
31 is => 'ro',
32 isa => ArrayRef[ Str ],
33 traits => ['Array'],
34 0 ▶ default => sub { [] },
Subroutine __ANON__: not called CC=1 SCAR=6.9
35 1 handles => {
36 all_hooks => 'elements',
37 },
38 );
39  
40 sub mapdir {
41 0 ▶ my $self = shift;
Subroutine mapdir: not called CC=2 SCAR=17.9
Pod undocumented
42 0 ▶ return $self->mapfile->parent if $self->mapfile->is_absolute; # work with old api
Branch: 1 branch
BranchTrueFalseTotal
if $self->mapfile->is_absolute 0 0 0
43 0 my $package = $self->map_package;
44 0 $package =~ s{::}{-}g;
45 0 return path(dist_dir($package));
46 }
47 sub maplocation {
48 0 ▶ my $self = shift;
Subroutine maplocation: not called CC=2 SCAR=17.9
Pod undocumented
49 0 ▶ return $self->mapfile if $self->mapfile->is_absolute; # work with old api
Branch: 1 branch
BranchTrueFalseTotal
if $self->mapfile->is_absolute 0 0 0
50 0 return $self->mapdir->child($self->mapfile);
51 }
52  
53 sub version {
54 0 ▶ my $self = shift;
Subroutine version: not called CC=2 SCAR=17.9
Pod undocumented
55 0 ▶ return 0 if $self->mapfile->is_absolute; # work with old api when we had no map_version()
Branch: 1 branch
BranchTrueFalseTotal
if $self->mapfile->is_absolute 0 0 0
56 0 return $self->map_version;
57 }
58  
59 1 1;
60  
61 __END__
62  
63 =pod
64  
65 =encoding utf-8
66  
67 =head1 NAME
68  
69 Map::Metro::Plugin::Map - How to make your own map
70  
71 =head1 VERSION
72  
73 Version 0.2404, released 2016-04-30.
74  
75 =head1 SYNOPSIS
76  
77 # This is a modified part of the map from Map::Metro::Plugin::Map::Stockholm
78  
79 --stations
80 Stadshagen
81 Fridhemsplan
82 Rådhuset
83 T-Centralen
84  
85 # comments are possible
86 Gamla stan
87 Slussen
88 Medborgarplatsen
89 Skanstull
90 Gullmarsplan
91 Globen
92 Sergels torg
93 Nybroplan
94  
95 --transfers
96 T-Centralen|Sergels torg|weight:4
97  
98 --lines
99 10|T10|Blue line
100 11|T11|Blue line
101 19|T19|Green line|color:#79c142
102 7|L7|Spårväg city
103  
104 --segments
105 10->,11<-|Stadshagen|Fridhemsplan % Västermalmsgallerian
106 10,11|Fridhemsplan|Rådhuset % :Radhuset
107 10,11|Rådhuset|T-Centralen
108 10,11|T-Centralen|Kungsträdgården
109 19|T-Centralen|Gamla stan
110 19|Gamla stan|Slussen
111 19|Slussen|Medborgarplatsen
112 19|Medborgarplatsen|Skanstull
113 19|Skanstull|Gullmarsplan
114 19|Gullmarsplan|Globen
115 7|Sergels torg|Nybroplan
116  
117 =head1 DESCRIPTION
118  
119 It is straightforward to create a map file. It consists of four parts:
120  
121 =head2 --stations
122  
123 This is a list of all stations in the network. Currently only one value per line. Don't use C<|> in station names.
124  
125 =head2 --transfers
126  
127 This is a list of L<Transfers|Map::Metro::Graph::Transfer>. If two stations share at least one line they are B<not> transfers. Three groups of data per line (delimited by C<|>):
128  
129 =over 4
130  
131 =item The first station.
132  
133 =item The following station.
134  
135 =item Optional options.
136  
137 =back
138  
139 The options in turn is a comma separated list of colon separated key-value pairs. Currently the only supported option is:
140  
141 =over 4
142  
143 =item weight. Integer. Set a custom weight for the 'cost' of making this transfer. Default value is 5. (Travelling between two
144 stations on the same line cost 1, and changing lines at a station costs 3).
145  
146 =back
147  
148 =head2 --lines
149  
150 This is a list of all lines in the network. Three values per line (delimited by C<|>):
151  
152 * Line id (only a-z, A-Z and 0-9 allowed). Used in segments.
153  
154 * Line name. This should preferably be short(ish) and a common name for the line.
155  
156 * Line description. This can be a longer common name for the line.
157  
158 * Optional options, a comma separated list of colon separated key-value pairs:
159  
160 =over 4
161  
162 * color. Hexadecimal, preceeded by '#'. Can be used by visualization tools to give lines their regular colours.
163  
164 * width. Integer. Can be used by visualization tools to give lines different widths, for example differentiate different types of transport.
165  
166 =back
167  
168 =head2 --segments
169  
170 This is a list of all L<Segments|Map::Metro::Graph::Segment> in the network. (A segment is a pair of consecutive stations.) Three groups of data per line (delimited by C<|>):
171  
172 * A list of line ids (comma delimited). This references the line list above. The list of line ids represents all lines travelling between the two stations.
173  
174 * The first station.
175  
176 * The following station
177  
178 In the synopsis, segments part starts like this:
179  
180 10->,11<-|Stadshagen|Fridhemsplan % Västermalmsgallerian
181 10,11|Fridhemsplan|Rådhuset % :Radhuset
182  
183 First, the arrow notation describes the direction of travel (the default is both ways, all three can be combined in one segment definition).
184  
185 C<-E<gt>> means that the line only travels I<from> Stadshagen I<to> Fridhemsplan.
186  
187 C<E<lt>-> means that the line only travels I<from> Fridhemsplan I<to> Stadshagen.
188  
189 Second, the C<%> notation makes it possible to attach more names to the station.
190  
191 If the name begins with a C<:> it is considered a I<search name>. This mean that it is possible to search, but it is generally not displayed (eg. by the L<PrettyPrinter|Map::Metro::Plugin::Hook::PrettyPrinter> hook).
192  
193 If the name doesn't begin with a C<:> it is considered an I<alternative name>. The L<PrettyPrinter|Map::Metro::Plugin::Hook::PrettyPrinter> hook displays them as "first given name/alternative name".
194  
195 =head3 When to use what?
196  
197 B<Alternative names> are used when the I<same station> is known as both names. This is not very common.
198  
199 B<Search names> is mostly useful when a station has changed names (keep the old name as a search name)
200  
201 Overriding station names through a hook (as L<Map::Metro::Plugin::Hook::Helsinki::Swedish> does) can be a good way to present translations or transliterations of station names.
202  
203 Just make sure that no names collide.
204  
205 =head1 WHAT NOW?
206  
207 Start a distribution called C<Map::Metro::Plugin::Map::$city>.
208  
209 =head2 With Dist::Zilla
210  
211 The easiest way to do that is to use L<Dist::Zilla> with L<Dist::Zilla::MintingProfile::MapMetro::Map>. See also L<Task::MapMetro::Dev>.
212  
213 $ dzil new -P MapMetro::Map Map::Metro::Plugin::Map::TheCity
214  
215 =head2 Without Dist::Zilla
216  
217 Save the map file as C<map-$city.metro> in the C<share> directory.
218  
219 Say we make a map for London; then C<Map::Metro::Plugin::Map::London> would look like this:
220  
221 use strict;
222  
223 package Map::Metro::Plugin::Map::London;
224  
225 our $VERSION = 0.01;
226  
227 use Moose;
228 with 'Map::Metro::Plugin::Map';
229  
230 has '+mapfile' => (
231 default => 'map-london.metro',
232 );
233 sub map_version {
234 return $VERSION;
235 }
236 sub map_package {
237 return __PACKAGE__;
238 }
239  
240 1;
241  
242 =head2 Diacritics?
243  
244 By default, station names with diacritics get their un-diacritic form added as a search name. If this causes problems with a map file, add this to the module definition and it is turned off:
245  
246 has '+do_undiacritic' => (
247 default => 0,
248 );
249  
250 =head1 SOURCE
251  
252 L<https://github.com/Csson/p5-Map-Metro>
253  
254 =head1 HOMEPAGE
255  
256 L<https://metacpan.org/release/Map-Metro>
257  
258 =head1 AUTHOR
259  
260 Erik Carlsson <info@code301.com>
261  
262 =head1 COPYRIGHT AND LICENSE
263  
264 This software is copyright (c) 2016 by Erik Carlsson.
265  
266 This is free software; you can redistribute it and/or modify it under
267 the same terms as the Perl 5 programming language system itself.
268  
269 =cut
« Metro/Shim.pm ↑ Summary Metro/Graph/Step.pm »