| 1 | package GPS::Track; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use 5.018000; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | 1 | ▶ | use Moo; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | 1 | ▶ | use GPS::Track::Point; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | 1 | ▶ | use XML::Simple; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | 1 | ▶ | use Try::Tiny; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||
| 11 | 1 | our $VERSION = '0.02'; | |||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||
| 13 | has "onPoint" => ( | ||||||||||||||||||||||||||||||||||||||||||
| 14 | is => "rw", | ||||||||||||||||||||||||||||||||||||||||||
| 15 | 8 | ▶ | isa => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 16 | 8 | GPS::Track::_validateOnPoint(shift); | |||||||||||||||||||||||||||||||||||||||||
| 17 | } | ||||||||||||||||||||||||||||||||||||||||||
| 18 | 1 | ); | |||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||
| 20 | 4 | ▶ | sub BUILD { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BUILD: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 21 | 4 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 22 | 4 | my $args = shift; | |||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||
| 24 | 4 | ▶ | if(exists $args->{onPoint}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 25 | 1 | GPS::Track::_validateOnPoint($args->{onPoint}); | |||||||||||||||||||||||||||||||||||||||||
| 26 | } | ||||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||
| 28 | 4 | return $args; | |||||||||||||||||||||||||||||||||||||||||
| 29 | } | ||||||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||||||
| 31 | 9 | ▶ | sub _validateOnPoint { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_validateOnPoint: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||
| 32 | 9 | my $candidate = shift; | |||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||
| 34 | 9 | ▶ | if(defined($candidate) && ref($candidate) ne "CODE") { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $candidate and ref $candidate ne "CODE"
MC/DC100%2/2
defined $candidate and ref $candidate ne "CODE"
defined $candidate
ref $candidate ne "CODE"
Truth table100%3/3
A and B
A= defined $candidateB= ref $candidate ne "CODE"
| |||||||||||||||||||||||||||||||||||||||||||
| 35 | 5 | die "Not a CODE-Ref to onPoint!" | |||||||||||||||||||||||||||||||||||||||||
| 36 | } | ||||||||||||||||||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||||||||||
| 40 | 0 | ▶ | sub parse { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
parse: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 41 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 42 | 0 | my $file = shift; | |||||||||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||||||||
| 44 | 0 | my $tcx = $self->convert($file); | |||||||||||||||||||||||||||||||||||||||||
| 45 | 0 | return $self->parseTCX($tcx); | |||||||||||||||||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||||||||||
| 48 | 0 | ▶ | sub convert { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
convert: not called CC=6 SCAR=37.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 49 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||||||||||
| 51 | 0 | ▶ | my $file = shift or die "No file supplied to parse!"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 52 | 0 | ▶ | die "The file '$file' does not exist!" unless(-e $file); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||||||||||
| 54 | # identify dies on unknown formats! | ||||||||||||||||||||||||||||||||||||||||||
| 55 | 0 | my $format = $self->identify($file); | |||||||||||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||||||||||
| 57 | 0 | my $xml = undef; | |||||||||||||||||||||||||||||||||||||||||
| 58 | 0 | ▶ | if($format eq "gpx") { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 59 | 0 | $xml = $self->_convertGPX($file); | |||||||||||||||||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||||||||||||||||
| 61 | elsif($format eq "fit") { | ||||||||||||||||||||||||||||||||||||||||||
| 62 | 0 | $xml = $self->_convertFIT($file); | |||||||||||||||||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||||||||||||||||
| 64 | elsif($format eq "tcx") { | ||||||||||||||||||||||||||||||||||||||||||
| 65 | 0 | $xml = $self->_convertTCX($file); | |||||||||||||||||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||||||||||
| 68 | 0 | return $xml; | |||||||||||||||||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||||||
| 71 | 0 | ▶ | sub parseTCX { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
parseTCX: not called CC=8 SCAR=42.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 72 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 73 | 0 | my $xml = shift; | |||||||||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||||||||||
| 75 | # use a faster parser | ||||||||||||||||||||||||||||||||||||||||||
| 76 | 0 | local $XML::Simple::PREFERRED_PARSER = "XML::SAX::ExpatXS"; | |||||||||||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||||||||||
| 78 | 0 | my @options = ( ForceArray => ['Course', 'Trackpoint'] ); | |||||||||||||||||||||||||||||||||||||||||
| 79 | 0 | my $data = XMLin($xml, @options); | |||||||||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||||||||||
| 81 | 0 | my @courses = @{$data->{Courses}->{Course}}; | |||||||||||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||||||||||
| 83 | 0 | my @retval; | |||||||||||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||||||||||||
| 85 | 0 | foreach my $course (@courses) { | |||||||||||||||||||||||||||||||||||||||||
| 86 | 0 | my @trackpoints = @{$course->{Track}->{Trackpoint}}; | |||||||||||||||||||||||||||||||||||||||||
| 87 | 0 | foreach my $p (@trackpoints) { | |||||||||||||||||||||||||||||||||||||||||
| 88 | # Parse the ISO8601 DateTime | ||||||||||||||||||||||||||||||||||||||||||
| 89 | 0 | my $time = undef; | |||||||||||||||||||||||||||||||||||||||||
| 90 | 0 | ▶ | try { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 91 | 0 | $time = DateTime::Format::ISO8601->parse_datetime($p->{Time}); | |||||||||||||||||||||||||||||||||||||||||
| 92 | 0 | }; | |||||||||||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||||||||||||
| 94 | my $gpsTrackPoint = GPS::Track::Point->new( | ||||||||||||||||||||||||||||||||||||||||||
| 95 | lat => $p->{Position}->{LatitudeDegrees}, | ||||||||||||||||||||||||||||||||||||||||||
| 96 | lon => $p->{Position}->{LongitudeDegrees}, | ||||||||||||||||||||||||||||||||||||||||||
| 97 | time => $time, | ||||||||||||||||||||||||||||||||||||||||||
| 98 | ele => $p->{AltitudeMeters} || undef, | ||||||||||||||||||||||||||||||||||||||||||
| 99 | spd => $p->{Extensions}->{TPX}->{Speed} || undef, | ||||||||||||||||||||||||||||||||||||||||||
| 100 | bpm => $p->{HeartRateBpm}->{Value} || undef, | ||||||||||||||||||||||||||||||||||||||||||
| 101 | cad => $p->{Cadence} || undef, | ||||||||||||||||||||||||||||||||||||||||||
| 102 | 0 | ▶ | ); | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/8
$p->{'AltitudeMeters'} || undef
$p->{'Extensions'}{'TPX'}{'Speed'} || undef
$p->{'HeartRateBpm'}{'Value'} || undef
$p->{'Cadence'} || undef
MC/DC0%0/1
$p->{'AltitudeMeters'} || undef
$p->{'AltitudeMeters'}
MC/DC0%0/1
$p->{'Extensions'}{'TPX'}{'Speed'} || undef
$p->{'Extensions'}{'TPX'}{'Speed'}
MC/DC0%0/1
$p->{'HeartRateBpm'}{'Value'} || undef
$p->{'HeartRateBpm'}{'Value'}
MC/DC0%0/1
$p->{'Cadence'} || undef
$p->{'Cadence'}
Truth table0%0/2
A
A= $p->{'AltitudeMeters'}
Truth table0%0/2
A
A= $p->{'Extensions'}{'TPX'}{'Speed'}
Truth table0%0/2
A
A= $p->{'HeartRateBpm'}{'Value'}
Truth table0%0/2
A
A= $p->{'Cadence'}
| |||||||||||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||||||||||
| 104 | # fire onPoint Callback | ||||||||||||||||||||||||||||||||||||||||||
| 105 | 0 | ▶ | $self->onPoint()->($gpsTrackPoint) if(defined($self->onPoint)); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||||||||||||
| 107 | # push back point | ||||||||||||||||||||||||||||||||||||||||||
| 108 | 0 | push(@retval, $gpsTrackPoint); | |||||||||||||||||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||||||||||||||
| 112 | 0 | return @retval; | |||||||||||||||||||||||||||||||||||||||||
| 113 | } | ||||||||||||||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||||||||||||
| 115 | 8 | ▶ | sub identify { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
identify: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 116 | 8 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 117 | 8 | my $filename = shift; | |||||||||||||||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||||||||||||||||
| 119 | 8 | my $suffix = ""; | |||||||||||||||||||||||||||||||||||||||||
| 120 | 8 | ▶ | if($filename =~ /\.(\w+)$/) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 121 | 6 | $suffix = lc($1); | |||||||||||||||||||||||||||||||||||||||||
| 122 | } | ||||||||||||||||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||||||||||||||||
| 124 | 8 | my %validSuffixes = ( | |||||||||||||||||||||||||||||||||||||||||
| 125 | gpx => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 126 | fit => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 127 | tcx => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 128 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||||||||||||||||
| 130 | 8 | ▶ | die "File '$filename' has an unknown dataformat!" unless(exists $validSuffixes{$suffix}); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||||||||||||||||
| 132 | 5 | return $suffix; | |||||||||||||||||||||||||||||||||||||||||
| 133 | } | ||||||||||||||||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||||||||||||||||
| 135 | 0 | ▶ | sub _convertFIT { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_convertFIT: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 136 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 137 | 0 | my $file = shift; | |||||||||||||||||||||||||||||||||||||||||
| 138 | 0 | $self->gpsbabel_convert("garmin_fit", $file); | |||||||||||||||||||||||||||||||||||||||||
| 139 | } | ||||||||||||||||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||||||||||||||||
| 141 | 0 | ▶ | sub _convertGPX { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_convertGPX: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 142 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 143 | 0 | my $file = shift; | |||||||||||||||||||||||||||||||||||||||||
| 144 | 0 | return $self->gpsbabel_convert("gpx", $file); | |||||||||||||||||||||||||||||||||||||||||
| 145 | } | ||||||||||||||||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||||||||||||||||
| 147 | 0 | ▶ | sub _convertTCX { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_convertTCX: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 148 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 149 | 0 | my $file = shift; | |||||||||||||||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||||||||||||||||
| 151 | 0 | $self->gpsbabel_convert("gtrnctr", $file); | |||||||||||||||||||||||||||||||||||||||||
| 152 | } | ||||||||||||||||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||||||||||||||||
| 154 | 0 | ▶ | sub gpsbabel_convert { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
gpsbabel_convert: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 155 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 156 | 0 | my $sourceFormat = quotemeta(shift); | |||||||||||||||||||||||||||||||||||||||||
| 157 | 0 | my $file = quotemeta(shift); | |||||||||||||||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||||||||||||||||
| 159 | 0 | my $tcx = `gpsbabel -i $sourceFormat -f $file -o gtrnctr -F -`; | |||||||||||||||||||||||||||||||||||||||||
| 160 | 0 | return $tcx; | |||||||||||||||||||||||||||||||||||||||||
| 161 | } | ||||||||||||||||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||||||||||||||||
| 163 | 1 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 164 | __END__ | ||||||||||||||||||||||||||||||||||||||||||