Metro.pm

filter: Statementstmt 70.5% 55 / 78 Branchbran 31.2% 5 / 16 Conditioncond 33.3% 2 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 80.0% 16 / 20 Podpod 50.0% 2 / 4 totaltotal 62.5% 80 / 128 CC 11 SCAR 16.0
CC
11
Cov
62%
__ANON__
13.8
decamelize
6.0
parse
6.0
CRAP 5.0
« Metro/Graph/Station.pm ↑ Summary Metro/Graph/Connection.pm »
1 11 ▶use 5.10.0;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 11 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 11 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 package Map::Metro;
6  
7 # ABSTRACT: Public transport graphing
8 11 our $AUTHORITY = 'cpan:CSSON'; # AUTHORITY
9 11 our $VERSION = '0.2405';
10  
11 11 ▶use Map::Metro::Elk;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 11 ▶use Module::Pluggable search_path => ['Map::Metro::Plugin::Map'], require => 1, sub_name => 'system_maps';
Subroutine BEGIN: called CC=1 SCAR=0.0
13 11 ▶use Types::Standard qw/ArrayRef Str/;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 11 ▶use Try::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 11 ▶use List::Util qw/any/;
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 11 ▶use Map::Metro::Graph;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 11 ▶use Map::Metro::Exceptions;
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20 11 has map => (
21 is => 'ro',
22 traits => ['Array'],
23 isa => ArrayRef,
24 predicate => 1,
25 handles => {
26 get_map => 'get',
27 },
28 );
29 has mapclasses => (
30 is => 'ro',
31 traits => ['Array'],
32 isa => ArrayRef,
33 1 ▶ default => sub { [] },
Subroutine __ANON__: called CC=1 SCAR=0.0
34 11 handles => {
35 add_mapclass => 'push',
36 get_mapclass => 'get',
37 },
38 );
39 has hooks => (
40 is => 'ro',
41 isa => ArrayRef[ Str ],
42 traits => ['Array'],
43 1 ▶ default => sub { [] },
Subroutine __ANON__: called CC=1 SCAR=0.0
44 11 handles => {
45 all_hooks => 'elements',
46 hook_count => 'count',
47 },
48 );
49 11 has _plugin_ns => (
50 is => 'ro',
51 isa => Str,
52 default => 'Plugin::Map',
53 init_arg => undef,
54 );
55  
56 1 ▶around BUILDARGS => sub {
Subroutine __ANON__: called CC=7 SCAR=26.3
57 1 my ($orig, $class, @args) = @_;
58 1 my %args;
59 1 ▶ if(scalar @args == 1) {
Branch: 2 branches
BranchTrueFalseTotal
if (scalar @args == 1) { } 1 0 1
elsif (scalar @args % 2 != 0) { } 0 0 0
60 1 $args{'map'} = shift @args;
61 }
62 elsif(scalar @args % 2 != 0) {
63 0 my $map = shift @args;
64 0 %args = @args;
65 0 $args{'map'} = $map;
66 }
67 else {
68 0 %args = @args;
69 }
70  
71 1 ▶ if(exists $args{'map'} && !ArrayRef->check($args{'map'})) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $args{"map"} and not &ArrayRef()->check($args{"map"})) 1 0 1
Condition33%1/3
exists $args{"map"} and not &ArrayRef()->check($args{"map"})
!ll&&!rl&&r
001
MC/DC0%0/2
exists $args{"map"} and not &ArrayRef()->check($args{"map"})
exists $args{"map"} not &ArrayRef()->check($args{"map"})
Truth table33%1/3
A and not(B)
A= exists $args{"map"}B= not &ArrayRef()->check($args{"map"})
ABresult
0X0
100
111
72 1 $args{'map'} = [$args{'map'}];
73 }
74 1 ▶ if(exists $args{'hooks'} && !ArrayRef->check($args{'hooks'})) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $args{"hooks"} and not &ArrayRef()->check($args{"hooks"})) 0 1 1
Condition33%1/3
exists $args{"hooks"} and not &ArrayRef()->check($args{"hooks"})
!ll&&!rl&&r
100
MC/DC0%0/2
exists $args{"hooks"} and not &ArrayRef()->check($args{"hooks"})
exists $args{"hooks"} not &ArrayRef()->check($args{"hooks"})
Truth table33%1/3
A and not(B)
A= exists $args{"hooks"}B= not &ArrayRef()->check($args{"hooks"})
ABresult
0X0
100
111
75 0 $args{'hooks'} = [$args{'hooks'}];
76 }
77  
78 1 return $class->$orig(%args);
79 11 };
80  
81 1 ▶sub BUILD {
Subroutine BUILD: called CC=3 SCAR=13.3
Pod undocumented
82 1 my $self = shift;
83 1 my @args = @_;
84  
85 1 ▶ if($self->has_map) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->has_map) 1 0 1
86 0 my @system_maps = map { s{^Map::Metro::Plugin::Map::}{}; $_ } $self->system_maps;
87 0 ▶ if(any { $_ eq $self->get_map(0) } @system_maps) {
Subroutine __ANON__: not called CC=1 SCAR=1.2
Branch: 1 branch
BranchTrueFalseTotal
if (&any(sub { $_ eq $self->get_map(0); } , @system_maps)) { } 0 1 1
88 0 my $mapclass = 'Map::Metro::Plugin::Map::'.$self->get_map(0);
89 0 my $mapobj = $mapclass->new(hooks => $self->hooks);
90 0 $self->add_mapclass($mapobj);
91 }
92 else {
93 1 ▶ try { die no_such_map mapname => $self->get_map(0) } catch { die $_->desc };
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
94 }
95 }
96 }
97  
98 # Borrowed from Mojo::Util
99 0 ▶sub decamelize {
Subroutine decamelize: not called CC=2 SCAR=17.9
Pod undocumented
100 0 my $self = shift;
101 0 my $string = shift;
102  
103 0 ▶ return $string if $string !~ m{[A-Z]};
Branch: 1 branch
BranchTrueFalseTotal
unless $string =~ /[A-Z]/ 0 0 0
104 return join '_' => map {
105 0 join ('_' => map { lc } grep { length } split m{([A-Z]{1}[^A-Z]*)})
106 } split '::' => $string;
107 }
108  
109 0 ▶sub parse {
Subroutine parse: not called CC=2 SCAR=17.9
Pod documented
110 0 my $self = shift;
111 0 my %args = @_;
112  
113 return Map::Metro::Graph->new(filepath => $self->get_mapclass(0)->maplocation,
114 do_undiacritic => $self->get_mapclass(0)->do_undiacritic,
115 wanted_hook_plugins => [$self->all_hooks],
116 0 ▶ exists $args{'override_line_change_weight'} ? (override_line_change_weight => $args{'override_line_change_weight'}) : (),
Branch: 1 branch
BranchTrueFalseTotal
exists $args{'override_line_change_weight'} ? : 0 0 0
117 )->parse;
118 }
119  
120 0 ▶sub available_maps {
Subroutine available_maps: not called CC=1 SCAR=6.9
Pod documented
121 0 my $self = shift;
122 0 return sort $self->system_maps;
123 }
124  
125 11 1;
126  
127 __END__
« Metro/Graph/Station.pm ↑ Summary Metro/Graph/Connection.pm »