Track/Point.pm

filter: Statementstmt 100% 66 / 66 Branchbran 100% 24 / 24 Conditioncond 93.3% 14 / 15 MC/DCmcdc 88.8% 8 / 9 Subroutinesub 100% 12 / 12 Podpod 80.0% 4 / 5 totaltotal 97.7% 128 / 131 CC 21 SCAR 16.2
CC
21
Cov
99%
equals
8.0
distanceTo
8.0
__ANON__
3.0
CRAP 5.1
« Track.pm ↑ Summary
1 package GPS::Track::Point;
2  
3 2 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use Scalar::Util qw/blessed/;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use Geo::Distance;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 use overload
8 1 ▶ '!=' => sub { !shift->equals(shift) },
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
9 2 '==' => \=
10  
11 2 has ["lon", "lat", "ele", "spd", "bpm", "cad" ] => (
12 is => "rw",
13 default => undef
14 );
15  
16 has "time" => (
17 is => "rw",
18 default => undef,
19 16 ▶ isa => sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
20 16 my $val = shift;
21 16 ▶ die "Not a DateTime object!" if(defined($val) && !$val->isa("DateTime"));
Branch: 1 branch
BranchTrueFalseTotal
if defined $val and not $val->isa("DateTime") 1 15 16
Condition100%3/3
defined $val and not $val->isa("DateTime")
!ll&&!rl&&r
1411
MC/DC100%2/2
defined $val and not $val->isa("DateTime")
defined $val not $val->isa("DateTime")
Truth table100%3/3
A and not(B)
A= defined $valB= not $val->isa("DateTime")
ABresult
0X0
100
111
22 }
23 2 );
24  
25 has "geoDistance" => (
26 is => "ro",
27 13 ▶ default => sub { return Geo::Distance->new(); },
Subroutine __ANON__: called CC=1 SCAR=0.0
28 2 );
29  
30 10 ▶sub distanceTo {
Subroutine distanceTo: called CC=8 SCAR=20.8
Pod documented
31 10 my $self = shift;
32 10 my $other = shift;
33  
34 10 my $otherLon = undef;
35 10 my $otherLat = undef;
36  
37 10 ▶ if(blessed($other)) {
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::blessed($other)) { } 6 4 10
38 6 ▶ unless($other->isa("GPS::Track::Point")) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($other->isa("GPS::Track::Point")) 1 5 6
39 1 die "\$other is not a GPS::Track::Point!";
40 }
41  
42 5 $otherLon = $other->lon;
43 5 $otherLat = $other->lat;
44 }
45 else {
46 4 ▶ unless(ref($other) eq "HASH") {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $other eq "HASH") 1 3 4
47 1 die "\$other is not a HASH reference!";
48 }
49  
50 3 $otherLon = $other->{lon};
51 3 $otherLat = $other->{lat};
52 }
53  
54 8 ▶ die "\$other is missing a 'lon' value!" unless(defined $otherLon);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $otherLon 2 6 8
55 6 ▶ die "\$other is missing a 'lat' value!" unless(defined $otherLat);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $otherLat 2 4 6
56  
57 4 ▶ die "\$self is missing a 'lon' value!" unless(defined $self->lon);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->lon 1 3 4
58 3 ▶ die "\$self is missing a 'lat' value!" unless(defined $self->lat);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->lat 1 2 3
59  
60 2 return $self->geoDistance->distance("meter", $self->lon, $self->lat, $otherLon, $otherLat);
61 }
62  
63 9 ▶sub equals {
Subroutine equals: called CC=8 SCAR=20.8
Pod documented
64 9 my $self = shift;
65 9 my $other = shift;
66  
67 9 ▶ unless(blessed($other) && $other->isa("GPS::Track::Point")) {
Branch: 1 branch
BranchTrueFalseTotal
unless (builtin::blessed($other) and $other->isa("GPS::Track::Point")) 1 8 9
Condition66%2/3
builtin::blessed($other) and $other->isa("GPS::Track::Point")
!ll&&!rl&&r
108
MC/DC50%1/2
builtin::blessed($other) and $other->isa("GPS::Track::Point")
builtin::blessed($other) $other->isa("GPS::Track::Point")
Truth table66%2/3
A and B
A= builtin::blessed($other)B= $other->isa("GPS::Track::Point")
ABresult
0X0
100
111
68 1 die "First argument not a GPS::Track::Point!";
69 }
70  
71 8 my $equal = 1;
72  
73 8 foreach my $attr ($self->attributes) {
74 32 my $me = $self->$attr();
75 32 my $other = $other->$attr();
76  
77 32 ▶ my $bothDefined = defined($me) && defined($other);
Condition100%3/3
defined $me && defined $other
!ll&&!rl&&r
6125
MC/DC100%2/2
defined $me && defined $other
defined $me defined $other
Truth table100%3/3
A && B
A= defined $meB= defined $other
ABresult
0X0
100
111
78 32 my $onlyOneDefined = defined($me) ^ defined($other);
79  
80 32 ▶ if($onlyOneDefined || ($bothDefined && $me != $other)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($onlyOneDefined or $bothDefined and $me != $other) 4 28 32
Condition100%6/6
$onlyOneDefined or $bothDefined and $me != $other
l!l&&r!l&&!r
1328
$bothDefined and $me != $other
!ll&&!rl&&r
6223
MC/DC100%3/3
$onlyOneDefined or $bothDefined and $me != $other
$onlyOneDefined $bothDefined $me != $other
Truth table100%4/4
A or B and C
A= $onlyOneDefinedB= $bothDefinedC= $me != $other
ABCresult
1XX1
0111
00X0
0100
81 4 $equal = 0;
82 4 last;
83 }
84 }
85  
86 8 return $equal;
87 }
88 1 ▶sub toString {
Subroutine toString: called CC=3 SCAR=11.0
Pod documented
89 1 my $self = shift;
90 1 my @parts;
91 1 foreach my $attr ($self->attributes) {
92 7 my $value = $self->$attr();
93 7 ▶ push(@parts, "$attr=" . (defined($value) ? $value : "undef"));
Branch: 1 branch
BranchTrueFalseTotal
defined $value ? : 3 4 7
94 }
95  
96 1 return join(" ", @parts);
97 }
98 4 ▶sub toHash {
Subroutine toHash: called CC=3 SCAR=11.0
Pod documented
99 4 my $self = shift;
100 4 my $data = {};
101
102 4 foreach my $attr ($self->attributes) {
103 28 my $value = $self->$attr();
104 28 ▶ if(defined($value)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $value) 14 14 28
105 14 $data->{$attr} = $value;
106 }
107 }
108  
109 4 return $data;
110 }
111  
112 13 ▶sub attributes {
Subroutine attributes: called CC=1 SCAR=0.0
Pod undocumented
113 13 return qw/lon lat time ele spd cad bpm/;
114 }
115  
116 2 1;
117  
118 __END__
« Track.pm ↑ Summary