Subject: | [PATCH] Tangram::Type::Dump::Perl fails to import self-referentials |
Date: | Tue, 29 May 2007 17:39:22 +0200 (CEST) |
To: | bug-Tangram [...] rt.cpan.org |
From: | Mark Lawrence <nomad [...] null.net> |
Hi Sam,
I've run into a bug with 'perl_dump' types. When 'eval'ing the column
retrieved from the storage, Tangram/Type/Dump/Perl.pm uses something
equivalent to the following:
my $obj = eval $expr;
However HASHes that are self referential are Dumped using more than
one statement because we necessarily set the Data::Dumper::Purity flag:
The default output of self-referential structures can be "eval"ed, but
the nested references to $VARn will be undefined, since a recursive
structure cannot be constructed using one Perl statement. You should
set the "Purity" flag to 1 to get additional statements that will
correctly fill in these references.
Since "eval {1;2;}" returns the value of the last statement (instead of
the first) we don't get what we expected.
The following patch fixes this, while maintaining behaviour for plain
HASHes.
Cheers,
Mark.
Fix Tangram::Type::Dump::Perl to handle self-referential objects.
---
commit 110879178cc3f2dd754af30e6c3e8f1fd46b83d7
tree 67b8d8071a02a7ced00e79f86acf3975b16bf153
parent 9ac7bac01b37a1b40c8facea1bb5d2699816f4bb
author Mark Lawrence <nomad@null.net> Tue, 29 May 2007 17:36:47 +0200
committer Mark Lawrence <nomad@null.net> Tue, 29 May 2007 17:36:47 +0200
lib/Tangram/Type/Dump/Perl.pm | 4 +++-
1 files changed, 3 insertions(+), 1 deletions(-)
diff --git a/lib/Tangram/Type/Dump/Perl.pm b/lib/Tangram/Type/Dump/Perl.pm
index f8bcb8b..b39e3ee 100644
--- a/lib/Tangram/Type/Dump/Perl.pm
+++ b/lib/Tangram/Type/Dump/Perl.pm
@@ -69,7 +69,9 @@ sub reschema {
sub get_importer
{
my ($self, $context) = @_;
- return("\$obj->{$self->{name}} = eval shift \@\$row;"
+ return("undef \$_t::v1;"
+ ."my \$val = eval shift \@\$row;"
+ ."\$obj->{$self->{name}} = \$_t::v1 || \$val;"
."Tangram::Type::Dump::unflatten(\$context->{storage}, "
."\$obj->{$self->{name}})");
}
--
Mark Lawrence