Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Is it ok to use Attribute::Handlers for implementing retry logic I have almost 50+ subroutine like verifyXXXX. I need to implement the retry logic for all these subs. I want to write this retry logic where the sub is actually implemented. If the return value of sub is false/undef then it will retry again. subs will be called in regular way, so that the caller will not know about the retry logic, something like.
verify_am_i_doing_good() or die('sorry you are not doing as expected.'); verify_am_i_fine() or die ('sorry you are not find.'); : :
the actual implementation of these functions is something like this in the package.
use Attribute::Handlers; use constant RETRY_LIMIT => 4; use constant RETRY_DELAY => 2; sub verify_am_i_doing_good : __retry { return 1 if ($x == $y); return; } sub __retry : ATTR(CODE) { my ($pkg, $sym, $code) = @_; my $name = *{ $sym }{NAME}; no warnings 'redefine'; *{ $sym } = sub { my $self = $_[0]; my $result; logMsg (INFO, "Executing subroutine $name with retry limit + " . RETRY_LIMIT); for (my $retryCount = 1; $retryCount <= RETRY_LIMIT; $retr +yCount++) { logMsg (INFO, "Executing subroutine $name with retry c +ount $retryCount"); my $result = $code->( @_ ); if ($result) { logMsg (INFO, "Expected result observed in retry c +ount $retryCount"); return wantarray ? @$result : $result; } else { logMsg (INFO, "Expected result is NOT observed in +retry count $retryCount"); logMsg (INFO, "Retrying again by updating uixml"); sleep RETRY_DELAY; $self->updateState(); } } logMsg (WARN, "Failed to verify expected result for subrou +tine $name with retry limit " . RETRY_LIMIT); return; }; }

The reason to use Attribute::Handlers, inplace of Attribute::Attempts is that in the case of failure, I need to call another subroutine `updateState()` before retrying (re-executing) the subroutine.

I got this idea of writing the retry logic from following post http://www.perl.com/pub/2007/04/12/lightning-four.html

My main concern is that since I am using this __retry attribute for almost 50+ subs. Is it a good practice to do in this way or is there anything simple I can do?

You help will be highly appreciated.