diff --git a/fhem/CHANGED b/fhem/CHANGED index 70a6f6ec7..2216b44be 100644 --- a/fhem/CHANGED +++ b/fhem/CHANGED @@ -1,5 +1,7 @@ # Add changes at the top of the list. Keep it in ASCII, and 80-char wide. # Do not insert empty lines here, update check depends on it. + - feature: 73_AMADCommBridge: try to use JSON::MaybeXS wrapper for chance of + better performance + open code - bugfix: 73_AutoShuttersControl: fix many bugs, code expand's and new logic values - bugfix: 73_GardenaSmartBridge: fix undefined value diff --git a/fhem/FHEM/73_AMADCommBridge.pm b/fhem/FHEM/73_AMADCommBridge.pm index 580463923..1a0496730 100644 --- a/fhem/FHEM/73_AMADCommBridge.pm +++ b/fhem/FHEM/73_AMADCommBridge.pm @@ -64,7 +64,7 @@ use strict; use warnings; use FHEM::Meta; -my $modulversion = '4.4.1'; +my $modulversion = '4.4.2'; my $flowsetversion = '4.4.1'; sub AMADCommBridge_Initialize($) { @@ -118,7 +118,76 @@ use HttpUtils; use TcpServerUtils; eval "use Encode qw(encode encode_utf8);1" or $missingModul .= 'Encode '; -eval "use JSON;1" or $missingModul .= 'JSON '; + +# 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; + } + } + } + } ## Import der FHEM Funktionen BEGIN { diff --git a/fhem/FHEM/74_AMADDevice.pm b/fhem/FHEM/74_AMADDevice.pm index 8f2506c65..d4f068410 100644 --- a/fhem/FHEM/74_AMADDevice.pm +++ b/fhem/FHEM/74_AMADDevice.pm @@ -50,7 +50,7 @@ use strict; use warnings; use FHEM::Meta; -my $modulversion = '4.4.1'; +my $modulversion = '4.4.2'; my $flowsetversion = '4.4.1'; sub AMADDevice_Initialize($) { @@ -122,7 +122,76 @@ use GPUtils qw(GP_Import) my $missingModul = ''; eval "use Encode qw(encode encode_utf8);1" or $missingModul .= 'Encode '; -eval "use JSON;1" or $missingModul .= 'JSON '; + +# 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; + } + } + } + } ## Import der FHEM Funktionen BEGIN {