| 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
Condition100%3/3
defined $val and not $val->isa("DateTime")
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")
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 38 | 6 | ▶ | unless($other->isa("GPS::Track::Point")) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 55 | 6 | ▶ | die "\$other is missing a 'lat' value!" unless(defined $otherLat); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||||||||||
| 57 | 4 | ▶ | die "\$self is missing a 'lon' value!" unless(defined $self->lon); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 58 | 3 | ▶ | die "\$self is missing a 'lat' value!" unless(defined $self->lat); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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
Condition66%2/3
builtin::blessed($other) and $other->isa("GPS::Track::Point")
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")
| |||||||||||||||||||||||||||||||||||||||||||
| 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
MC/DC100%2/2
defined $me && defined $other
defined $me
defined $other
Truth table100%3/3
A && B
A= defined $meB= defined $other
| |||||||||||||||||||||||||||||||||||||||||||
| 78 | 32 | my $onlyOneDefined = defined($me) ^ defined($other); | |||||||||||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||||||||||||
| 80 | 32 | ▶ | if($onlyOneDefined || ($bothDefined && $me != $other)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
$onlyOneDefined or $bothDefined and $me != $other
$bothDefined and $me != $other
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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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__ | ||||||||||||||||||||||||||||||||||||||||||