Pug has asked for the wisdom of the Perl Monks concerning the following question:

I am writing code that tests html pages and the server's internal responses. I am using HTML::Form to parse the html file and to set up the input. I want to be able to give an invalid value to an input type called option, which is a drop down box.

The problem is that HTML::Form croaks when given invalid value for that input type. For example the list of possible inputs is
MPI
ACS
DS
AHS

I want to be able to say for this input give it the value of "NONE" but HTML::Form croaks when I do that.8(

How do I get around this and make HTML::Form take invalid values in a reletivaly nice way?

I have used SuperSearch looking for HTML::Form and Croak with no luck. The perldoc Carp does not really point to anything and the perldocs for HTML::Form says that it will croak if given invalid input. I have thought about redefing the function to get what I want but I am not too sure if doing this will break when/if the next version of HTML::Form comes out.

Replies are listed 'Best First'.
Re: a HTML::Form question.
by Sinister (Friar) on Feb 28, 2002 at 19:22 UTC
    You could try to write your own class which uses HTML::Form as a base class.
    You'll need something like:
    package Invalid; use base qw(HTML::Form); use strict; # || loose(XP); sub new { my $class = ref($_[0]) || $_[0]; shift; my $self = $class->SUPER::new(@_); return(bless($self,$class)); } sub your_overwritten_routine { my $self = shift; ... and the rest of your code ... return $something; } "True value";
    This way you can still be using all your code, you'll just have to 'use Invalid' instead of 'use HTML::Form' and do a 'Invalid->new(...)' instead of 'HTML::Form->new(...)'.

    If a new version of HTML::Form ever comes out - nothing 'bad' happens...

    Hope this any good.

    Sinister greetings.
    "With tying hashes you can do everything God and Larry have forbidden" -- Johan Vromans - YAPC::Europe 2001
    perldoc -q $_
      Thanks that fixed the problem.
Re: a HTML::Form question.
by Pug (Monk) on Feb 28, 2002 at 19:13 UTC
    here is the code in question
    sub _goto_action_page my ($self, $type, $action)=@_; my ($response, $num, $form, $input); if(!exists $self->{MAIN_RESPONSE}) { return _error($self," some error message here"); } $response=$self->{MAIN_RESPONSE}; $num=0; $form=_get_new_form($self,$response->as_string, $response->base); foreach $input ($form->inputs()) { if($input->name eq "componentType") { #croaks here if $type is not eq to ACS, MPI, DS, # AHS. $input->value($type); $num++; } }