Re: [PATCH]HTML::Parser-XS-2.9913_mac-1
Michael A. Chase (mchase@ix.netcom.com)
Thu, 25 Nov 1999 07:05:13 -0800
Does this mean new() can't be used to define callbacks? That actually may
not be a bad idea since they do complicate the explanation and code. On the
other hand, being able to set everything up in the constructor is handy,
too.
--
Mac :})
----- Original Message -----
From: Gisle Aas <gisle@aas.no>
To: Michael A. Chase <mchase@ix.netcom.com>
Cc: libwww <libwww@perl.org>
Sent: 11/25/99 5:21
Subject: Re: [PATCH]HTML::Parser-XS-2.9913_mac-1
> BTW, I have decided that I want to modify the new callback interface.
> The main new thing is that you should always tell the parser what
> arguments you want the parser to pass to the callback handlers.
>
> Example:
>
> $p->callback(start => "self,tagname,line", sub { ... });
How about
$p->callback(start => [qw(self tagname line), sub { ... }]);
Options could appear in any order. Any keywords found would set options or
enable parameters to the callback and a coderef would be saved as the
callback. Any arguments to the coderef would always be in the same order,
just some arguments might be left out.
You wouldn't necessarily have to abandon $p->accum, it would just take the
same options as callback. Or it could be invoked if an array reference is
one of the elements provided:
$p->callback( declaration => [ qw(tagname tokens_arrayref), \@accum ] );
> This would set up a callback for start tags and tell the parser that
> it should pass $p, the name of the tag and the line number where the
> tag starts to the subroutine given.
>
> The argspec allows me to get rid of several of the new parser options
> (decode_text_entities, v2_compat, pass_self, attr_pos) and allow
> further optimizations as we don't have to build the stuff to
> represents arguments that the parser user don't need. The interface
> also become much easier extensible.
>
> The things that I think can go into argspec are:
>
> self
> tagname (element_name, gi)
> origtext
> decodedtext
> cdata_flag
> attr_arrayref
> attrpos_arrayref
> attr_hashref
> attrpos_hashref
> tokens_arrayref
> tokens # separate arguments (tagname @$attr_arrayref)
> charpos
> line
>
> Does anybody have some other ideas of how the argspec interface might
> look? An array? Just peek at the prototype of the callback function?
v2_compat (equivilant to qw( self tagname attr_arrayref attr_hashref
origtext ) )
If no keywords are given, it should be equivilant to qw( tagname
tokens_arrayref origtext ) or whatever is finally agreed on.
> This stuff probably also mean that the $p->accum() stuff should go.
> One idea would be to allow a array ref as the third $p->callback
> argument and then push stuff instead of doing a call.