Unverified Commit 59ee830d authored by boklm's avatar boklm
Browse files

clone_strip_coderef: remove scalar refs

dclone strips code refs and replaces them by a ref to a string, which
encode_json doesn't like. So we now replace those scalar refs with the
scalar itself.
parent d9298c30
......@@ -96,13 +96,30 @@ sub as_array {
ref $_[0] eq 'ARRAY' ? $_[0] : [ $_[0] ];
}
sub remove_scalarref {
my ($data) = @_;
return unless ref $data;
unless (ref $data eq 'ARRAY' or ref $data eq 'HASH') {
return;
}
foreach my $d (ref $data eq 'ARRAY' ? @$data : values %$data) {
if (ref $d eq 'ARRAY' or ref $d eq 'HASH') {
remove_scalarref($d);
} elsif (ref $d eq 'SCALAR') {
$d = $$d;
}
}
}
# clone a data structure, stripping code references
sub clone_strip_coderef {
my ($in) = @_;
local $Storable::Deparse = 0;
local $Storable::forgive_me = 1;
local $SIG{__WARN__} = sub {};
return dclone $in;
my $res = dclone $in;
remove_scalarref $res;
return $res;
}
1;
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment