Metro/Cmd/MetroToTube.pm

filter: Statementstmt 60.0% 30 / 50 Branchbran 0.0% 0 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 88.8% 8 / 9 Podpod n/a totaltotal 62.3% 38 / 61 CC 3 SCAR 13.9
CC
3
Cov
58%
run
12.0
BEGIN
1.0
BEGIN
1.0
CRAP 4.0
« Metro/Graph/Connection.pm ↑ Summary Metro/Shim.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::Cmd::MetroToTube;
6  
7 # ABSTRACT: Convert a Map::Metro map into a Map::Tube map
8 1 our $AUTHORITY = 'cpan:CSSON'; # AUTHORITY
9 1 our $VERSION = '0.2405';
10  
11 1 ▶use Map::Metro::Elk;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 ▶use MooseX::App::Command;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 extends 'Map::Metro::Cmd';
14 1 ▶use IO::File;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 1 ▶use XML::Writer;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 1 ▶use Types::Standard qw/Str/;
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 1 parameter cityname => (
19 is => 'rw',
20 isa => Str,
21 documentation => 'The name of the city',
22 required => 1,
23 );
24  
25 1 command_short_description 'Convert a Map::Metro map into a Map::Tube map';
26  
27 0 ▶sub run {
Subroutine run: not called CC=3 SCAR=24.8
28 0 my $self = shift;
29  
30 0 ▶ my $graph = $self->cityname !~ m{\.} ? Map::Metro->new($self->cityname)->parse : Map::Metro::Shim->new($self->cityname)->parse;
Branch: 1 branch
BranchTrueFalseTotal
!($self->cityname =~ /\./) ? : 0 0 0
31  
32 0 my $filename = sprintf 'map-%s-%s.xml', $self->cityname, time;
33 0 my $io = IO::File->new($filename, '>');
34 0 my $xml = XML::Writer->new(OUTPUT => $io, NEWLINES => 1, DATA_INDENT => 4, ENCODING => 'utf-8');
35 0 $xml->xmlDecl('utf-8');
36 0 $xml->startTag('tube', name => $self->cityname);
37 0 $xml->startTag('stations');
38  
39 0 foreach my $station ($graph->all_stations) {
40 0 my $line_names = join ',' => map { $_->name } sort { $a->name cmp $b->name } $station->all_lines;
41 0 my $connecting_station_ids = join ',' => map { $_->id } $station->all_connecting_stations;
42 0 $xml->emptyTag('station', id => $station->id, name => $station->name, line => $line_names, link => $connecting_station_ids);
43 }
44 0 $xml->endTag;
45 0 $xml->endTag;
46 0 $xml->end;
47 0 $io->close;
48  
49 0 say "Saved in $filename.";
50 }
51  
52 1 __PACKAGE__->meta->make_immutable;
53  
54 1 1;
55  
56 __END__
« Metro/Graph/Connection.pm ↑ Summary Metro/Shim.pm »