diff --git a/fhem/FHEM/42_npmjs.pm b/fhem/FHEM/42_npmjs.pm index ba8520cc0..070c99a31 100644 --- a/fhem/FHEM/42_npmjs.pm +++ b/fhem/FHEM/42_npmjs.pm @@ -34,6 +34,44 @@ use FHEM::Meta; use GPUtils qw(GP_Import); use Data::Dumper; +# Run before module compilation +BEGIN { + + # JSON preference order + $ENV{PERL_JSON_BACKEND} = + 'Cpanel::JSON::XS,JSON::XS,JSON::PP,JSON::backportPP' + unless ( defined( $ENV{PERL_JSON_BACKEND} ) ); + + # Import from main:: + GP_Import( + qw( + readingsSingleUpdate + readingsBulkUpdate + readingsBulkUpdateIfChanged + readingsBeginUpdate + readingsEndUpdate + ReadingsTimestamp + defs + modules + Log3 + Debug + DoTrigger + CommandAttr + attr + AttrVal + ReadingsVal + Value + IsDisabled + deviceEvents + init_done + gettimeofday + InternalTimer + RemoveInternalTimer + FW_webArgs + ) + ); +} + # try to use JSON::MaybeXS wrapper # for chance of better performance + open code eval { @@ -87,38 +125,6 @@ if ($@) { } } -# Run before module compilation -BEGIN { - # Import from main:: - GP_Import( - qw( - readingsSingleUpdate - readingsBulkUpdate - readingsBulkUpdateIfChanged - readingsBeginUpdate - readingsEndUpdate - ReadingsTimestamp - defs - modules - Log3 - Debug - DoTrigger - CommandAttr - attr - AttrVal - ReadingsVal - Value - IsDisabled - deviceEvents - init_done - gettimeofday - InternalTimer - RemoveInternalTimer - FW_webArgs - ) - ); -} - my %fhem_npm_modules = ( 'alexa-fhem' => { fhem_module => 'alexa', }, 'gassistant-fhem' => { fhem_module => 'gassistant', }, @@ -1846,8 +1852,7 @@ sub ToDay() { "SubProcess": 0 }, "recommends": { - "JSON": 0, - "JSON::MaybeXS": 0 + "JSON": 0 }, "suggests": { "Cpanel::JSON::XS": 0, diff --git a/fhem/FHEM/98_Installer.pm b/fhem/FHEM/98_Installer.pm index 2752a769b..c0db2c6d7 100644 --- a/fhem/FHEM/98_Installer.pm +++ b/fhem/FHEM/98_Installer.pm @@ -41,6 +41,51 @@ use Data::Dumper; use Config; use ExtUtils::Installed; +# Run before module compilation +BEGIN { + + # JSON preference order + $ENV{PERL_JSON_BACKEND} = + 'Cpanel::JSON::XS,JSON::XS,JSON::PP,JSON::backportPP' + unless ( defined( $ENV{PERL_JSON_BACKEND} ) ); + + # Import from main:: + GP_Import( + qw( + attr + AttrVal + cmds + CommandAttr + Debug + defs + deviceEvents + devspec2array + DoTrigger + FW_webArgs + gettimeofday + init_done + InternalTimer + IsDisabled + LoadModule + Log + Log3 + maxNum + modules + packages + readingsBeginUpdate + readingsBulkUpdate + readingsBulkUpdateIfChanged + readingsEndUpdate + readingsSingleUpdate + ReadingsTimestamp + ReadingsVal + RemoveInternalTimer + TimeNow + Value + ) + ); +} + # try to use JSON::MaybeXS wrapper # for chance of better performance + open code eval { @@ -86,53 +131,25 @@ if ($@) { # Fallback to built-in JSON which SHOULD # be available since 5.014 ... - require JSON::PP; - import JSON::PP qw(decode_json encode_json); - 1; + 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; + } } } } } -# Run before module compilation -BEGIN { - # Import from main:: - GP_Import( - qw( - attr - AttrVal - cmds - CommandAttr - Debug - defs - deviceEvents - devspec2array - DoTrigger - FW_webArgs - gettimeofday - init_done - InternalTimer - IsDisabled - LoadModule - Log - Log3 - maxNum - modules - packages - readingsBeginUpdate - readingsBulkUpdate - readingsBulkUpdateIfChanged - readingsEndUpdate - readingsSingleUpdate - ReadingsTimestamp - ReadingsVal - RemoveInternalTimer - TimeNow - Value - ) - ); -} - # Load dependent FHEM modules as packages, # no matter if user also defined FHEM devices or not. # We want to use their functions here :-) @@ -1032,7 +1049,7 @@ sub CpanInstall($) { print qq($line\n) if ( $cmd->{debug} == 1 ); if ( $line =~ - /^Successfully\s+(\S+)\s+([\S]+)-(\d+\.\d+(?:_\d+)?).*$/i ) + /^Successfully\s+(\S+)\s+([\S]+)-(\d+(?:\.\d+(?:_\d+)?)?).*$/i ) { my $r = $1; my $m = $2; @@ -1044,7 +1061,8 @@ sub CpanInstall($) { } elsif ( $line =~ - /^(\S+)\s+is\s+up\s+to\s+date.*\((\d+\.\d+(?:_\d+)?)\).*$/i ) + /^(\S+)\s+is\s+up\s+to\s+date.*\((\d+(?:\.\d+(?:_\d+)?)?)\).*$/i + ) { my $m = $1; my $v = $2; @@ -5483,8 +5501,7 @@ sub __list_module { }, "recommends": { "Perl::PrereqScanner::NotQuiteLite": 0, - "JSON": 0, - "JSON::MaybeXS": 0 + "JSON": 0 }, "suggests": { "Cpanel::JSON::XS": 0, diff --git a/fhem/FHEM/Meta.pm b/fhem/FHEM/Meta.pm index c4ab2eeb2..80167c8ac 100644 --- a/fhem/FHEM/Meta.pm +++ b/fhem/FHEM/Meta.pm @@ -22,6 +22,11 @@ use Encode; # Run before module compilation BEGIN { + # JSON preference order + $ENV{PERL_JSON_BACKEND} = + 'Cpanel::JSON::XS,JSON::XS,JSON::PP,JSON::backportPP' + unless ( defined( $ENV{PERL_JSON_BACKEND} ) ); + # Import from main:: GP_Import( qw( @@ -1293,6 +1298,18 @@ m/(^#\s+(?:\d{1,2}\.\d{1,2}\.(?:\d{2}|\d{4})\s+)?[^v\d]*(v?(?:\d{1,3}\.\d{1,3}(? import JSON::PP qw(decode_json encode_json); 1; }; + + if ($@) { + $@ = undef; + + # Fallback to JSON::backportPP in really rare cases + eval { + require JSON::backportPP; + import JSON::backportPP + qw(decode_json encode_json); + 1; + }; + } } } } @@ -3155,7 +3172,6 @@ sub __SetXVersion { }, "recommends": { "JSON": 0, - "JSON::MaybeXS": 0, "Perl::PrereqScanner::NotQuiteLite": 0, "Time::Local": 0 },