in reply to Access parent class object in callback
I think using the word "parent" is misleading in your title, because you seem to (properly) use containment/delegation instead of inheritance. If I misunderstand your setup, the following likely is also wrong:
I would pass closures as the callbacks that contain and pass on the reference to $self as well:
sub parse { my ($self, $xmlfile) = @_; my $parser = XML::Parser->new( Handlers => {Start => sub { $self->handle_start(@_) }, End => sub { $self->handle_end(@_) }, Char => sub { $self->handle_char(@_) }, ); $parser->parsefile($xmlfile); } sub handle_start { my ($self, $parser, @args) = @_; print $self->{i_need_this}; ... }; ...
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Access parent class object in callback
by Elijah (Hermit) on Mar 08, 2008 at 12:32 UTC | |
by Corion (Patriarch) on Mar 08, 2008 at 12:46 UTC |