use strict; use warnings; use Geo::Gpx; use Test::More; BEGIN { eval "use Geo::Cache"; plan skip_all => 'Geo::Cache not available' if $@; eval "use Test::XML"; plan skip_all => 'Test::XML not available' if $@; } plan tests => 1; # Get expected output from previous version my $xml; { local $/; $xml = ; } $xml = normalise( $xml ); my @pts = ( new Geo::Cache( lat => 45.460366651, lon => -75.767939974, ele => 33.700000, name => 'WP0001', cmt => 'WP0001', desc => 'WP0001', fix => '2d', sat => 3, pdop => 30.600000, ), new Geo::Cache( lat => 45.460339984, lon => -75.767591640, ele => 33.700000, name => 'WP0002', cmt => 'WP0002', desc => 'WP0002', fix => '2d', sat => 3, pdop => 30.600000, ), new Geo::Cache( lat => 45.458376651, lon => -75.768483307, ele => 105.400000, name => 'WP0003', cmt => 'WP0003', desc => 'WP0003', fix => 'dgps', sat => 7, pdop => 1.400000, ) ); my $gpx = Geo::Gpx->new( @pts ); my $gxml = $gpx->xml(); $gxml = normalise( $gxml ); is_xml( $gxml, $xml, 'same output as previous version' ); # if ($gxml ne $xml) { # save('orig.gpx', $xml); # save('gen.gpx', $gxml); # } sub normalise { my $xml = shift; # Remove leading spaces in case we decide to indent the output $xml =~ s{^\s+}{}msg; my $fix_time = sub { my $tm = shift; $tm =~ s{\d}{9}g; $tm =~ s{[+-]}{-}g; return $tm; }; $xml =~ s{()}{$1 . $fix_time->($2) . $3}eg; my $fix_coord = sub { my $co = shift; return sprintf( "%.6f", $co ); }; $xml =~ s{((?:lat|lon)=\")([^\"]+)(\")}{$1 . $fix_coord->($2) . $3}eg; $xml =~ s{}{}g; return $xml; } sub save { my ( $name, $xml ) = @_; open( my $fh, '>', $name ) or die "Can't write $name ($!)\n"; print $fh $xml; close( $fh ); } __DATA__ GPX file generated by Geo::Gpx Groundspeak contact@groundspeak.com cache, geocache, groundspeak WP0001 WP0001 http://drbacchus.com/ Geo::Cache box WP0001 Traditional Cache Regular 1 1 United States Kentucky WP0001 Geo::Cache WP0002 WP0002 http://drbacchus.com/ Geo::Cache box WP0002 Traditional Cache Regular 1 1 United States Kentucky WP0002 Geo::Cache WP0003 WP0003 http://drbacchus.com/ Geo::Cache box WP0003 Traditional Cache Regular 1 1 United States Kentucky WP0003 Geo::Cache