Aha!
Yes, it was trying to call something from HTML::Parser instead of the
method in my subclass. The error makes perfect sense in hindsight. Of
course, I made this one-line change and it works as expected now. Many
thanks, David.
In my attempts to orignally get around the problem, I had created a
closure that referenced the object in an attempt to use the method as the
call-back. For example,
I did this:
my $funcref = sub { $self->_findreq(@_); };
$self->handler( start => $funcref, 'tagname, attr' );
Unfortunately, this did not work either because I would receive the error
"Modification of a read-only value attempted at Sysweb/Templater/Required.pm
line 22." whenever I ran it. However, in this case, my logic seems sound
(i.e. I'm passing the method to the parser). Any ideas on these
idle-musings?
Thanks!
Kory Lasker
-----Original Message-----
From: David Dyck [mailto:[EMAIL PROTECTED]]
Sent: Monday, March 13, 2000 2:29 PM
To: Lasker Kory
Cc: '[EMAIL PROTECTED]'
Subject: RE: Subclassing HTML::Parser
On Mon, 13 Mar 2000, Lasker Kory wrote:
> I'm trying to use HTML::Parser 3.06 to subclass an object but keep
receiving
> a very frustrating error. It seems I cannot call a subclassed method
> against HTML::Parser without it complaining:
>
> Here's the object:
>
> package Sysweb::Templater::Required;
....
> sub new {
....
> $self->handler( start => "_findreq", 'tagname, attr' );
does this help
$self->handler( start => "_findreq", 'self,tagname, attr' );
# ^^^^^
.....
> sub _findreq {
> my ($self, $tagname, $attr) = @_;
# ^^^^^^
There's some code in report_event() in hparser.c that leads
me to think that it calls methods when "self" is an arg
otherwise it just calls the function, which it appears
by your error message is looking in HTML::Parser
instead of your package
if ((enum argcode)*argspec == ARG_SELF && !SvROK(h->cb)) {
char *method = SvPV(h->cb, my_na);
perl_call_method(method, G_DISCARD | G_VOID);
}
else {
perl_call_sv(h->cb, G_DISCARD | G_VOID);
}
In the Argspec section of the man page
`self'
Self causes the current object to be passed to the
handler. If the handler is a method, this must be the
first element in the argspec.