Subject: | [PATCH] Solve Stash::XS problem with tied hashes |
The attached patch (against 2.13) solves the first bug mentioned in the
Template::Stash::XS Pod. It just uses SvOK instead of comparing to
PL_sv_undef to determine the definedness of a hash value --- just like it
is done in the perl internals (pp_defined in file pp.c). The patch also
includes another test case in tiedelem.t.
Regards,
Slaven
--- ./t/tiedhash.t.orig 2004-09-30 18:32:41.000000000 +0200
+++ ./t/tiedhash.t 2004-09-30 18:43:57.000000000 +0200
@@ -65,8 +65,17 @@ sub STORE {
# sub DELETE { }
# sub CLEAR { }
# sub EXISTS { }
-# sub FIRSTKEY { }
-# sub NEXTKEY { }
+sub FIRSTKEY {
+ my ($self) = @_;
+ my $action = $self->{ FIRSTKEY } || return undef;
+ &$action();
+}
+
+sub NEXTKEY {
+ my ($self) = @_;
+ my $action = $self->{ NEXTKEY } || return undef;
+ &$action();
+}
sub AUTOLOAD {
my $self = shift;
@@ -94,6 +103,12 @@ my $hash = My::Tied::Hash->new({
print "STORE($key, $val)\n" if $DEBUG;
$data->{ $key } = $val;
},
+ FIRSTKEY => sub { print "FIRSTKEY\n" if $DEBUG;
+ my $a = scalar keys %$data; each %$data;
+ },
+ NEXTKEY => sub { print "NEXTKEY\n" if $DEBUG;
+ each %$data;
+ },
});
#------------------------------------------------------------------------
@@ -173,3 +188,7 @@ nothing
1
+-- test --
+[% hash.keys.sort.join(" ") %]
+-- expect --
+a b c d e f foo g h i j k l m n o one p q r s t u v w wiz x y z zero
--- ./xs/Stash.xs.orig 2004-09-30 18:25:45.000000000 +0200
+++ ./xs/Stash.xs 2004-09-30 18:27:03.000000000 +0200
@@ -344,7 +344,7 @@ static TT_RET tt_fetch_item(pTHX_ SV *ro
return TT_RET_CODEREF;
}
- else if (*value != &PL_sv_undef) {
+ else if (SvOK(*value)) {
*result = *value;
return TT_RET_OK;
}