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

HTML::Form warnings

From:
Ovid
Date:
December 3, 2003 10:28
Subject:
HTML::Form warnings
Message ID:
20031203182832.67545.qmail@web21503.mail.yahoo.com
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>/ &&
$self->{no_form_warnings};
      $self->_carp($message);
    };
    $self->{no_form_warnings};
  }

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 :)

Cheers,
Ovid

=====
Silence is Evil            http://users.easystreet.com/ovid/philosophy/indexdecency.htm
Ovid                       http://www.perlmonks.org/index.pl?node_id=17000
Web Programming with Perl  http://users.easystreet.com/ovid/cgi_course/

__________________________________
Do you Yahoo!?
Free Pop-Up Blocker - Get it now
http://companion.yahoo.com/



nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About