blib/lib/Map/Tube/Text/Shortest.pm

filter: Statementstmt 44.6% 25 / 56 Branchbran 0.0% 0 / 12 Conditioncond 0.0% 0 / 5 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 70.0% 7 / 10 Podpod 100% 2 / 2 totaltotal 38.6% 34 / 88 SCAR 39.7
CC
12
Cov
34%
print
72.0
new
20.0
__ANON__
6.0
CRAP 52.9
↑ Summary
1 package Map::Tube::Text::Shortest;
2  
3 # Pragmas.
4 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 # Modules.
8 3 ▶use Class::Utils qw(set_params);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 3 ▶use Error::Pure qw(err);
Subroutine BEGIN: called CC=1 SCAR=0.0
10 3 ▶use List::Util qw(reduce);
Subroutine BEGIN: called CC=1 SCAR=0.0
11 3 ▶use Readonly;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 3 ▶use Scalar::Util qw(blessed);
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 # Constants.
15 3 Readonly::Scalar our $DOUBLE_SPACE => q{ };
16 3 Readonly::Scalar our $EMPTY_STR => q{};
17  
18 # Version.
19 3 our $VERSION = 0.01;
20  
21 # Constructor.
22 sub new {
23 0 ▶ my ($class, @params) = @_;
Subroutine new: not called CC=4 SCAR=30.0
Pod documented
24  
25 # Create object.
26 0 my $self = bless {}, $class;
27  
28 # Map::Tube object.
29 0 $self->{'tube'} = undef;
30  
31 # Process params.
32 0 set_params($self, @params);
33  
34 # Check Map::Tube object.
35 0 ▶ if (! defined $self->{'tube'}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"tube"}) 0 0 0
36 0 err "Parameter 'tube' is required.";
37 }
38 0 ▶ if (! blessed($self->{'tube'})
Branch: 1 branch
BranchTrueFalseTotal
unless (builtin::blessed($self->{"tube"}) and $self->{"tube"}->does("Map::Tube")) 0 0 0
Condition0%0/3
builtin::blessed($self->{"tube"}) and $self->{"tube"}->does("Map::Tube")
!ll&&!rl&&r
000
MC/DC0%0/2
builtin::blessed($self->{"tube"}) and $self->{"tube"}->does("Map::Tube")
builtin::blessed($self->{"tube"}) $self->{"tube"}->does("Map::Tube")
Truth table0%0/3
A and B
A= builtin::blessed($self->{"tube"})B= $self->{"tube"}->does("Map::Tube")
ABresult
0X0
100
111
39 || ! $self->{'tube'}->does('Map::Tube')) {
40  
41 0 err "Parameter 'tube' must be 'Map::Tube' object.";
42 }
43  
44 # Object.
45 0 return $self;
46 }
47  
48 # Print shortest table.
49 sub print {
50 0 ▶ my ($self, $from, $to) = @_;
Subroutine print: not called CC=8 SCAR=42.8
Pod documented
51 0 my $route = $self->{'tube'}->get_shortest_route($from, $to);
52 0 my $header = sprintf 'From %s to %s', $route->from->name,
53 $route->to->name;
54 0 my @output = (
55 $EMPTY_STR,
56 $header,
57 '=' x length $header,
58 $EMPTY_STR,
59 sprintf '-- Route %d (cost %s) ----------', 1, '?',
60 );
61 my $line_id_length = length
62 0 ▶ reduce { length($a) > length($b) ? $a : $b }
Subroutine __ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
length $a > length $b ? : 0 0 0
63 0 ▶ map { $_->id || '?'} @{$self->{'tube'}->get_lines};
Branch: 1 branch
BranchTrueFalseTotal
$_->id or "?" 0 0 0
64 0 foreach my $node (@{$route->nodes}) {
65 0 my $num = 0;
66 0 foreach my $line (@{$node->line}) {
67 0 $num++;
68 0 ▶ my $line_id = $line->id || '?';
Condition0%0/2
$line->id || '?'
l!l
00
MC/DC0%0/1
$line->id || '?'
$line->id
Truth table0%0/2
A
A= $line->id
Aresult
11
00
69 0 ▶ push @output, sprintf "[ %1s %-${line_id_length}s ] %s",
Branch: 1 branch
BranchTrueFalseTotal
$num == 2 ? : 0 0 0
70 # TODO +
71 $num == 2 ? '*' : $EMPTY_STR,
72 $line_id,
73 $node->name;
74 }
75 }
76 0 push @output, $EMPTY_STR;
77 # TODO Skip lines, which are not in route table.
78 0 foreach my $line (@{$self->{'tube'}->get_lines}) {
79 0 push @output, (
80 $line->id.$DOUBLE_SPACE.$line->name,
81 );
82 }
83 0 push @output, (
84 $EMPTY_STR,
85 '*: Transfer to other line',
86 '+: Transfer to other station',
87 $EMPTY_STR,
88 );
89 0 ▶ return wantarray ? @output : join "\n", @output;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
90 }
91  
92 3 1;
93  
94 __END__
↑ Summary