WWW::Mechanize is a wonderful tool. However, there are all sorts of little things that I like to add that extend beyond what it's intended to do. Some of these issues are "Perl only" (such as Detecting stringified references with WWW::Mechanize), and others are more generic, such as detecting when an HTML entity has been encoded twice (e.g., & -- we had methods that shouldn't be encoding their output, but they did and then they got encoded again in Mason).

To deal with the double-encoding problem, I added a very simple line to my overloaded content() method (see above link):

if ($content =~ /(&(?:[lg]t|amp|quot);)/) { carp "Possible double-encoded HTML entity ($1) found in result +s"; }

However, I can think of several other potential issues I would like to check and make warnings for them optional by instantiating my subclass with a hashref and suppressing warnings that I don't want (maybe a page is trying to display HTML entity codes and wants them double-encoded):

my $mech = WWW::Mechanize::Warnings->new( stringified_references => 1, valid_dtd => 1, encoded_entities => 0, valid_html => 1, );

I think the warnings should be on by default, so only the "encoded_entities" key/value pair would be strictly necessary in the hypothetical constructor above.

What else would you want to see in such a module? If it's anything tricky, implementation ideas would be welcome.

Cheers,
Ovid

New address of my CGI Course.


In reply to Customizing WWW::Mechanize by Ovid

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.