Routing/Role/Route.pm

filter: Statementstmt 81.8% 9 / 11 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 5 / 5 Podpod n/a totaltotal 87.5% 14 / 16 CC 1 SCAR 0.6
CC
1
Cov
82%
BEGIN
1.3
BEGIN
1.0
BEGIN
1.0
CRAP 1.1
« Routing/Role/Driver.pm ↑ Summary Routing/Driver/OSRM.pm »
1 package Geo::Routing::Role::Route;
2 5 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
3 5 $Geo::Routing::Role::Route::AUTHORITY = 'cpan:AVAR';
4 }
5 5 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
6 5 $Geo::Routing::Role::Route::VERSION = '0.11';
7 }
8 5 ▶use Any::Moose '::Role';
Subroutine BEGIN: called CC=1 SCAR=0.0
9 5 ▶use warnings FATAL => "all";
Subroutine BEGIN: called CC=1 SCAR=0.0
10 0 ▶use Geo::Distance::XS;
Subroutine BEGIN: called CC=1 SCAR=2.6
11 use namespace::clean -except => "meta";
12  
13 has points => (
14 is => 'ro',
15 isa => 'ArrayRef[ArrayRef[Num|Undef|Str]]',
16 required => 1,
17 documentation => '',
18 );
19  
20 has distance => (
21 is => 'ro',
22 isa => 'Num',
23 documentation => '',
24 lazy_build => 1,
25 );
26  
27 sub _build_distance {
28 my ($self) = @_;
29  
30 my $points = $self->points;
31 my $distance = 0;
32  
33 my $geo = Geo::Distance->new;
34  
35 for (my $i = 1; $i < @$points; $i++) {
36 my $prev_point = $points->[$i - 1];
37 my $curr_point = $points->[$i];
38 my ($lon1, $lat1) = @$prev_point;
39 my ($lon2, $lat2) = @$curr_point;
40  
41 my $prev_to_curr_distance = $geo->distance(
42 kilometer => $lon1, $lat1, $lon2, $lat2,
43 );
44  
45 $distance += $prev_to_curr_distance;
46 }
47  
48 return $distance;
49 }
50  
51 has travel_time => (
52 is => 'ro',
53 isa => 'Int',
54 documentation => '',
55 lazy_build => 1,
56 );
57  
58 requires '_build_travel_time';
59  
60 1;
« Routing/Role/Driver.pm ↑ Summary Routing/Driver/OSRM.pm »