Wouldn't it be useful to be able to give a maximum depth for the page stack? This way, when someone writes a bot that runs for a long time and never calls back(), the script does not eat up all the memory.
Attached is a patch proposal against 0.72.
-- BooK
--- WWW-Mechanize-0.72/lib/WWW/Mechanize.pm 2004-01-13 05:36:36.000000000 +0100
+++ WWW-Mechanize/lib/WWW/Mechanize.pm 2004-02-16 13:17:30.000000000 +0100
@@ -238,6 +238,11 @@
Don't complain on warnings. Setting C<< quiet => 1 >> is the same as
calling C<< $agent->quiet(1) >>. Default is off.
+=item * C<< stack_depth => $value >>
+
+Sets the depth of the page stack that keeps tracks of all teh downloaded
+pages. Default is -1 (infinite).
+
=back
=cut
@@ -255,6 +260,7 @@
onwarn => \&WWW::Mechanize::_warn,
onerror => \&WWW::Mechanize::_die,
quiet => 0,
+ stack_depth => -1,
);
my %passed_parms = @_;
@@ -1134,6 +1140,21 @@
return $self->{quiet};
}
+=head2 $mech->stack_depth($value)
+
+Get or set the page stack depth. Older pages are discarded first.
+
+A negative value means "keep all the pages".
+
+=cut
+
+sub stack_depth {
+ my $self = shift;
+ my $old = $self->{stack_depth};
+ $self->{stack_depth} = shift if @_;
+ return $old;
+}
+
=head1 Overridden L<LWP::UserAgent> methods
=head2 $mech->redirect_ok()
@@ -1402,6 +1423,8 @@
$self->{page_stack} = [];
push( @$save_stack, $self->clone );
+ shift @$save_stack if $self->stack_depth >= 0
+ and @$save_stack > $self->stack_depth;
$self->{page_stack} = $save_stack;
}