mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-04-21 07:56:03 +00:00
Meta.pm: maximize JSON performance and compatibility
git-svn-id: https://svn.fhem.de/fhem/trunk@19216 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
parent
53d961b626
commit
96fdfe63c8
@ -32,9 +32,61 @@ use POSIX;
|
|||||||
use FHEM::Meta;
|
use FHEM::Meta;
|
||||||
|
|
||||||
use GPUtils qw(GP_Import);
|
use GPUtils qw(GP_Import);
|
||||||
use JSON;
|
|
||||||
use Data::Dumper;
|
use Data::Dumper;
|
||||||
|
|
||||||
|
# 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 {
|
||||||
|
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 ...
|
||||||
|
require JSON::PP;
|
||||||
|
import JSON::PP qw(decode_json encode_json);
|
||||||
|
1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
# Run before module compilation
|
# Run before module compilation
|
||||||
BEGIN {
|
BEGIN {
|
||||||
# Import from main::
|
# Import from main::
|
||||||
@ -527,14 +579,14 @@ sub Get($$@) {
|
|||||||
|
|
||||||
my ( $cmd, @args ) = @aa;
|
my ( $cmd, @args ) = @aa;
|
||||||
|
|
||||||
if ( $cmd eq 'showOutdatedList' ) {
|
if ( lc($cmd) eq 'showoutdatedlist' ) {
|
||||||
return "usage: $cmd" if ( @args != 0 );
|
return "usage: $cmd" if ( @args != 0 );
|
||||||
|
|
||||||
my $ret = CreateOutdatedList( $hash, $cmd );
|
my $ret = CreateOutdatedList( $hash, $cmd );
|
||||||
return $ret;
|
return $ret;
|
||||||
|
|
||||||
}
|
}
|
||||||
elsif ( $cmd eq 'showInstalledList' ) {
|
elsif ( lc($cmd) eq 'showinstalledlist' ) {
|
||||||
return "usage: $cmd" if ( @args != 0 );
|
return "usage: $cmd" if ( @args != 0 );
|
||||||
|
|
||||||
my $ret = CreateInstalledList( $hash, $cmd );
|
my $ret = CreateInstalledList( $hash, $cmd );
|
||||||
@ -570,7 +622,7 @@ sub Get($$@) {
|
|||||||
# return $ret;
|
# return $ret;
|
||||||
#
|
#
|
||||||
# }
|
# }
|
||||||
elsif ( $cmd eq 'showErrorList' ) {
|
elsif ( lc($cmd) eq 'showerrorlist' ) {
|
||||||
return "usage: $cmd" if ( @args != 0 );
|
return "usage: $cmd" if ( @args != 0 );
|
||||||
|
|
||||||
my $ret = CreateErrorList($hash);
|
my $ret = CreateErrorList($hash);
|
||||||
@ -1406,7 +1458,8 @@ sub CreateInstalledList($$) {
|
|||||||
if ( ref($packages) eq "HASH" ) {
|
if ( ref($packages) eq "HASH" ) {
|
||||||
|
|
||||||
my $linecount = 1;
|
my $linecount = 1;
|
||||||
foreach my $package ( sort keys( %{$packages} ) ) {
|
foreach my $package ( sort { "\L$a" cmp "\L$b" } keys( %{$packages} ) )
|
||||||
|
{
|
||||||
next if ( $package eq "undefined" );
|
next if ( $package eq "undefined" );
|
||||||
|
|
||||||
my $l = $linecount % 2 == 0 ? $rowOpenEven : $rowOpenOdd;
|
my $l = $linecount % 2 == 0 ? $rowOpenEven : $rowOpenOdd;
|
||||||
@ -1494,7 +1547,8 @@ sub CreateOutdatedList($$) {
|
|||||||
if ( ref($packages) eq "HASH" ) {
|
if ( ref($packages) eq "HASH" ) {
|
||||||
|
|
||||||
my $linecount = 1;
|
my $linecount = 1;
|
||||||
foreach my $package ( sort keys( %{$packages} ) ) {
|
foreach my $package ( sort { "\L$a" cmp "\L$b" } keys( %{$packages} ) )
|
||||||
|
{
|
||||||
next if ( $package eq "undefined" );
|
next if ( $package eq "undefined" );
|
||||||
my $fhemPkg = defined( $fhem_npm_modules{$package} ) ? 1 : 0;
|
my $fhemPkg = defined( $fhem_npm_modules{$package} ) ? 1 : 0;
|
||||||
|
|
||||||
@ -1765,7 +1819,7 @@ sub ToDay() {
|
|||||||
"abstract": "Modul zur Bedienung der Node.js Installation und Updates"
|
"abstract": "Modul zur Bedienung der Node.js Installation und Updates"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"version": "v1.0.6",
|
"version": "v1.1.0",
|
||||||
"release_status": "stable",
|
"release_status": "stable",
|
||||||
"author": [
|
"author": [
|
||||||
"Julian Pawlowski <julian.pawlowski@gmail.com>"
|
"Julian Pawlowski <julian.pawlowski@gmail.com>"
|
||||||
@ -1787,12 +1841,17 @@ sub ToDay() {
|
|||||||
"FHEM": 5.00918799,
|
"FHEM": 5.00918799,
|
||||||
"perl": 5.014,
|
"perl": 5.014,
|
||||||
"GPUtils": 0,
|
"GPUtils": 0,
|
||||||
"JSON": 0,
|
"JSON::PP": 0,
|
||||||
"Data::Dumper": 0
|
"Data::Dumper": 0,
|
||||||
|
"SubProcess": 0
|
||||||
},
|
},
|
||||||
"recommends": {
|
"recommends": {
|
||||||
|
"JSON": 0,
|
||||||
|
"JSON::MaybeXS": 0
|
||||||
},
|
},
|
||||||
"suggests": {
|
"suggests": {
|
||||||
|
"Cpanel::JSON::XS": 0,
|
||||||
|
"JSON::XS": 0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -37,11 +37,63 @@ use POSIX;
|
|||||||
use FHEM::Meta;
|
use FHEM::Meta;
|
||||||
|
|
||||||
use GPUtils qw(GP_Import);
|
use GPUtils qw(GP_Import);
|
||||||
use JSON::PP;
|
|
||||||
use Data::Dumper;
|
use Data::Dumper;
|
||||||
use Config;
|
use Config;
|
||||||
use ExtUtils::Installed;
|
use ExtUtils::Installed;
|
||||||
|
|
||||||
|
# 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 {
|
||||||
|
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 ...
|
||||||
|
require JSON::PP;
|
||||||
|
import JSON::PP qw(decode_json encode_json);
|
||||||
|
1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
# Run before module compilation
|
# Run before module compilation
|
||||||
BEGIN {
|
BEGIN {
|
||||||
# Import from main::
|
# Import from main::
|
||||||
@ -1754,7 +1806,7 @@ sub CreateInstalledPerlList($$) {
|
|||||||
. $tHOpen
|
. $tHOpen
|
||||||
. $trOpen;
|
. $trOpen;
|
||||||
|
|
||||||
push @ret, $thOpen . 'Package Name' . $thClose;
|
push @ret, $thOpen . 'Name' . $thClose;
|
||||||
push @ret, $thOpen . 'Version' . $thClose;
|
push @ret, $thOpen . 'Version' . $thClose;
|
||||||
push @ret, $trClose . $tHClose;
|
push @ret, $trClose . $tHClose;
|
||||||
|
|
||||||
@ -1917,7 +1969,7 @@ sub CreateOutdatedPerlList($$) {
|
|||||||
. $tHOpen
|
. $tHOpen
|
||||||
. $trOpen;
|
. $trOpen;
|
||||||
|
|
||||||
push @ret, $thOpen . 'Package Name' . $thClose;
|
push @ret, $thOpen . 'Name' . $thClose;
|
||||||
push @ret, $thOpen . 'Current Version' . $thClose;
|
push @ret, $thOpen . 'Current Version' . $thClose;
|
||||||
push @ret, $thOpen . 'Latest Version' . $thClose;
|
push @ret, $thOpen . 'Latest Version' . $thClose;
|
||||||
push @ret, $trClose . $tHClose;
|
push @ret, $trClose . $tHClose;
|
||||||
@ -2253,15 +2305,15 @@ sub CreatePrereqsList {
|
|||||||
. $mAttr . ' '
|
. $mAttr . ' '
|
||||||
. ucfirst($area)
|
. ucfirst($area)
|
||||||
. '</a></div>';
|
. '</a></div>';
|
||||||
# push @ret,
|
push @ret,
|
||||||
# ( $linecount % 2 == 0 ? $trOpenEven : $trOpenOdd )
|
( $linecount % 2 == 0 ? $trOpenEven : $trOpenOdd )
|
||||||
# . $tdOpen3
|
. $tdOpen3
|
||||||
# . $tdClose
|
. $tdClose
|
||||||
# . $tdOpen1
|
. $tdOpen1
|
||||||
# . $action
|
. $action
|
||||||
# . $tdClose
|
. $tdClose
|
||||||
# . $trClose
|
. $trClose
|
||||||
# if ($html);
|
if ($html);
|
||||||
|
|
||||||
push @ret, $tBClose;
|
push @ret, $tBClose;
|
||||||
|
|
||||||
@ -5424,16 +5476,19 @@ sub __list_module {
|
|||||||
"Config": 0,
|
"Config": 0,
|
||||||
"ExtUtils::Installed": 0,
|
"ExtUtils::Installed": 0,
|
||||||
"B": 0,
|
"B": 0,
|
||||||
"JSON": 0,
|
"JSON::PP": 0,
|
||||||
"perl": 5.014,
|
"perl": 5.014,
|
||||||
"version": 0,
|
"version": 0,
|
||||||
"SubProcess": 0
|
"SubProcess": 0
|
||||||
},
|
},
|
||||||
"recommends": {
|
"recommends": {
|
||||||
"Perl::PrereqScanner::NotQuiteLite": 0,
|
"Perl::PrereqScanner::NotQuiteLite": 0,
|
||||||
"Time::Local": 0
|
"JSON": 0,
|
||||||
|
"JSON::MaybeXS": 0
|
||||||
},
|
},
|
||||||
"suggests": {
|
"suggests": {
|
||||||
|
"Cpanel::JSON::XS": 0,
|
||||||
|
"JSON::XS": 0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -1241,11 +1241,62 @@ m/(^#\s+(?:\d{1,2}\.\d{1,2}\.(?:\d{2}|\d{4})\s+)?[^v\d]*(v?(?:\d{1,3}\.\d{1,3}(?
|
|||||||
$encoding = 'latin1' unless ($encoding);
|
$encoding = 'latin1' unless ($encoding);
|
||||||
|
|
||||||
if ( keys %json > 0 ) {
|
if ( keys %json > 0 ) {
|
||||||
|
|
||||||
|
# try to use JSON::MaybeXS wrapper
|
||||||
|
# for chance of better performance + open code
|
||||||
|
# See: https://perlmaven.com/comparing-the-speed-of-json-decoders
|
||||||
eval {
|
eval {
|
||||||
require JSON::PP;
|
require JSON::MaybeXS;
|
||||||
JSON::PP->import();
|
import JSON::MaybeXS qw( decode_json );
|
||||||
1;
|
1;
|
||||||
};
|
};
|
||||||
|
if ($@) {
|
||||||
|
$@ = undef;
|
||||||
|
|
||||||
|
# try to use JSON wrapper
|
||||||
|
# for chance of better performance
|
||||||
|
eval {
|
||||||
|
require JSON;
|
||||||
|
import JSON qw( decode_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 ( !$@ ) {
|
if ( !$@ ) {
|
||||||
foreach ( keys %json ) {
|
foreach ( keys %json ) {
|
||||||
@ -3052,7 +3103,7 @@ sub __SetXVersion {
|
|||||||
"2019-04-18": {
|
"2019-04-18": {
|
||||||
"version": "v0.5.1",
|
"version": "v0.5.1",
|
||||||
"changes": [
|
"changes": [
|
||||||
"use built-in JSON:PP instead of JSON"
|
"improved JSON dependencies"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"2019-04-16": {
|
"2019-04-16": {
|
||||||
@ -3099,14 +3150,18 @@ sub __SetXVersion {
|
|||||||
"Data::Dumper": 0,
|
"Data::Dumper": 0,
|
||||||
"Module::CoreList": 0,
|
"Module::CoreList": 0,
|
||||||
"Encode": 0,
|
"Encode": 0,
|
||||||
"version": 0
|
"version": 0,
|
||||||
|
"JSON::PP": 0
|
||||||
},
|
},
|
||||||
"recommends": {
|
"recommends": {
|
||||||
"JSON::PP": 0,
|
"JSON": 0,
|
||||||
|
"JSON::MaybeXS": 0,
|
||||||
"Perl::PrereqScanner::NotQuiteLite": 0,
|
"Perl::PrereqScanner::NotQuiteLite": 0,
|
||||||
"Time::Local": 0
|
"Time::Local": 0
|
||||||
},
|
},
|
||||||
"suggests": {
|
"suggests": {
|
||||||
|
"JSON::XS": 0,
|
||||||
|
"Cpanel::JSON::XS": 0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
Loading…
x
Reference in New Issue
Block a user