Metro/Cmd/Stations.pm

filter: Statementstmt 47.3% 27 / 57 Branchbran 0.0% 0 / 8 Conditioncond 0.0% 0 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 77.7% 7 / 9 Podpod n/a totaltotal 44.1% 34 / 77 CC 9 SCAR 38.7
CC
9
Cov
40%
run
90.0
station_to_text
2.0
BEGIN
1.0
CRAP 48.2
« Metro/Plugin/Hook/PrettyPrinter.pm ↑ Summary Metro/Cmd/Lines.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::Stations;
6  
7 # ABSTRACT: Show all stations in a 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 Term::Size::Any 'chars';
Subroutine BEGIN: called CC=1 SCAR=0.0
15 1 ▶use Types::Standard qw/Str/;
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 1 parameter cityname => (
18 is => 'rw',
19 isa => Str,
20 documentation => 'The name of the city you want to search in',
21 required => 1,
22 );
23  
24 1 command_short_description 'Show all stations in a map';
25  
26 0 ▶sub run {
Subroutine run: not called CC=9 SCAR=45.0
27 0 my $self = shift;
28  
29 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
30  
31 0 my @station_texts = map { $self->station_to_text($_) } sort { $a->name cmp $b->name } $graph->all_stations;
32 0 my $intro_text = sprintf 'Stations: %s', scalar @station_texts;
33  
34 0 my $column_width = length ((sort { length $b <=> length $a } @station_texts)[0]) + 3;
35 0 my($terminal_width, $terminal_height) = chars;
36  
37  
38 0 my $column_count = (int $terminal_width / $column_width) - 2;
39 0 ▶ $column_count = 9 if $column_count > 9;
Branch: 1 branch
BranchTrueFalseTotal
if $column_count > 9 0 0 0
40  
41 0 my $columns = [];
42 0 my $max_per_column = 1 + int scalar @station_texts / $column_count;
43  
44 0 foreach (1..$column_count) {
45 0 my $column = [];
46 0 ▶ while(scalar @$column < $max_per_column && scalar @station_texts) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$column < $max_per_column and scalar @station_texts) 0 0 0
Condition0%0/2
scalar @$column < $max_per_column and scalar @station_texts
!ll
00
MC/DC0%0/1
scalar @$column < $max_per_column and scalar @station_texts
scalar @$column < $max_per_column
Truth table0%0/2
A
A= scalar @$column < $max_per_column
Aresult
00
11
47 0 my $text = shift @station_texts;
48 0 my $padding = ' ' x ($column_width - length $text);
49  
50 0 push @$column => $text . $padding;
51 }
52 0 push @$columns => $column;
53 }
54  
55 0 say join "\n" => '', $intro_text, '';
56 0 foreach my $row (0..scalar @{ $columns->[0] } - 1) {
57 0 foreach my $column (@$columns) {
58 0 ▶ print $column->[$row] if $column->[$row];
Branch: 1 branch
BranchTrueFalseTotal
if $column->[$row] 0 0 0
59 }
60 0 say '';
61 }
62 0 say '';
63 }
64 0 ▶sub station_to_text {
Subroutine station_to_text: not called CC=1 SCAR=6.9
65 0 my $self = shift;
66 0 my $station = shift;
67 0 return sprintf '%3s. %s', $station->id, $station->name;
68 }
69  
70 1 __PACKAGE__->meta->make_immutable;
71  
72 1 1;
73  
74 __END__
« Metro/Plugin/Hook/PrettyPrinter.pm ↑ Summary Metro/Cmd/Lines.pm »