Re: Subclassing HTML::Parser to support $p->include()

Gisle Aas <[email protected]>
Newsgroups gmane.comp.lang.perl.modules.lwp
Message-ID <[email protected]>
Andy Armstrong <[email protected]> writes:

> For that to work I have to rely on HTML::Parser issuing a tag
> callback as soon as it sees the closing character of a tag - if it
> reads ahead then it will have already digested text beyond the
> <include /> tag by the time it issues the callback for the <include /
> > tage.
> 
> I can easily check what the current behaviour is - and I shall - but
> there's no contract that I can see about the relationship between the
> text that HTML::Parser has read via a callback and when the handlers
> trigger. So even if it works now it could potentially change in the
> future - I don't want to rely on undocumented behaviour.
> 
> So, is what I'm proposing sensible?

Seems so to me.  You can depend on any complete tag to be reported
before $p->parse(), passing in the corresponding text, returns.  This
is implicitly documented by the description of $p->eof that says that
its effect is to flush any remaining _text_.

One caveat is that your tag will not be recognized inside tags that
force literal text content.  For instance:

   <textarea>
     <include />
   </textarea>

Here <include /> will be parsed as text whatever you do.

--Gisle
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.