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
ab8e69f8
Commit
ab8e69f8
authored
5 years ago
by
Gerhard Gonter
Browse files
Options
Downloads
Patches
Plain Diff
do not depend on File::Sluper
parent
63010c03
No related branches found
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
+40
-21
40 additions, 21 deletions
modules/util/Util/JSON.pm
with
40 additions
and
21 deletions
modules/util/Util/JSON.pm
+
40
−
21
View file @
ab8e69f8
...
...
@@ -3,7 +3,22 @@ package Util::JSON;
use
strict
;
use
File::
Slurper
qw(read_text write_text)
;
BEGIN
{
eval
{
require
File::
Slurper
;
# *read_text= File::Slurper::read_text;
# *write_text= File::Slurper::write_text;
};
if
(
$@
)
{
print
STDERR
"
defining read_text ourselves
\n
";
*read_text
=
*x_read_text
;
*write_text
=
*x_wirte_text
;
}
}
use
JSON
-
convert_blessed_universally
;
sub
read_json_file
...
...
@@ -11,26 +26,17 @@ sub read_json_file
my
$fnm
=
shift
;
# 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
;
eval
{
$json_text
=
read_text
(
$fnm
);
};
if
(
$@
)
if
(
$@
||
!
defined
(
$json_text
)
)
{
return
undef
;
}
...
...
@@ -49,16 +55,6 @@ 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
(
$json_fnm
,
$json_str
);
1
;
...
...
@@ -75,6 +71,29 @@ sub get_config_item
my
$cfg
=
shift
;
}
sub
x_read_text
{
my
$fnm
=
shift
;
open
(
my
$fh
,
'
<:utf8
',
$fnm
)
or
return
undef
;
local
$/
;
my
$json_text
=
<
$fh
>
;
close
(
$fh
);
$json_text
;
}
sub
x_write_text
{
my
$json_fnm
=
shift
;
my
$json_str
=
shift
;
open
(
J
,
'
>:utf8
',
$json_fnm
)
or
die
("
can not write to [
$json_fnm
]
");
syswrite
(
J
,
$json_str
);
close
(
J
);
}
1
;
__END__
...
...
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