Important update: I forgot one of the most important points about this module. Like CGI::Safe, it's a drop-in replacement. You can use this in place of HTML::TokeParser and it's completely transparent. Then, just use the new methods where you feel the need to get the greater clarity. This simplifies migration to this module.
Update 2: crazyinsomniac is right: the AUTOLOAD has got to go. When the methods were simple, the AUTOLOAD sort of made sense. Now, however, I need to overload a couple of them and even pulling them out and refactoring the rest into an AUTOLOAD just doesn't have enough benefit to justify the obfuscation value. Darn it. If anyone else had written this, I would have been the first to point that out. How reluctant we are to admit that our children are ugly :)
After prompting from a couple of monks, I finally got off my duff and finished up the HTML::TokeParser::Easy module. This is basically an adaptor for HTML::TokeParser that makes the module easier to use (no more memorizing array indices). For example, with HTML::TokeParser, if you want to find out if a token returned from get_token() is a start token and a form token, you would do this:
if ( $token->[0] eq 'S' and $token->[1] eq 'form' ){...}
Now, you just do this:
if ( $token->is_start_tag( 'form' ) ){...}
Is a token a comment?
if ( $token->is_comment ){...}
That was originally $token->[0] eq 'C'.
Need the attributes of a given token?
my $attributes = $token->attr;
That code was $token->[3], or $token->[2], depending upon how you generated the token. Now, it's one standard method.
If this interests you and you use HTML::TokeParser, please download and test the distribution. I haven't written the tests yet, but I won't upload to the CPAN without them. I at least managed to get POD written up :)
Cheers,
Ovid
Join the Perlmonks Setiathome Group or just click on the the link and check out our stats.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
(crazyinsomniac : a request) Re: RFC: HTML::TokeParser::Easy
by crazyinsomniac (Prior) on Mar 02, 2002 at 01:36 UTC | |
by Ovid (Cardinal) on Mar 02, 2002 at 03:25 UTC | |
|
Re: RFC: HTML::TokeParser::Easy
by theguvnor (Chaplain) on Mar 02, 2002 at 06:39 UTC | |
by Ovid (Cardinal) on Mar 02, 2002 at 07:09 UTC |