K
kaisung
Hi,
I'm trying to write a Class which uses XML:
arser. XML:
arser 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:
arser;
sub new {
my $invocant = shift;
my $class = ref($invocant) || $invocant;
my $self = { @_ };
bless($self, $class);
return $self;
}
sub load {
my $parser = new XML:
arser(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
I'm trying to write a Class which uses XML:
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:
sub new {
my $invocant = shift;
my $class = ref($invocant) || $invocant;
my $self = { @_ };
bless($self, $class);
return $self;
}
sub load {
my $parser = new XML:
$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