Subject: | Postback IDs |
POE-Component-Generic-0.1008
perl -v: This is perl, v5.8.8 built for darwin-2level
uname -a: Darwin hephaestus.local 8.11.1 Darwin Kernel Version
8.11.1: Wed Oct 10 18:23:28 PDT 2007; root:xnu-792.25.20~1/RELEASE_I386
i386 i386
Calling postbacks and saving the values in the child breaks if where you
save it depends on some other arguments: only the last value will be
saved, because the PBids will be the same.
(note: the following code is imaginary, and wouldn't work at all as
written. we'd have to convert coderefs to states, etc...)
<code>
#...parent...
child->set_a_postback_for_later({}, 'Quiznos', sub {
return "Toasty.";
});
child->set_a_postback_for_later({}, 'Subway', sub {
return "Not-toasty.";
});
#...child...
sub set_a_postback_for_later {
my ($self, $name, $pb) = @_;
shift->{callbacks}->{$name} = $pb;
}
#...much later...
$self->{callbacks}->{'Quiznos'}->();
Show quoted text
>>> "Not-toasty" # clearly untrue!
</code>
This happens because PBIDs are based solely on the postback-signature.
This can be fixed by making PBIDs more unique:
1) have them include the rest of their arguments
2) use some other unique identifier
1 would make the PBIDs arbitrarily long and I don't like it, 2 is used
in the attached patch (just an incrementing integer). The patch has the
outside possibility of overflowing if Perl's arbitrary precision
arithmetic isn't baked in, but then you'd just get a wrap (and unless
you're trying to store 4 billion different postbacks, that won't be a
problem. Also, wraps are really tasty). If that's a concern,
Data::UUID would give us something guaranteed unique, but that's adding
a dependancy. I'd be happy to cook up a patch for that if you think
it's better.
Thanks for looking at this. :)
-Paul
p.s. It's almost lunchtime and I missed breakfast, sorry for the food
metaphors...
Subject: | possible_fix.patch |
52a53,54
>
> $self->{next_PBid} = 0;
462c464,468
<
---
> sub __next_PBid
> {
> my $num = shift->{next_PBid}++;
> return "---POSTBACK-$num---";
> }
477c483
< my $PBid = "---POSTBACK-$params->{package}-$pmap->{method}-$pos---";
---
> my $PBid = $self->__next_PBid();
1487c1493
<
\ No newline at end of file
---
>