Subject: | $agent->back() does not work |
For WWW-Automate version 0.20.
The back() method on $agent objects does not seem to work as expected. It alters the state of $agent->{page_stack}, but $agent is otherwise unchanged, especially the current URI and page content.
This can be demonstrated with:
use WWW::Automate;
my $start_url = 'http://www.monash.edu.au/';
my $agent = WWW::Automate->new();
$agent->get( $start_url );
print $agent->{status} . ' ' . $agent->{uri} . "\n"; ## Page 1
$agent->follow( 2 );
print $agent->{status} . ' ' . $agent->{uri} . "\n"; ## Page 2
$agent->back();
print $agent->{status} . ' ' . $agent->{uri} . "\n"; ## Page 1 ??
Attached is a suggested patch to version 0.20 which fixes this problem. WWW::Automate::pop_page_stack() attempts to modify $self, but it should actually modify $_[0]. This also required a change from $self to $_[0] in WWW::Automate::back() as well.
Perl v5.6.1. Linux localhost.localdomain 2.4.18-19.7.xsmp #1 SMP Thu Dec 12 07:56:58 EST 2002 i686 unknown
291,292c291,293
< my $self = shift;
< $self->pop_page_stack;
---
> ## don't modify @_ here (using shift), as pop_page_stack needs to modify
> ## $_[0] so that the object is updated properly with its earlier clone.
> $_[0]->pop_page_stack;
365,368c366,368
< my $self = shift;
< if (@{$self->{page_stack}}) {
< $self = pop @{$self->{page_stack}};
< bless $self;
---
> if (@{$_[0]->{page_stack}}) {
> $_[0] = pop @{$_[0]->{page_stack}};
> bless $_[0];