Implement General::jsonLoad
This commit is contained in:
parent
2768975f96
commit
a7dc9d4e36
|
@ -28,6 +28,7 @@ our %EXPORT_TAGS = (
|
|||
makePath
|
||||
jsonEncode
|
||||
jsonDecode
|
||||
jsonLoad
|
||||
systemStatus
|
||||
packageControl
|
||||
daemonControl
|
||||
|
@ -536,6 +537,23 @@ sub jsonDecode {
|
|||
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 {
|
||||
my %settings;
|
||||
foreach my $line ( split ( /\r?\n/, $_[0] ) ) {
|
||||
|
|
Loading…
Reference in New Issue