Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
aix-pm
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Gerhard Gonter
aix-pm
Commits
00185715
Commit
00185715
authored
6 years ago
by
Gerhard Gonter
Browse files
Options
Downloads
Patches
Plain Diff
use File::Slurper
parent
cdf49679
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
modules/util/Util/JSON.pm
+24
-0
24 additions, 0 deletions
modules/util/Util/JSON.pm
with
24 additions
and
0 deletions
modules/util/Util/JSON.pm
+
24
−
0
View file @
00185715
...
...
@@ -3,6 +3,7 @@ package Util::JSON;
use
strict
;
use
File::
Slurper
qw(read_text write_text)
;
use
JSON
-
convert_blessed_universally
;
sub
read_json_file
...
...
@@ -12,10 +13,19 @@ sub read_json_file
# BEGIN load JSON data from file content
local
$/
;
# print "reading config [$fnm]\n";
=begin comment
open( my $fh, '<:utf8', $fnm ) or return undef;
my $json_text = <$fh>;
close ($fh);
# 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
);
}
...
...
@@ -30,10 +40,18 @@ sub write_json_file
my
$json
=
new
JSON
;
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]");
syswrite (J, $json_str);
close (J);
=end comment
=cut
write_text
(
$fnm
,
$json_str
);
1
;
}
...
...
@@ -52,6 +70,12 @@ sub get_config_item
__END__
=head1 DEPENDENCIES
=head2 Ubuntu
sudo apt-get install libfile-slurper-perl
=head1 AUTHOR
Gerhard Gonter <ggonter@cpan.org>
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment