NAME
WWW::Mechanize::Sleepy - A Sleepy Mechanize Agent
SYNOPSIS
use WWW::Mechanize::Sleepy;
# sleep 5 seconds between requests
my $a = WWW::Mechanize::Sleepy->new( sleep => 5 );
$a->get( 'http://www.cpan.org' );
# sleep between 5 and 20 seconds between requests
my $a = WWW::Mechanize::Sleepy->new( sleep => '5..20' );
$a->get( 'http://www.cpan.org' );
# don't sleep at all
my $a = WWW::Mechanize::Sleepy->new();
$a->get( 'http://www.cpan.org' );
DESCRIPTION
Sometimes when testing the behavior of a webserver it is important to be able to space out your requests in order to simulate a person reading, thinking (or sleeping) at the keyboard.
WWW::Mechanize::Sleepy subclasses WWW::Mechanize to provide pauses between your server requests. Use it just like you would use WWW::Mechanize.
METHODS
All the methods are the same as WWW::Mechanize, except for the constructor which accepts an additional parameter.
new()
The constructor which acts just like the WWW::Mechanize constructor except you can pass it an extra parameter.
sleep
An amount of time in seconds to sleep.
my $a = WWW::Mechanize::Sleepy->new( sleep => 5 );
Or a range of time to sleep within. Your robot will sleep a random amount of time within that range.
my $a = WWW::Mechanize::Sleepy->new( sleep => '5..20' );
If you would like to have a non sleeping WWW::Mechanize object, you can simply not pass in the sleep paramter.
my $a = WWW::Mechanize::Sleepy->new();
Note: since WWW::Mechanize::Sleepy subclasses WWW::Mechanize, which subclasses LWP::UserAgent, you can pass in LWP::UserAgent::new() options to WWW::Mechanize::Sleepy::new().
my $a = WWW::Mechanize::Sleepy->new(
agent => 'foobar agent',
timeout => 100
);
sleep()
If you want to get or set your object's sleep value on the fly use sleep().
my $a = WWW::Mechanize::Sleepy->new( sleep => '1..3' );
...
print "currently sleeping ", $a->sleep(), " seconds\n";
$a->sleep( '4..6' );
If you want to make your WWW::Mechanize::Sleepy object no longer sleepy just set to 0.
$a->sleep( 0 );
AUTHOR/MAINTAINER
WWW::Mechanize::Sleepy was originally written in 2003 by Ed Summers (ehs@pobox.com). Since version 0.7 (September 2010) it has been maintained by Kostas Ntonas (kntonas@gmail.com).
SEE ALSO
LICENSE
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.