Elijah has asked for the wisdom of the Perl Monks concerning the following question:
Here is a simple example:
In this example, I need access to the attribute 'i_need_this' in the XMLParse class object from within the xml parser callback methods. How to I go about getting at it?package XMLParse; use strict; use XML::Parser; sub new { my $class = shift; my $self = { 'i_need_this' => 'important', }; bless $self, $class; return $self; } sub parse { my ($self, $xmlfile) = @_; my $parser = XML::Parser->new( Handlers => {Start => \&handle_start, End => \&handle_end, Char => \&handle_char} ); $parser->parsefile($xmlfile); } sub handle_start { .... } sub handle_end { .... } sub handle_char { .... } 1;
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Access parent class object in callback
by Corion (Patriarch) on Mar 08, 2008 at 12:25 UTC | |
by Elijah (Hermit) on Mar 08, 2008 at 12:32 UTC | |
by Corion (Patriarch) on Mar 08, 2008 at 12:46 UTC |