<?xml version="1.0" encoding="windows-1252"?>
<node id="929637" title="Re^3: What Tools Do You Use With WWW::Mechanize" created="2011-10-04 14:43:53" updated="2011-10-04 14:43:53">
<type id="11">
note</type>
<author id="180961">
Limbic~Region</author>
<data>
<field name="doctext">
[OfficeLinebacker],
&lt;br /&gt;
Have you seen [mod://WWW::Mechanize::Sleepy]?  Personally, I use something along the lines of:
&lt;CODE&gt;

# Sleep a random interval between $duration and 2 * $duration - 1 unit
sub rest {
    my ($duration) = @_;
    sleep $duration;
    sleep rand($duration);
}

sub fetch_page {
    my ($mech, $action, $target, $max, $duration) = @_;
    for (1 .. $max) {
        rest($duration);
        eval {$mech-&gt;$action($target);};
        return if ! $@ &amp;&amp; $mech-&gt;status == OK;
    }
    die "Failed to fetch '$url' after '$max' attempts\n";
}
&lt;/CODE&gt;
&lt;p&gt;
Of course, if you want to allow for HTTP redirects then you will need to change status == OK to include acceptable HTTP codes.  Additionally, if you use [mod://Time::HiRes] to overload [doc://sleep], you can easily sleep for partial minutes.  In truth, I typically use milliseconds.
&lt;/p&gt;
&lt;div class="pmsig"&gt;&lt;div class="pmsig-180961"&gt;
&lt;p&gt;
Cheers - [Limbic~Region|L~R]
&lt;/p&gt;
&lt;/div&gt;&lt;/div&gt;</field>
<field name="root_node">
929348</field>
<field name="parent_node">
929634</field>
</data>
</node>
