Metro/Graph/Routing.pm

filter: Statementstmt 73.1% 30 / 41 Branchbran 0.0% 0 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 66.6% 8 / 12 Podpod 0.0% 0 / 2 totaltotal 66.6% 38 / 57 CC 2 SCAR 6.9
CC
2
Cov
70%
__ANON__
6.0
__ANON__
2.0
ordered_routes
2.0
CRAP 2.0
« Metro/Emitter.pm ↑ Summary Metro/Graph/Route.pm »
1 14 ▶use 5.10.0;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 14 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 14 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 package Map::Metro::Graph::Routing;
6  
7 # ABSTRACT: A collection of routes between two stations
8 14 our $AUTHORITY = 'cpan:CSSON'; # AUTHORITY
9 14 our $VERSION = '0.2405';
10  
11 14 ▶use Map::Metro::Elk;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 14 ▶use Types::Standard qw/ArrayRef/;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 14 ▶use Map::Metro::Types qw/Station LineStation Route/;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 14 has origin_station => (
16 is => 'ro',
17 isa => Station,
18 required => 1,
19 );
20 14 has destination_station => (
21 is => 'ro',
22 isa => Station,
23 required => 1,
24 );
25 has line_stations => (
26 is => 'ro',
27 isa => ArrayRef[ LineStation ],
28 traits => ['Array'],
29 1 ▶ default => sub {[]},
Subroutine __ANON__: called CC=1 SCAR=0.0
30 14 handles => {
31 add_line_station => 'push',
32 find_line_station => 'first',
33 all_line_stations => 'elements',
34 }
35 );
36 14 has routes => (
37 is => 'ro',
38 isa => ArrayRef[ Route ],
39 traits => ['Array'],
40 handles => {
41 get_route => 'get',
42 add_route => 'push',
43 all_routes => 'elements',
44 sort_routes => 'sort',
45 route_count => 'count',
46 find_route => 'first',
47 },
48 );
49  
50 0 ▶around add_line_station => sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
51 0 my $next = shift;
52 0 my $self = shift;
53 0 my $ls = shift; # LineStation
54  
55 0 ▶ my $exists = $self->find_line_station(sub { $ls->line_station_id == $_->line_station_id });
Subroutine __ANON__: not called CC=1 SCAR=6.9
56 0 ▶ return if $exists;
Branch: 1 branch
BranchTrueFalseTotal
if $exists 0 0 0
57 0 $self->$next($ls);
58 14 };
59  
60 0 ▶sub ordered_routes {
Subroutine ordered_routes: not called CC=1 SCAR=6.9
Pod undocumented
61 0 my $self = shift;
62  
63 0 ▶ $self->sort_routes(sub { $_[0]->weight <=> $_[1]->weight });
Subroutine __ANON__: not called CC=1 SCAR=6.9
64 }
65  
66 1 ▶sub to_hash {
Subroutine to_hash: called CC=1 SCAR=0.2
Pod undocumented
67 1 my $self = shift;
68  
69 return {
70 origin_station => $self->origin_station->to_hash,
71 destination_station => $self->destination_station->to_hash,
72 line_stations => [
73 0 map { $_->to_hash } $self->all_line_stations,
74 ],
75 routes => [
76 1 map { $_->to_hash } $self->all_routes,
77 ],
78 };
79 }
80  
81 14 __PACKAGE__->meta->make_immutable;
82  
83 14 1;
84  
85 __END__
« Metro/Emitter.pm ↑ Summary Metro/Graph/Route.pm »