try to use JSON::MaybeXS wrapper for chance of better performance + open code
This commit is contained in:
File diff suppressed because one or more lines are too long
@ -39,16 +39,84 @@ use warnings;
|
|||||||
use POSIX;
|
use POSIX;
|
||||||
use HttpUtils;
|
use HttpUtils;
|
||||||
|
|
||||||
|
# try to use JSON::MaybeXS wrapper
|
||||||
|
# for chance of better performance + open code
|
||||||
|
eval {
|
||||||
|
require JSON::MaybeXS;
|
||||||
|
import JSON::MaybeXS qw( decode_json encode_json );
|
||||||
|
1;
|
||||||
|
};
|
||||||
|
|
||||||
|
if ($@) {
|
||||||
|
$@ = undef;
|
||||||
|
|
||||||
|
# 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'
|
||||||
|
unless ( defined( $ENV{PERL_JSON_BACKEND} ) );
|
||||||
|
|
||||||
|
require JSON;
|
||||||
|
import JSON qw( decode_json encode_json );
|
||||||
|
1;
|
||||||
|
};
|
||||||
|
|
||||||
|
if ($@) {
|
||||||
|
$@ = undef;
|
||||||
|
|
||||||
|
# In rare cases, Cpanel::JSON::XS may
|
||||||
|
# be installed but JSON|JSON::MaybeXS not ...
|
||||||
|
eval {
|
||||||
|
require Cpanel::JSON::XS;
|
||||||
|
import Cpanel::JSON::XS qw(decode_json encode_json);
|
||||||
|
1;
|
||||||
|
};
|
||||||
|
|
||||||
|
if ($@) {
|
||||||
|
$@ = undef;
|
||||||
|
|
||||||
|
# In rare cases, JSON::XS may
|
||||||
|
# be installed but JSON not ...
|
||||||
|
eval {
|
||||||
|
require JSON::XS;
|
||||||
|
import JSON::XS qw(decode_json encode_json);
|
||||||
|
1;
|
||||||
|
};
|
||||||
|
|
||||||
|
if ($@) {
|
||||||
|
$@ = undef;
|
||||||
|
|
||||||
|
# Fallback to built-in JSON which SHOULD
|
||||||
|
# be available since 5.014 ...
|
||||||
|
eval {
|
||||||
|
require JSON::PP;
|
||||||
|
import JSON::PP qw(decode_json encode_json);
|
||||||
|
1;
|
||||||
|
};
|
||||||
|
|
||||||
|
if ($@) {
|
||||||
|
$@ = undef;
|
||||||
|
|
||||||
|
# Fallback to JSON::backportPP in really rare cases
|
||||||
|
require JSON::backportPP;
|
||||||
|
import JSON::backportPP qw(decode_json encode_json);
|
||||||
|
1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
my $missingModul = '';
|
my $missingModul = '';
|
||||||
eval "use JSON;1"
|
|
||||||
or $missingModul .=
|
|
||||||
"JSON "; # apt-get install libperl-JSON on Debian and derivatives
|
|
||||||
eval "use Encode qw(encode_utf8);1" or $missingModul .= "Encode ";
|
eval "use Encode qw(encode_utf8);1" or $missingModul .= "Encode ";
|
||||||
|
|
||||||
# use Data::Dumper; # for Debug only
|
# use Data::Dumper; # for Debug only
|
||||||
## API URL
|
## API URL
|
||||||
use constant URL => 'https://api.openweathermap.org/data/2.5/';
|
use constant URL => 'https://api.openweathermap.org/data/2.5/';
|
||||||
use constant VERSION => '0.2.5';
|
use constant VERSION => '0.4.0';
|
||||||
## URL . 'weather?' for current data
|
## URL . 'weather?' for current data
|
||||||
## URL . 'forecast?' for forecast data
|
## URL . 'forecast?' for forecast data
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user