| 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.2405'; | |||||||||||||||||||||||||||
| 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 | 80 | ▶ | around BUILDARGS => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=5 SCAR=17.4
| |||||||||||||||||||||||||||||
| 96 | 80 | my $orig = shift; | |||||||||||||||||||||||||||
| 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
Condition33%1/3
exists $args{"do_undiacritic"} and not $args{"do_undiacritic"}
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"}
| |||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | 80 | my $no_diacritic = undiacriticise($args{'name'}); | |||||||||||||||||||||||||||
| 103 | 80 | ▶ | if(defined $no_diacritic) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 104 | 16 | ▶ | if(exists $args{'search_names'}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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 | 0 | ▶ | sub set_name { | ||||||||||||||||||||||||||
|
Subroutine
set_name: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 115 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 116 | 0 | my $name = shift; | |||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||
| 118 | 0 | ▶ | if($self->do_undiacritic) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 119 | 0 | my $no_diacritic = undiacriticise($name); | |||||||||||||||||||||||||||
| 120 | 0 | ▶ | if(defined $no_diacritic) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 121 | 0 | $self->add_search_name($no_diacritic); | |||||||||||||||||||||||||||
| 122 | } | ||||||||||||||||||||||||||||
| 123 | } | ||||||||||||||||||||||||||||
| 124 | 0 | $self->name($name); | |||||||||||||||||||||||||||
| 125 | } | ||||||||||||||||||||||||||||
| 126 | 0 | ▶ | sub set_original_name { | ||||||||||||||||||||||||||
|
Subroutine
set_original_name: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 127 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 128 | 0 | my $name = shift; | |||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||
| 130 | 0 | ▶ | if($self->do_undiacritic) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 131 | 0 | my $no_diacritic = undiacriticise($name); | |||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||
| 133 | 0 | ▶ | if(defined $no_diacritic) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 134 | 0 | $self->add_search_name($no_diacritic); | |||||||||||||||||||||||||||
| 135 | } | ||||||||||||||||||||||||||||
| 136 | } | ||||||||||||||||||||||||||||
| 137 | 0 | $self->original_name($name); | |||||||||||||||||||||||||||
| 138 | } | ||||||||||||||||||||||||||||
| 139 | 0 | ▶ | around add_search_name => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||
| 140 | 0 | my $next = shift; | |||||||||||||||||||||||||||
| 141 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 142 | 0 | my @names = @_; | |||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||
| 144 | 0 | ▶ | if($self->do_undiacritic) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 148 | } | ||||||||||||||||||||||||||||
| 149 | } | ||||||||||||||||||||||||||||
| 150 | 0 | $self->$next(@names); | |||||||||||||||||||||||||||
| 151 | 14 | }; | |||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||
| 153 | 0 | ▶ | around add_alternative_name => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||
| 154 | 0 | my $next = shift; | |||||||||||||||||||||||||||
| 155 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 156 | 0 | my @names = @_; | |||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||
| 158 | 0 | ▶ | if($self->do_undiacritic) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 162 | } | ||||||||||||||||||||||||||||
| 163 | } | ||||||||||||||||||||||||||||
| 164 | 0 | $self->$next(@names); | |||||||||||||||||||||||||||
| 165 | 14 | }; | |||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||
| 167 | 192 | ▶ | around add_line => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 168 | 192 | my $next = shift; | |||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 173 | 14 | }; | |||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||
| 175 | 192 | ▶ | around add_connecting_station => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 176 | 192 | my $next = shift; | |||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 181 | 14 | }; | |||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||
| 183 | 0 | ▶ | sub name_with_alternative { | ||||||||||||||||||||||||||
|
Subroutine
name_with_alternative: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 184 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||
| 186 | 0 | return ($self->name, $self->all_alternative_names); | |||||||||||||||||||||||||||
| 187 | } | ||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||
| 189 | 80 | ▶ | sub undiacriticise { | ||||||||||||||||||||||||||
|
Subroutine
undiacriticise: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 190 | 80 | my $text = shift; | |||||||||||||||||||||||||||
| 191 | 80 | my $undia = undiacritic($text); | |||||||||||||||||||||||||||
| 192 | 80 | ▶ | return $undia if $undia ne $text; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 193 | 64 | return; | |||||||||||||||||||||||||||
| 194 | } | ||||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||
| 196 | 12 | ▶ | sub to_hash { | ||||||||||||||||||||||||||
|
Subroutine
to_hash: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 197 | 12 | my $self = shift; | |||||||||||||||||||||||||||
| 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__ | ||||||||||||||||||||||||||||