Implement General::jsonLoad
This commit is contained in:
parent
2768975f96
commit
a7dc9d4e36
|
@ -28,6 +28,7 @@ our %EXPORT_TAGS = (
|
||||||
makePath
|
makePath
|
||||||
jsonEncode
|
jsonEncode
|
||||||
jsonDecode
|
jsonDecode
|
||||||
|
jsonLoad
|
||||||
systemStatus
|
systemStatus
|
||||||
packageControl
|
packageControl
|
||||||
daemonControl
|
daemonControl
|
||||||
|
@ -536,6 +537,23 @@ sub jsonDecode {
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sub jsonLoad {
|
||||||
|
my $file = shift;
|
||||||
|
my $json = undef;
|
||||||
|
eval {
|
||||||
|
require File::Slurp;
|
||||||
|
my $contents = File::Slurp::read_file($file);
|
||||||
|
if (!$contents) {
|
||||||
|
Error("No contents for $file");
|
||||||
|
return $json;
|
||||||
|
}
|
||||||
|
require JSON;
|
||||||
|
$json = JSON::decode_json($contents);
|
||||||
|
};
|
||||||
|
Error($@) if $@;
|
||||||
|
return $json;
|
||||||
|
}
|
||||||
|
|
||||||
sub parseNameEqualsValueToHash {
|
sub parseNameEqualsValueToHash {
|
||||||
my %settings;
|
my %settings;
|
||||||
foreach my $line ( split ( /\r?\n/, $_[0] ) ) {
|
foreach my $line ( split ( /\r?\n/, $_[0] ) ) {
|
||||||
|
|
Loading…
Reference in New Issue