Interesting. I was having a similar problem and I solved it by making each of the handlers closures with a shared lexical. While I had each handler as a named subroutine it is also probably better written as a generator. I'll include samples of each mode - what I actually used and what I think is better.
# My actual implementation { my $object; sub setobject { $object = shift; } # Each of these routines has access to the shared # lexical. Enclosing this whole section in a block # prevents the lexical from being used in other scopes sub start_handler { ... } sub char_handler { ... } sub end_handler { ... } } # What is probably better though there is a heck of a lot # of space to move this around. I implemented this as a # wrapper over some named subroutines and passed the shared # variable in. You can really do this however you feel. sub get_handlers { my $object; return { start_handler => sub { start_handler(\@_,\$object) }, end_handler => sub { end_handler(\@_,\$object) }, char_handler => sub { char_handler(\@_,\$object) } } }
Seeking Green geeks in Minnesota
In reply to Re: XML::Parser and objects
by diotalevi
in thread XML::Parser and objects
by Ineffectual
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |