testing #29
| @@ -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} = ( | ||||
| @@ -173,7 +160,7 @@ sub setRetrieveData { | ||||
| } | ||||
|  | ||||
| sub setLocation { | ||||
|     my ($self,$lat,$long) = @_; | ||||
|     my ( $self, $lat, $long ) = @_; | ||||
|  | ||||
|     $self->{lat}  = $lat; | ||||
|     $self->{long} = $long; | ||||
| @@ -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' | ||||
|   | ||||
		Reference in New Issue
	
	Block a user