11package Map::Tube ;
22
3- $Map::Tube::VERSION = ' 4.07 ' ;
3+ $Map::Tube::VERSION = ' 4.08 ' ;
44$Map::Tube::AUTHORITY = ' cpan:MANWAR' ;
55
66=head1 NAME
@@ -9,7 +9,7 @@ Map::Tube - Lightweight Routing Framework.
99
1010=head1 VERSION
1111
12- Version 4.07
12+ Version 4.08
1313
1414=cut
1515
@@ -418,6 +418,7 @@ sub get_line_by_name {
418418 line_number => $caller [2] }) unless defined $name ;
419419
420420 my $line = $self -> _get_line_object_by_name($name );
421+ $name = _decode_utf8_if_needed($name );
421422 Map::Tube::Exception::InvalidLineName-> throw({
422423 method => __PACKAGE__ ." ::get_line_by_name" ,
423424 message => " ERROR: Invalid Line Name [$name ]." ,
@@ -935,7 +936,7 @@ sub _init_map {
935936 }
936937 my $master_line_data = {};
937938 foreach (@lines ) {
938- $master_line_data -> {lc $_ -> {id }} = 1;
939+ $master_line_data -> {NFC( lc $_ -> {id }) } = 1;
939940 }
940941
941942 my $has_station_index = {};
@@ -967,7 +968,8 @@ sub _init_map {
967968 $has_station_index -> {$_line} = 1;
968969 }
969970
970- if (!exists $master_line_data -> {lc $_line}) {
971+ $_line = _decode_utf8_if_needed($_line);
972+ if (!exists $master_line_data -> {NFC(lc $_line)}) {
971973 Map::Tube::Exception::InvalidStationLineId-> throw({
972974 method => $method ,
973975 message => " ERROR: Invalid line [$_line] for station [$name ]." ,
@@ -1046,6 +1048,16 @@ sub _init_map {
10461048 $self -> tables($tables );
10471049}
10481050
1051+ sub _decode_utf8_if_needed {
1052+ my ($data ) = @_ ;
1053+
1054+ if (!utf8::is_utf8($data ) && utf8::valid($data )) {
1055+ $data = decode_utf8($data );
1056+ }
1057+
1058+ return $data ;
1059+ }
1060+
10491061sub _is_directly_linked {
10501062 my ($self , $start_station , $end_station ) = @_ ;
10511063 my $linked_stations = $self -> get_linked_stations($start_station );
@@ -1269,15 +1281,16 @@ sub _get_node_id {
12691281 return unless defined $name ;
12701282 $name =~ s / ^\s +// ;
12711283 $name =~ s /\s +$// ;
1272- $name = decode_utf8( $name ) if !utf8::is_utf8( $name ) && utf8::valid ($name );
1284+ $name = _decode_utf8_if_needed ($name );
12731285 $name = NFC(uc ($name ));
12741286 return $self -> {name_to_id }-> {$name };
12751287}
12761288
12771289sub _get_line_object_by_name {
12781290 my ($self , $name ) = @_ ;
12791291
1280- $name = uc ($name );
1292+ $name = _decode_utf8_if_needed($name );
1293+ $name = NFC(uc ($name ));
12811294 foreach my $line_id (keys %{$self -> {_lines }}) {
12821295 my $line = $self -> {_lines }-> {$line_id };
12831296 if (defined $line && defined $line -> name) {
0 commit comments