develooper Front page | perl.libwww | Postings from December 2003

HTML::Form warnings

December 3, 2003 10:28
HTML::Form warnings
Message ID:
Hi all,

I sometimes gets <$tag> outside <form> warnings when using HTML::Form
(via WWW::Mechanize).

The code in HTML::Form that issues this warning is:

    Carp::carp("<$tag> outside <form>") if $^W;

The problem is, if I suppress this warning, I have to suppress all
warnings and I'd rather not do that.

When HTML::Form parses our HTML, we have many form elements that are
handled by JavaScript (redirect with select boxes, for example), and we
get these warnings all over the place.  For the time being, I have a
hack that allows me to turn this warning off or on as needed by
overriding carp().

I considered a submitting a patch to HTML::Form to allow this warning
to be optional, but I'm not sure if this is desired or, if so, what
would be an appropriate patch.  In my current code, I suppress it with:

  sub no_form_warnings {
    my ($self, $warnings) = @_;
    $warnings = 1 unless defined $warnings;
    $self->{no_form_warnings} = $warnings;

    no warnings 'redefine';
    *Carp::carp =  sub {
      my $message = shift;
      return if $message =~ /<[^>]+> outside <form>/ &&

I think that's a rather ugly hack that I'm terrified my future children
might uncover this some day.  Please help save me from disgrace :)


Silence is Evil  
Web Programming with Perl

Do you Yahoo!?
Free Pop-Up Blocker - Get it now Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About