Ineffectual has asked for the wisdom of the Perl Monks concerning the following question:
use WWW::Mechanize; use Test::More qw /no_plan/; my $base = 'myuri'; # fake value my $mech = WWW::Mechanize->new; my $form_name = 'searchform'; my $field_name = 'search'; my $term = ''; $mech->get($base); $mech->submit_form( form_name => $form_name, fields => { $field_name => $term}, ); ok($mech->status == 400,'empty searches should have a 400 status'); ok($mech->content =~ /no search term/i, 'and a chide about having no s +earch term');
The page rendering is complicated (of course) but works just fine in a web browser. The confess is to make sure that the chide that got called (likely in the middle of another perl module) prevents that perl module from continuing to process.sub chide { my $self = shift; my $chide_msg = shift; $chide_msg=~s/\n/<br>/gm; # "\n"'s can sometimes totally confuse + the headers; weird, but true my $page_title = shift; warn __PACKAGE__,"::error_page:chide: msg is '$chide_msg'" if $EN +V{DEBUG}; $self->_vars->{page_template} = $self->_vars->{chide_template}; $self->_vars->{chiding} = $chide_msg; $self->_vars->{page_title} = $page_title if $page_title; $self->_vars->{status} = "400 $chide_msg "; # HTTP status code 400 + = 'Bad Request' $self->process; confess $chide_msg if $self->exit_on_error; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: WWW::Mechanize version differences with confess
by jbt (Chaplain) on Aug 04, 2009 at 02:27 UTC | |
by Ineffectual (Scribe) on Aug 04, 2009 at 20:20 UTC |