|
|
@ -7,17 +7,42 @@ use warnings; |
|
|
|
use XML::LibXML; |
|
|
|
use XML::LibXML; |
|
|
|
use URI::Escape; |
|
|
|
use URI::Escape; |
|
|
|
|
|
|
|
|
|
|
|
my ($name, $coordinates) = @ARGV; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
my $filename = 'ours.kml'; |
|
|
|
my $filename = 'ours.kml'; |
|
|
|
my $dom = XML::LibXML->load_xml(location => $filename, no_blanks => 1); |
|
|
|
my $dom = XML::LibXML->load_xml(location => $filename, no_blanks => 1); |
|
|
|
my $xpc = XML::LibXML::XPathContext->new($dom); |
|
|
|
my $xpc = XML::LibXML::XPathContext->new($dom); |
|
|
|
$xpc->registerNs('k', "http://earth.google.com/kml/2.2"); |
|
|
|
$xpc->registerNs('k', "http://earth.google.com/kml/2.2"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
my $mode = shift; |
|
|
|
|
|
|
|
if ($mode eq 'add') |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
my ($name, $coordinates) = @ARGV; |
|
|
|
|
|
|
|
unless (defined($name) && defined($coordinates)) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
say "Not enough args for add operation"; |
|
|
|
|
|
|
|
USAGE(1); |
|
|
|
|
|
|
|
} |
|
|
|
append_placemark($name, $coordinates, uri_escape($name)); |
|
|
|
append_placemark($name, $coordinates, uri_escape($name)); |
|
|
|
|
|
|
|
|
|
|
|
print $dom->toString(1); |
|
|
|
print $dom->toString(1); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
elsif ($mode eq 'remove') |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
say "Remove mode"; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
elsif ($mode eq 'set') |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
say "Set mode"; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
USAGE(1); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
sub USAGE |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
my $code = shift; |
|
|
|
|
|
|
|
say "USAGE: "; |
|
|
|
|
|
|
|
exit($code); |
|
|
|
|
|
|
|
} |
|
|
|
sub add_empty_child |
|
|
|
sub add_empty_child |
|
|
|
{ |
|
|
|
{ |
|
|
|
my $node = shift; |
|
|
|
my $node = shift; |
|
|
|