Metro/Graph/Station.pm

filter: Statementstmt 66.3% 67 / 101 Branchbran 35.7% 10 / 28 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 78.2% 18 / 23 Podpod 0.0% 0 / 5 totaltotal 59.2% 96 / 162 CC 18 SCAR 19.8
CC
18
Cov
59%
__ANON__
20.0
__ANON__
20.0
set_name
12.0
CRAP 7.2
« Metro/Graph.pm ↑ Summary Metro.pm »
1 14 ▶use 5.10.0;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 14 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 14 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 package Map::Metro::Graph::Station;
6  
7 # ABSTRACT: Information about a station
8 14 our $AUTHORITY = 'cpan:CSSON'; # AUTHORITY
9 14 our $VERSION = '0.2404';
10  
11 14 ▶use Map::Metro::Elk;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 14 ▶use Types::Standard qw/Int Str Maybe ArrayRef Bool/;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 14 ▶use Map::Metro::Types qw/Line Station/;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 14 ▶use Text::Undiacritic 'undiacritic';
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 14 has id => (
17 is => 'ro',
18 isa => Int,
19 required => 1,
20 documentation => 'Internal identification',
21 );
22  
23 14 has name => (
24 is => 'rw',
25 isa => Str,
26 required => 1,
27 documentation => q{The station's name, with any diacritics removed.},
28 );
29 14 has original_name => (
30 is => 'ro',
31 isa => Maybe[Str],
32 documentation => q{The station's name as given in the map file.},
33 );
34 has search_names => (
35 is => 'rw',
36 isa => ArrayRef[Str],
37 traits => ['Array'],
38 64 ▶ default => sub { [] },
Subroutine __ANON__: called CC=1 SCAR=0.0
39 14 handles => {
40 add_search_name => 'push',
41 all_search_names => 'elements',
42 },
43 documentation => q{All search names for the station given in the map file.},
44 );
45 has alternative_names => (
46 is => 'rw',
47 isa => ArrayRef[Str],
48 traits => ['Array'],
49 80 ▶ default => sub { [] },
Subroutine __ANON__: called CC=1 SCAR=0.0
50 14 handles => {
51 add_alternative_name => 'push',
52 all_alternative_names => 'elements',
53 },
54 documentation => q{All alternative names for the station given in the map file.},
55 );
56  
57 has lines => (
58 is => 'rw',
59 isa => ArrayRef[ Line ],
60 traits => ['Array'],
61 80 ▶ default => sub { [] },
Subroutine __ANON__: called CC=1 SCAR=0.0
62 14 init_arg => undef,
63 handles => {
64 add_line => 'push',
65 all_lines => 'elements',
66 find_line => 'first',
67 filter_lines => 'grep',
68 },
69 documentation => q{All lines passing through this station.},
70 );
71 has connecting_stations => (
72 is => 'ro',
73 isa => ArrayRef[ Station ],
74 traits => ['Array'],
75 80 ▶ default => sub { [] },
Subroutine __ANON__: called CC=1 SCAR=0.0
76 14 init_arg => undef,
77 handles => {
78 add_connecting_station => 'push',
79 all_connecting_stations => 'elements',
80 find_connecting_station => 'first',
81 },
82 documentation => q{All stations one can travel to from this station without passing another station.},
83 );
84 14 has do_undiacritic => (
85 is => 'rw',
86 isa => Bool,
87 default => 1,
88 traits => ['Documented'],
89 documentation_alts => {
90 0 => q{Do not remove diacritics from station name.},
91 1 => q{Do remove diacritics from station name.},
92 },
93 );
94  
95 around BUILDARGS => sub {
96 80 ▶ my $orig = shift;
Subroutine __ANON__: called CC=5 SCAR=17.4
97 80 my $class = shift;
98 80 my %args = @_;
99  
100 80 ▶ return $class->$orig(%args) if exists $args{'do_undiacritic'} && !$args{'do_undiacritic'};
Branch: 1 branch
BranchTrueFalseTotal
if exists $args{"do_undiacritic"} and not $args{"do_undiacritic"} 0 80 80
Condition33%1/3
exists $args{"do_undiacritic"} and not $args{"do_undiacritic"}
!ll&&!rl&&r
0800
MC/DC0%0/2
exists $args{"do_undiacritic"} and not $args{"do_undiacritic"}
exists $args{"do_undiacritic"} not $args{"do_undiacritic"}
Truth table33%1/3
A and not(B)
A= exists $args{"do_undiacritic"}B= not $args{"do_undiacritic"}
ABresult
0X0
100
111
101  
102 80 my $no_diacritic = undiacriticise($args{'name'});
103 80 ▶ if(defined $no_diacritic) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $no_diacritic) 16 64 80
104 16 ▶ if(exists $args{'search_names'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $args{'search_names'}) { } 0 16 16
105 0 push @{ $args{'search_names'} } => $no_diacritic;
106 }
107 else {
108 16 $args{'search_names'} = [$no_diacritic];
109 }
110 }
111 80 return $class->$orig(%args);
112 14 };
113  
114 sub set_name {
115 0 ▶ my $self = shift;
Subroutine set_name: not called CC=3 SCAR=24.8
Pod undocumented
116 0 my $name = shift;
117  
118 0 ▶ if($self->do_undiacritic) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->do_undiacritic) 0 0 0
119 0 my $no_diacritic = undiacriticise($name);
120 0 ▶ if(defined $no_diacritic) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $no_diacritic) 0 0 0
121 0 $self->add_search_name($no_diacritic);
122 }
123 }
124 0 $self->name($name);
125 }
126 sub set_original_name {
127 0 ▶ my $self = shift;
Subroutine set_original_name: not called CC=3 SCAR=24.8
Pod undocumented
128 0 my $name = shift;
129  
130 0 ▶ if($self->do_undiacritic) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->do_undiacritic) 0 0 0
131 0 my $no_diacritic = undiacriticise($name);
132  
133 0 ▶ if(defined $no_diacritic) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $no_diacritic) 0 0 0
134 0 $self->add_search_name($no_diacritic);
135 }
136 }
137 0 $self->original_name($name);
138 }
139 around add_search_name => sub {
140 0 ▶ my $next = shift;
Subroutine __ANON__: not called CC=4 SCAR=30.0
141 0 my $self = shift;
142 0 my @names = @_;
143  
144 0 ▶ if($self->do_undiacritic) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->do_undiacritic) 0 0 0
145 0 foreach my $name (@names) {
146 0 my $no_diacritic = undiacriticise($name);
147 0 ▶ push @names => $no_diacritic if defined $no_diacritic;
Branch: 1 branch
BranchTrueFalseTotal
if defined $no_diacritic 0 0 0
148 }
149 }
150 0 $self->$next(@names);
151 14 };
152  
153 around add_alternative_name => sub {
154 0 ▶ my $next = shift;
Subroutine __ANON__: not called CC=4 SCAR=30.0
155 0 my $self = shift;
156 0 my @names = @_;
157  
158 0 ▶ if($self->do_undiacritic) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->do_undiacritic) 0 0 0
159 0 foreach my $name (@names) {
160 0 my $no_diacritic = undiacriticise($name);
161 0 ▶ push @names => $no_diacritic if defined $no_diacritic;
Branch: 1 branch
BranchTrueFalseTotal
if defined $no_diacritic 0 0 0
162 }
163 }
164 0 $self->$next(@names);
165 14 };
166  
167 around add_line => sub {
168 192 ▶ my $next = shift;
Subroutine __ANON__: called CC=2 SCAR=6.9
169 192 my $self = shift;
170 192 my $line = shift; # Line
171  
172 192 ▶ $self->$next($line) if !$self->find_line(sub { $line->id eq $_->id });
Subroutine __ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
BranchTrueFalseTotal
if not $self->find_line(sub { $line->id eq $_->id; } ) 104 88 192
173 14 };
174  
175 around add_connecting_station => sub {
176 192 ▶ my $next = shift;
Subroutine __ANON__: called CC=2 SCAR=6.9
177 192 my $self = shift;
178 192 my $station = shift; # Station
179  
180 192 ▶ $self->$next($station) if !$self->find_connecting_station(sub { $station->id eq $_->id });
Subroutine __ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
BranchTrueFalseTotal
if not $self->find_connecting_station(sub { $station->id eq $_->id; } ) 152 40 192
181 14 };
182  
183 sub name_with_alternative {
184 0 ▶ my $self = shift;
Subroutine name_with_alternative: not called CC=1 SCAR=6.9
Pod undocumented
185  
186 0 return ($self->name, $self->all_alternative_names);
187 }
188  
189 sub undiacriticise {
190 80 ▶ my $text = shift;
Subroutine undiacriticise: called CC=2 SCAR=6.9
Pod undocumented
191 80 my $undia = undiacritic($text);
192 80 ▶ return $undia if $undia ne $text;
Branch: 1 branch
BranchTrueFalseTotal
if $undia ne $text 16 64 80
193 64 return;
194 }
195  
196 sub to_hash {
197 12 ▶ my $self = shift;
Subroutine to_hash: called CC=1 SCAR=0.0
Pod undocumented
198  
199 return {
200 id => $self->id,
201 name => $self->name,
202 original_name => $self->original_name,
203 search_names => [ $self->all_search_names ],
204 alternative_names => [ $self->all_alternative_names ],
205 lines => [
206 12 map { $_->to_hash } $self->all_lines
207 ],
208 # connecting_stations => [
209 # map { $_->to_hash } $self->all_connecting_stations
210 # ],
211  
212 }
213 }
214  
215 14 __PACKAGE__->meta->make_immutable;
216  
217 14 1;
218  
219 __END__
220  
221 =pod
222  
223 =encoding UTF-8
224  
225 =head1 NAME
226  
227 Map::Metro::Graph::Station - Information about a station
228  
229 =head1 VERSION
230  
231 Version 0.2404, released 2016-04-30.
232  
233  
234  
235 =head1 DESCRIPTION
236  
237 Stations represents actual stations, and are used both during the graph building phase and the navigational phase.
238  
239 =head1 ATTRIBUTES
240  
241  
242 =head2 id
243  
244 =begin HTML
245  
246 <table cellpadding="0" cellspacing="0">
247 <tr>
248 <td style="padding-right: 6px; padding-left: 6px; border-right: 1px solid #b8b8b8; white-space: nowrap;"><a href="https://metacpan.org/pod/Types::Standard#Int">Int</a></td>
249 <td style="padding-right: 6px; padding-left: 6px; border-right: 1px solid #b8b8b8; white-space: nowrap;">required</td>
250 <td style="padding-left: 6px; padding-right: 6px; white-space: nowrap;">read-only</td>
251 </tr>
252 </table>
253  
254 <p></p>
255  
256 =end HTML
257  
258 =begin markdown
259  
260 <table cellpadding="0" cellspacing="0">
261 <tr>
262 <td style="padding-right: 6px; padding-left: 6px; border-right: 1px solid #b8b8b8; white-space: nowrap;"><a href="https://metacpan.org/pod/Types::Standard#Int">Int</a></td>
263 <td style="padding-right: 6px; padding-left: 6px; border-right: 1px solid #b8b8b8; white-space: nowrap;">required</td>
264 <td style="padding-left: 6px; padding-right: 6px; white-space: nowrap;">read-only</td>
265 </tr>
266 </table>
267  
268 <p></p>
269  
270 =end markdown
271  
272 =head2 name
273  
274 =begin HTML
275  
276 <table cellpadding="0" cellspacing="0">
277 <tr>
278 <td style="padding-right: 6px; padding-left: 6px; border-right: 1px solid #b8b8b8; white-space: nowrap;"><a href="https://metacpan.org/pod/Types::Standard#Str">Str</a></td>
279 <td style="padding-right: 6px; padding-left: 6px; border-right: 1px solid #b8b8b8; white-space: nowrap;">required</td>
280 <td style="padding-left: 6px; padding-right: 6px; white-space: nowrap;">read/write</td>
281 </tr>
282 </table>
283  
284 <p></p>
285  
286 =end HTML
287  
288 =begin markdown
289  
290 <table cellpadding="0" cellspacing="0">
291 <tr>
292 <td style="padding-right: 6px; padding-left: 6px; border-right: 1px solid #b8b8b8; white-space: nowrap;"><a href="https://metacpan.org/pod/Types::Standard#Str">Str</a></td>
293 <td style="padding-right: 6px; padding-left: 6px; border-right: 1px solid #b8b8b8; white-space: nowrap;">required</td>
294 <td style="padding-left: 6px; padding-right: 6px; white-space: nowrap;">read/write</td>
295 </tr>
296 </table>
297  
298 <p></p>
299  
300 =end markdown
301  
302 =head2 do_undiacritic
303  
304 =begin HTML
305  
306 <table cellpadding="0" cellspacing="0">
307 <tr>
308 <td style="padding-right: 6px; padding-left: 6px; border-right: 1px solid #b8b8b8; white-space: nowrap;"><a href="https://metacpan.org/pod/Types::Standard#Bool">Bool</a></td>
309 <td style="padding-right: 6px; padding-left: 6px; border-right: 1px solid #b8b8b8; white-space: nowrap;">optional, default: <code>1</code></td>
310 <td style="padding-right: 6px; padding-left: 6px; border-right: 1px solid #b8b8b8; white-space: nowrap;">read/write</td>
311 <td style="text-align: right; padding-right: 6px; padding-left: 6px;"><code>0</code>:</td>
312 <td style="padding-left: 12px;">Do not remove diacritics from station name.</td>
313 </tr>
314 <tr>
315 <td>&#160;</td>
316 <td>&#160;</td>
317 <td>&#160;</td>
318 <td style="text-align: right; padding-right: 6px; padding-left: 6px;"><code>1</code>:</td>
319 <td style="padding-left: 12px;">Do remove diacritics from station name.</td>
320 </tr>
321 </table>
322  
323 <p></p>
324  
325 =end HTML
326  
327 =begin markdown
328  
329 <table cellpadding="0" cellspacing="0">
330 <tr>
331 <td style="padding-right: 6px; padding-left: 6px; border-right: 1px solid #b8b8b8; white-space: nowrap;"><a href="https://metacpan.org/pod/Types::Standard#Bool">Bool</a></td>
332 <td style="padding-right: 6px; padding-left: 6px; border-right: 1px solid #b8b8b8; white-space: nowrap;">optional, default: <code>1</code></td>
333 <td style="padding-right: 6px; padding-left: 6px; border-right: 1px solid #b8b8b8; white-space: nowrap;">read/write</td>
334 <td style="text-align: right; padding-right: 6px; padding-left: 6px;"><code>1</code>:</td>
335 <td style="padding-left: 12px;">Do remove diacritics from station name.</td>
336 </tr>
337 </table>
338  
339 <p></p>
340  
341 =end markdown
342  
343 =head2 alternative_names
344  
345 =begin HTML
346  
347 <table cellpadding="0" cellspacing="0">
348 <tr>
349 <td style="padding-right: 6px; padding-left: 6px; border-right: 1px solid #b8b8b8; white-space: nowrap;"><a href="https://metacpan.org/pod/Types::Standard#ArrayRef">ArrayRef</a> [ <a href="https://metacpan.org/pod/Types::Standard#Str">Str</a> ]</td>
350 <td style="padding-right: 6px; padding-left: 6px; border-right: 1px solid #b8b8b8; white-space: nowrap;">optional, default is a <code>coderef</code></td>
351 <td style="padding-left: 6px; padding-right: 6px; white-space: nowrap;">read/write</td>
352 </tr>
353 </table>
354  
355 <p></p>
356  
357 =end HTML
358  
359 =begin markdown
360  
361 <table cellpadding="0" cellspacing="0">
362 <tr>
363 <td style="padding-right: 6px; padding-left: 6px; border-right: 1px solid #b8b8b8; white-space: nowrap;"><a href="https://metacpan.org/pod/Types::Standard#ArrayRef">ArrayRef</a> [ <a href="https://metacpan.org/pod/Types::Standard#Str">Str</a> ]</td>
364 <td style="padding-right: 6px; padding-left: 6px; border-right: 1px solid #b8b8b8; white-space: nowrap;">optional, default is a <code>coderef</code></td>
365 <td style="padding-left: 6px; padding-right: 6px; white-space: nowrap;">read/write</td>
366 </tr>
367 </table>
368  
369 <p></p>
370  
371 =end markdown
372  
373 =head2 original_name
374  
375 =begin HTML
376  
377 <table cellpadding="0" cellspacing="0">
378 <tr>
379 <td style="padding-right: 6px; padding-left: 6px; border-right: 1px solid #b8b8b8; white-space: nowrap;"><a href="https://metacpan.org/pod/Types::Standard#Maybe">Maybe</a> [ <a href="https://metacpan.org/pod/Types::Standard#Str">Str</a> ]</td>
380 <td style="padding-right: 6px; padding-left: 6px; border-right: 1px solid #b8b8b8; white-space: nowrap;">optional</td>
381 <td style="padding-left: 6px; padding-right: 6px; white-space: nowrap;">read-only</td>
382 </tr>
383 </table>
384  
385 <p></p>
386  
387 =end HTML
388  
389 =begin markdown
390  
391 <table cellpadding="0" cellspacing="0">
392 <tr>
393 <td style="padding-right: 6px; padding-left: 6px; border-right: 1px solid #b8b8b8; white-space: nowrap;"><a href="https://metacpan.org/pod/Types::Standard#Maybe">Maybe</a> [ <a href="https://metacpan.org/pod/Types::Standard#Str">Str</a> ]</td>
394 <td style="padding-right: 6px; padding-left: 6px; border-right: 1px solid #b8b8b8; white-space: nowrap;">optional</td>
395 <td style="padding-left: 6px; padding-right: 6px; white-space: nowrap;">read-only</td>
396 </tr>
397 </table>
398  
399 <p></p>
400  
401 =end markdown
402  
403 =head2 search_names
404  
405 =begin HTML
406  
407 <table cellpadding="0" cellspacing="0">
408 <tr>
409 <td style="padding-right: 6px; padding-left: 6px; border-right: 1px solid #b8b8b8; white-space: nowrap;"><a href="https://metacpan.org/pod/Types::Standard#ArrayRef">ArrayRef</a> [ <a href="https://metacpan.org/pod/Types::Standard#Str">Str</a> ]</td>
410 <td style="padding-right: 6px; padding-left: 6px; border-right: 1px solid #b8b8b8; white-space: nowrap;">optional, default is a <code>coderef</code></td>
411 <td style="padding-left: 6px; padding-right: 6px; white-space: nowrap;">read/write</td>
412 </tr>
413 </table>
414  
415 <p></p>
416  
417 =end HTML
418  
419 =begin markdown
420  
421 <table cellpadding="0" cellspacing="0">
422 <tr>
423 <td style="padding-right: 6px; padding-left: 6px; border-right: 1px solid #b8b8b8; white-space: nowrap;"><a href="https://metacpan.org/pod/Types::Standard#ArrayRef">ArrayRef</a> [ <a href="https://metacpan.org/pod/Types::Standard#Str">Str</a> ]</td>
424 <td style="padding-right: 6px; padding-left: 6px; border-right: 1px solid #b8b8b8; white-space: nowrap;">optional, default is a <code>coderef</code></td>
425 <td style="padding-left: 6px; padding-right: 6px; white-space: nowrap;">read/write</td>
426 </tr>
427 </table>
428  
429 <p></p>
430  
431 =end markdown
432  
433 =head2 connecting_stations
434  
435 =begin HTML
436  
437 <table cellpadding="0" cellspacing="0">
438 <tr>
439 <td style="padding-right: 6px; padding-left: 6px; border-right: 1px solid #b8b8b8; white-space: nowrap;"><a href="https://metacpan.org/pod/Types::Standard#ArrayRef">ArrayRef</a> [ <a href="https://metacpan.org/pod/Map::Metro::Types#Station">Station</a> ]</td>
440 <td style="padding-right: 6px; padding-left: 6px; border-right: 1px solid #b8b8b8; white-space: nowrap;">not in constructor</td>
441 <td style="padding-left: 6px; padding-right: 6px; white-space: nowrap;">read-only</td>
442 </tr>
443 </table>
444  
445 <p></p>
446  
447 =end HTML
448  
449 =begin markdown
450  
451 <table cellpadding="0" cellspacing="0">
452 <tr>
453 <td style="padding-right: 6px; padding-left: 6px; border-right: 1px solid #b8b8b8; white-space: nowrap;"><a href="https://metacpan.org/pod/Types::Standard#ArrayRef">ArrayRef</a> [ <a href="https://metacpan.org/pod/Map::Metro::Types#Station">Station</a> ]</td>
454 <td style="padding-right: 6px; padding-left: 6px; border-right: 1px solid #b8b8b8; white-space: nowrap;">not in constructor</td>
455 <td style="padding-left: 6px; padding-right: 6px; white-space: nowrap;">read-only</td>
456 </tr>
457 </table>
458  
459 <p></p>
460  
461 =end markdown
462  
463 =head2 lines
464  
465 =begin HTML
466  
467 <table cellpadding="0" cellspacing="0">
468 <tr>
469 <td style="padding-right: 6px; padding-left: 6px; border-right: 1px solid #b8b8b8; white-space: nowrap;"><a href="https://metacpan.org/pod/Types::Standard#ArrayRef">ArrayRef</a> [ <a href="https://metacpan.org/pod/Types::Standard#Line">Line</a> ]</td>
470 <td style="padding-right: 6px; padding-left: 6px; border-right: 1px solid #b8b8b8; white-space: nowrap;">not in constructor</td>
471 <td style="padding-left: 6px; padding-right: 6px; white-space: nowrap;">read/write</td>
472 </tr>
473 </table>
474  
475 <p></p>
476  
477 =end HTML
478  
479 =begin markdown
480  
481 <table cellpadding="0" cellspacing="0">
482 <tr>
483 <td style="padding-right: 6px; padding-left: 6px; border-right: 1px solid #b8b8b8; white-space: nowrap;"><a href="https://metacpan.org/pod/Types::Standard#ArrayRef">ArrayRef</a> [ <a href="https://metacpan.org/pod/Types::Standard#Line">Line</a> ]</td>
484 <td style="padding-right: 6px; padding-left: 6px; border-right: 1px solid #b8b8b8; white-space: nowrap;">not in constructor</td>
485 <td style="padding-left: 6px; padding-right: 6px; white-space: nowrap;">read/write</td>
486 </tr>
487 </table>
488  
489 <p></p>
490  
491 =end markdown
492  
493 =head1 METHODS
494  
495 =head2 id()
496  
497 Returns the internal station id. Do not depend on this between executions.
498  
499 =head2 name()
500  
501 Returns the station name given in the parsed map file.
502  
503 =head2 lines()
504  
505 Returns an array of all L<Lines|Map::Metro::Graph::Line> passing through the station.
506  
507 =head2 connecting_stations()
508  
509 Returns an array of all L<Stations|Map::Metro::Graph::Station> directly (on at least one line) connected to this station.
510  
511 =head1 SOURCE
512  
513 L<https://github.com/Csson/p5-Map-Metro>
514  
515 =head1 HOMEPAGE
516  
517 L<https://metacpan.org/release/Map-Metro>
518  
519 =head1 AUTHOR
520  
521 Erik Carlsson <info@code301.com>
522  
523 =head1 COPYRIGHT AND LICENSE
524  
525 This software is copyright (c) 2016 by Erik Carlsson.
526  
527 This is free software; you can redistribute it and/or modify it under
528 the same terms as the Perl 5 programming language system itself.
529  
530 =cut
« Metro/Graph.pm ↑ Summary Metro.pm »