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

I need to understand the behavior of WWW::Mechanize.

If I "get" a URL in Mechanize and then "submit" that form, is the updated page now bound to the same mech variable?

I keep finding examples that use HTML::Response to work with the results of a submit so it's unclear to me if the Mechanize variable I do the initial submit with is updated or somehow stale after I submit it.

The issue I have is that I need to submit a page , get the response back and then submit the second page to confirm the transaction I'm trying to automate.

I'm wondering if I need to take the HTML::Response and somehow find a way to Submit it , or can I just verify the content of the original Mechanize variable after I submit it the first time and simply submit it again.

Thanks for any help - ShipMyPants

Replies are listed 'Best First'.
Re: Working with Mechinaze and Responses
by Anonymous Monk on Jul 28, 2013 at 21:21 UTC

    Does this answer your question ?

    #!/usr/bin/perl -- use WWW::Mechanize; use Data::Dumper; use strict; use warnings; my $res = $mech->get('http://example.com'); print int $res == $mech->res print int $res->status == $mech->res->status print int $res->status == $mech->status my $res2 = $mech->get('http://example.com/two'); print int $res == $mech->res print int $res->status == $mech->res->status print int $res->status == $mech->status print Dumper( { mech => $mech, rest => $res , rest2 => $res } ); __END__ #!/usr/bin/perl -- use WWW::Mechanize; use Data::Dumper; use strict; use warnings; my $mech = WWW::Mechanize->new; my $res = $mech->get('http://example.com'); print int $res == $mech->res; ## HELLO print int $res->code == $mech->res->code; print int $res->code == $mech->status ; my $res2 = $mech->get('http://example.com/two'); print int $res2 == $mech->res; ## HELLO print int $res2->code == $mech->res->code ; print int $res2->code == $mech->status; print "\n"; print Dumper( { mech => $mech }, { res1 => $res , res2 => $res } ); __END__ 111111 $VAR1 = { 'mech' => bless( { ... $VAR2 = { 'res1' => $VAR1->{'mech'}{'page_stack'}[0]{'res'}, 'res2' => $VAR1->{'mech'}{'page_stack'}[0]{'res'} };

    Like a regular browser, a stack of pages is kept, a history, so you can go forward or back

    Also Basic debugging checklist item 4 ( Dumper )