completely rewind an HTML::TokeParser (PullParser)

Ashley Pond V <[email protected]>
Newsgroups gmane.comp.lang.perl.modules.lwp
Message-ID <[email protected]>
I want to parse out some HTML to count the text characters and then 
rewind to the beginning of the parser to step through tags and excerpt 
to an argument supplied character or percentage point in the *text* 
chars and then, keeping track of what tags are open, automatically add 
close tags.

To be used in a TT2 filter like "truncate" but for HTML instead of 
plain text. So that...

  [% html = "<p><b>this <i>is something to truncate</i></b></p>" %]
  [% html | truncate_html(10) %]

Would output
  <p><b>this <i>is so...</i></b></p>
  ^^^^^^12345^^^67890

Anyway, the trouble I'm trying to address is rewinding the parser for 
the second walkthrough once I've counted text characters.

I want to do this: 1 while $p->unget_token()

But it doesn't work because HTML::PullParser->unget_token returns the 
parser object itself.

To make a long story short, and it's not too late for that -- would 
changing the return be reasonable or would it break code?

  sub unget_token
  {
      my $self = shift;
      unshift @{$self->{pullparser_accum}}, @_;
  #    $self; <-- change, don't return $self anymore
  }

If not, does anyone have a smart idea for how to rewind it while 
respecting the interface (ie, not testing $self->{pullparser_accum})?

Thanks!
-Ashley
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.