Move setup into function where it is required
This commit is contained in:
parent
e88e59231f
commit
b754308a90
|
@ -8,11 +8,8 @@ use warnings;
|
||||||
use LWP::UserAgent;
|
use LWP::UserAgent;
|
||||||
use JSON::XS;
|
use JSON::XS;
|
||||||
|
|
||||||
my $ua = LWP::UserAgent->new();
|
|
||||||
my $json = JSON::XS->new();
|
|
||||||
my $location = "https://papillon.john.me.tz/data/location.json";
|
my $location = "https://papillon.john.me.tz/data/location.json";
|
||||||
|
my $lat_lon = fetch_lat_lon($location);
|
||||||
my $lat_lon = fetch_lat_lon($ua, $json, $location);
|
|
||||||
|
|
||||||
my $pid = fork;
|
my $pid = fork;
|
||||||
unless ($pid) {
|
unless ($pid) {
|
||||||
|
@ -25,10 +22,15 @@ unless ($pid) {
|
||||||
|
|
||||||
sub fetch_lat_lon
|
sub fetch_lat_lon
|
||||||
{
|
{
|
||||||
my ($ua, $json, $location) = @_;
|
my ($location) = shift;
|
||||||
|
|
||||||
|
my $ua = LWP::UserAgent->new();
|
||||||
|
my $json = JSON::XS->new();
|
||||||
|
|
||||||
my $raw = $ua->get($location)->content();
|
my $raw = $ua->get($location)->content();
|
||||||
|
|
||||||
if (defined $raw) {
|
if (defined $raw) {
|
||||||
|
print($raw."\n");
|
||||||
my $decoded = $json->decode($raw);
|
my $decoded = $json->decode($raw);
|
||||||
if (defined $decoded->{lat} && defined $decoded->{lon}) {
|
if (defined $decoded->{lat} && defined $decoded->{lon}) {
|
||||||
return "$decoded->{lat}:$decoded->{lon}";
|
return "$decoded->{lat}:$decoded->{lon}";
|
||||||
|
|
Loading…
Reference in New Issue