Skip to content
Snippets Groups Projects
Commit 00185715 authored by Gerhard Gonter's avatar Gerhard Gonter :speech_balloon:
Browse files

use File::Slurper

parent cdf49679
Branches
Tags
No related merge requests found
...@@ -3,6 +3,7 @@ package Util::JSON; ...@@ -3,6 +3,7 @@ package Util::JSON;
use strict; use strict;
use File::Slurper qw(read_text write_text);
use JSON -convert_blessed_universally; use JSON -convert_blessed_universally;
sub read_json_file sub read_json_file
...@@ -12,10 +13,19 @@ sub read_json_file ...@@ -12,10 +13,19 @@ sub read_json_file
# BEGIN load JSON data from file content # BEGIN load JSON data from file content
local $/; local $/;
# print "reading config [$fnm]\n"; # print "reading config [$fnm]\n";
=begin comment
open( my $fh, '<:utf8', $fnm ) or return undef; open( my $fh, '<:utf8', $fnm ) or return undef;
my $json_text = <$fh>; my $json_text = <$fh>;
close ($fh); close ($fh);
# decode_json( $json_text ); # for some reason, decode_json() barfs when otherwise cleanly read wide characters are present # decode_json( $json_text ); # for some reason, decode_json() barfs when otherwise cleanly read wide characters are present
=end comment
=cut
my $json_text= read_text($fnm);
from_json($json_text); from_json($json_text);
} }
...@@ -30,10 +40,18 @@ sub write_json_file ...@@ -30,10 +40,18 @@ sub write_json_file
my $json= new JSON; my $json= new JSON;
my $json_str= $json->allow_blessed->convert_blessed->encode($x); my $json_str= $json->allow_blessed->convert_blessed->encode($x);
=begin comment
open (J, '>:utf8', $json_fnm) or die ("can not write to [$json_fnm]"); open (J, '>:utf8', $json_fnm) or die ("can not write to [$json_fnm]");
syswrite (J, $json_str); syswrite (J, $json_str);
close (J); close (J);
=end comment
=cut
write_text($fnm, $json_str);
1; 1;
} }
...@@ -52,6 +70,12 @@ sub get_config_item ...@@ -52,6 +70,12 @@ sub get_config_item
__END__ __END__
=head1 DEPENDENCIES
=head2 Ubuntu
sudo apt-get install libfile-slurper-perl
=head1 AUTHOR =head1 AUTHOR
Gerhard Gonter <ggonter@cpan.org> Gerhard Gonter <ggonter@cpan.org>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment