testing #29

Merged
marko merged 73 commits from testing into main 2023-01-07 12:49:01 +00:00
Showing only changes of commit c600937332 - Show all commits

View File

@ -23,14 +23,11 @@ eval {
require JSON::MaybeXS;
import JSON::MaybeXS qw( decode_json encode_json );
1;
};
if ($@) {
$@ = undef;
} or do {
# try to use JSON wrapper
# for chance of better performance
eval {
# JSON preference order
local $ENV{PERL_JSON_BACKEND} =
'Cpanel::JSON::XS,JSON::XS,JSON::PP,JSON::backportPP'
@ -39,10 +36,7 @@ if ($@) {
require JSON;
import JSON qw( decode_json encode_json );
1;
};
if ($@) {
$@ = undef;
} or do {
# In rare cases, Cpanel::JSON::XS may
# be installed but JSON|JSON::MaybeXS not ...
@ -50,10 +44,7 @@ if ($@) {
require Cpanel::JSON::XS;
import Cpanel::JSON::XS qw(decode_json encode_json);
1;
};
if ($@) {
$@ = undef;
} or do {
# In rare cases, JSON::XS may
# be installed but JSON not ...
@ -61,10 +52,7 @@ if ($@) {
require JSON::XS;
import JSON::XS qw(decode_json encode_json);
1;
};
if ($@) {
$@ = undef;
} or do {
# Fallback to built-in JSON which SHOULD
# be available since 5.014 ...
@ -72,20 +60,17 @@ if ($@) {
require JSON::PP;
import JSON::PP qw(decode_json encode_json);
1;
};
if ($@) {
$@ = undef;
} or do {
# Fallback to JSON::backportPP in really rare cases
require JSON::backportPP;
import JSON::backportPP qw(decode_json encode_json);
1;
}
}
}
}
}
};
};
};
};
};
use Data::Dumper; # for Debug only
## API URL
@ -109,6 +94,8 @@ sub new {
lat => ( split( ',', $argsRef->{location} ) )[0],
long => ( split( ',', $argsRef->{location} ) )[1],
fetchTime => 0,
forecast => $argsRef->{forecast},
alerts => $argsRef->{alerts},
};
$self->{cachemaxage} = (
@ -181,6 +168,22 @@ sub setLocation {
return 0;
}
sub setAlerts {
my $self = shift;
my $alerts = shift // 0;
$self->{alerts} = $alerts;
return;
}
sub setForecast {
my $self = shift;
my $forecast = shift // '';
$self->{forecast} = $forecast;
return;
}
sub getFetchTime {
my $self = shift;
@ -199,8 +202,7 @@ sub _RetrieveDataFromWU($) {
# retrieve data from cache
if ( ( time() - $self->{fetchTime} ) < $self->{cachemaxage}
and $self->{cached}->{lat} == $self->{lat}
and $self->{cached}->{long} == $self->{long}
)
and $self->{cached}->{long} == $self->{long} )
{
return _CallWeatherCallbackFn($self);
}
@ -239,6 +241,7 @@ sub _RetrieveDataFromWU($) {
my $options = 'geocode=' . $self->{lat} . ',' . $self->{long};
$options .= '&format=json';
$options .= '&units=' . $self->{units};
$options .= '&numericPrecision=decimal';
$options .= '&language='
. (
$self->{lang} eq 'en'