From 88ea55724668ccb239bb3381126728f3fe166d93 Mon Sep 17 00:00:00 2001 From: John Mertz Date: Tue, 27 Jul 2021 01:25:41 -0400 Subject: [PATCH] Move setup into function where it is required --- sway/gammastep.pl | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/sway/gammastep.pl b/sway/gammastep.pl index cc252c5..61e791f 100755 --- a/sway/gammastep.pl +++ b/sway/gammastep.pl @@ -8,11 +8,8 @@ use warnings; use LWP::UserAgent; use JSON::XS; -my $ua = LWP::UserAgent->new(); -my $json = JSON::XS->new(); my $location = "https://papillon.john.me.tz/data/location.json"; - -my $lat_lon = fetch_lat_lon($ua, $json, $location); +my $lat_lon = fetch_lat_lon($location); my $pid = fork; unless ($pid) { @@ -25,10 +22,15 @@ unless ($pid) { 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(); + if (defined $raw) { + print($raw."\n"); my $decoded = $json->decode($raw); if (defined $decoded->{lat} && defined $decoded->{lon}) { return "$decoded->{lat}:$decoded->{lon}";