WWW::Mechanize::Sleepy - A Sleepy Mechanize Agent
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' );
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.
All the methods are the same as WWW::Mechanize, except for the constructor which accepts an additional parameter.
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 );
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 );
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).
WWW::Mechanize
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
To install WWW::Mechanize::Sleepy, copy and paste the appropriate command in to your terminal.
cpanm
cpanm WWW::Mechanize::Sleepy
CPAN shell
perl -MCPAN -e shell install WWW::Mechanize::Sleepy
For more information on module installation, please visit the detailed CPAN module installation guide.