package MyMech; use WWW::Mechanize; our @ISA = "WWW::Mechanize"; sub _wrapped { my $self = shift; my $method = "SUPER::".shift; my $result; RETRY: for (1..3) { eval { $result = $self->$method(@_); }; if ($@) { warn gmtime(time).": $@"; $result = undef; # just in case sleep 5; } else { last RETRY; } } return $result; } sub get { shift->_wrapped('get', @_) } sub put { shift->_wrapped('put', @_) } # ... #### #!/usr/bin/perl use MyMech; my $mech = MyMech->new(autocheck => 1); my $resp = $mech->get("http://localhost:9999/foo"); # ... __END__ Mon Oct 12 19:32:48 2009: Error GETing http://localhost:9999/foo: Can't connect to localhost:9999 (connect: Connection refused) at ./800725.pl line 7 Mon Oct 12 19:32:53 2009: Error GETing http://localhost:9999/foo: Can't connect to localhost:9999 (connect: Connection refused) at ./800725.pl line 7 Mon Oct 12 19:32:58 2009: Error GETing http://localhost:9999/foo: Can't connect to localhost:9999 (connect: Connection refused) at ./800725.pl line 7