From a68eb2021dbb14d3d550ccb0becbd6c75b725545 Mon Sep 17 00:00:00 2001 From: Shawn Laffan Date: Sat, 3 Sep 2016 13:54:29 +1000 Subject: [PATCH] Sereal does not serialise code refs Updates #358 (even though it has been closed) --- lib/Biodiverse/Common.pm | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/Biodiverse/Common.pm b/lib/Biodiverse/Common.pm index 8aecf7bd1..af4cda035 100644 --- a/lib/Biodiverse/Common.pm +++ b/lib/Biodiverse/Common.pm @@ -831,11 +831,15 @@ sub save_to_sereal { use Sereal::Encoder; - my $encoder = Sereal::Encoder->new(); - my $out = $encoder->encode($self); + my $encoder = Sereal::Encoder->new({ + undef_unknown => 1, # strip any code refs + }); open (my $fh, '>', $file) or die "Cannot open $file"; - print {$fh} $out; + + eval { + print {$fh} $encoder->encode($self); + }; my $e = $EVAL_ERROR; $fh->close;