in reply to Perl objects and code references
Instead, you need to create an anonymous subroutine that will pass the correct value of $self along to XML::Parser. Anonymous subroutines are neat, if easy to abuse.
The important thing about anonymous subroutines, also known as closures, is that they hang onto the value of any lexical variables inside it. Read perlman:perlsub for more about closures. So, if I created an anonymous subroutine inside a hash, like so:
...and then later on used it:my $self = Foo->new(); my $mysub = sub { $self->increment() };
Then the correct value of $self would be have increment() called on it.$mysub->();
So, in order to fix your problem, you need to create closures around your method calls. I'll leave the rest to you. :)
stephen
|
|---|