Subject: | New method wrapper |
Date: | Mon, 08 Oct 2007 17:02:39 +0100 |
To: | bug-Test-WWW-Mechanize [...] rt.cpan.org |
From: | Greg Sheard <greg.sheard [...] wcn.co.uk> |
Inspired by get_ok(), this is its counterpart, post_ok(). Patch attached
against 1.14.
--
Greg Sheard <greg.sheard@wcn.co.uk>
Not speaking for WCN plc in any way.
#include "long_disclaimer.h"
--- Mechanize.pm.orig 2007-10-08 16:31:10.000000000 +0100
+++ Mechanize.pm 2007-10-08 16:31:35.000000000 +0100
@@ -124,6 +124,51 @@
return $ok;
}
+=head2 $mech->post_ok($url, [ \%LWP_options ,] $desc)
+
+A wrapper around WWW::Mechanize's post(), with similar options, except
+the second argument needs to be a hash reference, not a hash. Like
+well-behaved C<*_ok()> functions, it returns true if the test passed,
+or false if not.
+
+=cut
+sub post_ok {
+ my $self = shift;
+ my $url = shift;
+
+ my $desc;
+ my %opts;
+
+ if ( @_ ) {
+ my $flex = shift; # The flexible argument
+
+ if ( !defined( $flex ) ) {
+ $desc = shift;
+ }
+ elsif ( ref $flex eq 'HASH' ) {
+ %opts = %$flex;
+ $desc = shift;
+ }
+ elsif ( ref $flex eq 'ARRAY' ) {
+ %opts = @$flex;
+ $desc = shift;
+ }
+ else {
+ $desc = $flex;
+ }
+ } # parms left
+
+ $self->post( $url, \%opts );
+ my $ok = $self->success;
+ $Test->ok( $ok, $desc );
+ if ( !$ok ) {
+ $Test->diag( $self->status );
+ $Test->diag( $self->response->message ) if $self->response;
+ }
+
+ return $ok;
+}
+
=head2 $mech->title_is( $str [, $desc ] )
Tells if the title of the page is the given string.