;
unless ((grep /^xml$/, @attributes) || (grep /^json$/, @attributes)) {
die "ERROR: Can't apply Map::Tube role, missing 'xml' or 'json'.";
}
$self->_init_map;
$self->_load_pl
_number => $caller->[2] });
}
else {
my $json = $self->json;
if ($json ne '') {
eval { $data = to_perl($json) };
unless ($@) {
$self->_v
method => $method,
message => "ERROR: Malformed Map Data ($json): $@",
filename => $caller->[1],
line_number => $caller->[2] }
data (XML or JSON) and store it
# surreptitiously in the Map::Tube object for later use.
my $map = shift;
return _prepare_xml_map($map ) if $map->can('xml');
return _prepare_json_map($map) if
n_served_by_lines,
};
return $map;
}
sub _prepare_json_map {
# analyse the original map data (JSON format) and store them
# surreptitiously in the Map::Tube object for lat
ion_served_by_lines,
%station_line_count,
);
my $json = Map::Tube::Utils::to_perl( $map->json( ) );
for my $line ( @{ $json->{lines}{line} } ) {
my $id_case = $line->{id};
my $
Tube> library.
=head1 CREATE A MAP
C<Map::Tube v3.22> or above now supports map data in XML and JSON format. Here is
the structure of a map in XML format:
<?xml version="1.0" encoding="UTF-8"?>
.....
.....
.....
</stations>
</tube>
And the same in JSON format:
{
"name" : "Your-Map-Name",
"lines" : {
"line" : [
line="L1:8" link="L07" />
</stations>
</tube>
Next is the JSON representation C<sample.json> of the above map:
{
"name" : "Sample",
"lines" : { "line
1 VERSION
Version 4.10
=cut
use utf8;
use v5.14;
use strict;
use warnings;
use Try::Tiny;
use JSON::MaybeXS;
use Scalar::Util ();
use File::ShareDir ':ALL';
use Unicode::Normalize 'NFC';
use pare
e) = @_;
my $json_text = do {
open(my $json_fh, "<", $file) or die("ERROR: Can't open $file: $!\n");
local $/;
my $text = <$json_fh>;
close($json_fh);
$tex
t;
};
try {
return JSON::MaybeXS->new->allow_nonref->utf8(1)->decode($json_text);
}
catch {
die $@;
};
}
sub trim {
my ($data) = @_;
return unless define