accessing object variables from callback function
- From: "kaisung@xxxxxxxxx" <kaisung@xxxxxxxxx>
- Date: 29 Jun 2006 02:23:06 -0700
Hi,
I'm trying to write a Class which uses XML::Parser. XML::Parser uses
callback functions. If I use an object method as the callback
function, how can I access object variables from within that callback
function if it doesn't get passed a reference to $self? Here's what I
have so far:
-----BEGIN PERL-----
package Test;
use XML::Parser;
sub new {
my $invocant = shift;
my $class = ref($invocant) || $invocant;
my $self = { @_ };
bless($self, $class);
return $self;
}
sub load {
my $parser = new XML::Parser(ErrorContext => 2);
$parser->setHandlers(Start => \&_start_handler);
$parser->parsefile("file.xml");
}
sub _start_handler {
# In this function, I want to set $self->{var}, however don't have
# access to $self
}
sub getVar {
my $self = shift;
return $self->{var};
}
-----END PERL-----
Thanks in advance,
-Kai
.
- Follow-Ups:
- Re: accessing object variables from callback function
- From: anno4000
- Re: accessing object variables from callback function
- Prev by Date: Re: Scalable method for searching in relatively big files
- Next by Date: Re: crash on async in taint mode
- Previous by thread: Debugging Memory consumption for Perl Program
- Next by thread: Re: accessing object variables from callback function
- Index(es):
Relevant Pages
|
|