blib/script/tcx_interactive.pl untested

filter: Statementstmt 0.0% 0 / 37 Branchbran 0.0% 0 / 20 Conditioncond 0.0% 0 / 13 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 6 Podpod 0.0% 0 / 1 totaltotal 0.0% 0 / 77 CC 1 SCAR 6.9
CC
1
Cov
0%
usage
2.0
BEGIN
2.0
BEGIN
2.0
CRAP 2.0
1 #!/usr/bin/env perl
2 use strict;
3 use warnings;
4  
5 our $VERSION = '1.04';
6  
7 =encoding utf-8
8  
9 =head1 NAME
10  
11 tcx_interactive.pl - Script to use the L<Geo::TCX> module interactively from the command line or in the perl debugger
12  
13 =head1 SYNOPSIS
14  
15 tcx_interactive.pl --help
16 tcx_interactive.pl --src_dir=dir [ --help --recent=# --wrk_dir=dir --wpt_dir=dir --dev_dir=dir --tolerance_meters=# ]
17  
18 =head1 DESCRIPTION
19  
20 C<tcx_interactive.pl> is a utility script that is mostly useful after having saved an activity from a GPS training device onto a computer.
21  
22 The script looks up recently saved TCX or FIT files in the path specified by C<--src_dir> and prompts the user for one to parse. It reads the selected file, intiates a L<Geo::TCX::Interactive> instance, and prompts the user for commonly used methods such as C<save_laps()> among other.
23  
24 The user is subsequently prompted whether they wish to read recently saved waypoints from their GPS device (provided it is currently plugged in via USB cable), save these points in a *.gpx waypoints file located in C<--wpt_dir>, and whether they wish to add the end points of each lap to that waypoints file.
25  
26 The user can also transfer the resulting waypoints file back to their device for use during their next activity (not yet enabled, coming soon).
27  
28 =cut
29  
30 use Geo::Gpx;
31 use Geo::TCX::Interactive;
32 use Getopt::Long;
33  
34 my ( $recent, $tolerance_meters, $src_dir, $wrk_dir, $wpt_dir, $dev_dir, $chdir, $help ) = (25, 10);
35 sub usage { "Usage: $0 --src_dir=dir [ --help --tolerance=# --recent=# --wrk_dir=dir --wpt_dir=dir --dev_dir=dir ]\n" }
36 GetOptions( "recent=i" => \$recent,
37 "src_dir=s" => \$src_dir,
38 "wrk_dir=s" => \$wrk_dir,
39 "wpt_dir=s" => \$wpt_dir,
40 "dev_dir=s" => \$dev_dir,
41 "chdir=s" => \$chdir,
42 "help" => \$help,
43 "tolerance_meters=i" => \$tolerance_meters,
44 ) or die usage();
45 die usage() if $help;
46  
47 # check that any specified *_dir exist. $src_dir will be checked by new()
48 # $chdir is undocumented and provided for debugging purposes
49 $src_dir =~ s/^\s*~/$ENV{HOME}/ if defined $src_dir;
50 $wrk_dir =~ s/^\s*~/$ENV{HOME}/ if defined $wrk_dir;
51 $wpt_dir =~ s/^\s*~/$ENV{HOME}/ if defined $wpt_dir;
52 $dev_dir =~ s/^\s*~/$ENV{HOME}/ if defined $dev_dir;
53 die "--wrk_dir: directory specified does not exists" if defined $wrk_dir and ! -d $wrk_dir;
54 die "--wpt_dir: directory specified does not exists" if defined $wpt_dir and ! -d $wpt_dir;
55 die "--dev_dir: directory specified does not exists" if defined $dev_dir and ! -d $dev_dir;
56 if ($chdir) { chdir $chdir or die "can't chdir to $chdir: $!" }
57  
58 =head2 Options
59  
60 =over 4
61  
62 =item C<< --recent => # >>
63  
64 specifies the number of recent files to look up in C<--src_dir>. The default is 25.
65  
66 =item C<< --src_dir=I<$dir> >>
67  
68 the directory where TCX or FIT files are located.
69  
70 =item C<< --wrk_dir=I<$dir> >>
71  
72 the directory where working files are to be saved, such as with the C<save_laps()> method.
73  
74 =item C<< --wpt_dir=I<$dir> >>
75  
76 If this option is specified, the script will attempt to load a waypoints file from the user's computer into the L<Geo::TCX::Interactive> instance. This option is used by a call to C<< gpx_load() >> which prompts the user to select a I<*.gpx> file from all such files found in I<$dir>.
77  
78 The script will later prompt the user whether they wish to add other waypoints saved on the GPS device and also whether to add the begining and end position of each of the activity's laps parsed by the instance to the I<*.gpx> file.
79  
80 =item C<< --dev_dir=I<$dir> >>
81  
82 the directory on the GPS device where the waypoints are stored. On recent devices, this tends to be a C<Locations> folder and older devices it is sometimes named C<GPX/current>.
83  
84 If C<< way_add_device() >> is called and I<$dir> is not specified, the method will search where this directory might be (provided the GPS device is plugged in).
85  
86 =item C<< --tolerance_meters => # >>
87  
88 the distance below which waypoints at the beginning or end of a lap are to be ignored when comparing with the waypoints file read in the instance. The default is 10 meters.
89  
90 This option is only relevant for C<< way_add_endpoints() >>. It is not considered by C<< way_add_device() >> under the assumption that if a user marked a particular location manually on their device, it has some degree of importance and should not be overlooked.
91  
92 =back
93  
94 =cut
95  
96 my $o= Geo::TCX::Interactive->new( $src_dir, recent => $recent, work_dir => $wrk_dir );
97 $o->prompt_and_set_wd;
98 # $o->lap_summary($_) for ( 1 .. $o->laps );
99 $o->save_laps();
100  
101 if ($wpt_dir) {
102 my $gpx = $o->gpx_load( $wpt_dir );
103 $o->way_add_device( $dev_dir );
104 $o->way_add_endpoints( tolerance_meters => $tolerance_meters );
105 $o->gpx_save();
106 }
107  
108 =head1 DEPENDENCIES
109  
110 This script is part of the L<Geo::TCX> module and relies on the L<Geo::TCX::Interactive> sub-class it provides.
111  
112 L<Geo::FIT> is also required to parse FIT files and to add waypoints from a GPS device (except for some older models).
113  
114 =head1 SEE ALSO
115  
116 L<Geo::TCX::Interactive>, L<Geo::Gpx>, L<Geo::FIT>.
117  
118 =head1 AUTHOR
119  
120 Patrick Joly C<< <patjol@cpan.org> >>.
121  
122 =head1 VERSION
123  
124 1.04
125  
126 =head1 LICENSE AND COPYRIGHT
127  
128 Copyright 2022, Patrick Joly C<< patjol@cpan.org >>. All rights reserved.
129  
130 This script is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See L<perlartistic>.
131  
132 =head1 DISCLAIMER OF WARRANTY
133  
134 BECAUSE THIS SOFTWARE IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE SOFTWARE, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE SOFTWARE "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE SOFTWARE IS WITH YOU. SHOULD THE SOFTWARE PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR, OR CORRECTION.
135  
136 IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE SOFTWARE AS PERMITTED BY THE ABOVE LICENSE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE SOFTWARE (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE SOFTWARE TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
137  
138 =cut
139  
140 1;