[Bath-pm] OO / global instance variable
Andrew McGregor
andy at pasty.org.uk
Tue May 24 09:14:44 PDT 2005
Hi,
An OO question.
If I have an instance of an object:
my $ins = My::Obj->new();
Which does a job:
$ins->read_xml();
in turn triggers the event:
handle_char_data();
How can I get $text into the anonymous hash referened by $self?
Regards,
Andy
package My::Obj;
use XML::Parser;
sub handle_char_data {
my ($expat, $text);
# how do I populate $self{text} with $text
}
sub new {
my ($this, %params) = @_;
my $class = ref($this) || $this;
my $self = {};
$self->{parser} = XML::Parser->new ( Handlers => {
Char => \&handle_char_data,
} );
bless $self, $class;
return $self;
}
sub read_xml {
my $this = shift;
my $xml = <STDIN>;
$this->{parser}->parse($xml);
}
1;
More information about the Bath-pm
mailing list