| 1 | # | ||||||||||
| 2 | # This file is part of Action-Retry | ||||||||||
| 3 | # | ||||||||||
| 4 | # This software is copyright (c) 2013 by Damien "dams" Krotkine. | ||||||||||
| 5 | # | ||||||||||
| 6 | # This is free software; you can redistribute it and/or modify it under | ||||||||||
| 7 | # the same terms as the Perl 5 programming language system itself. | ||||||||||
| 8 | # | ||||||||||
| 9 | package Action::Retry::Strategy::HelperRole::SleepCapping; | ||||||||||
| 10 | { | ||||||||||
| 11 | 1 | $Action::Retry::Strategy::HelperRole::SleepCapping::VERSION = '0.24'; | |||||||||
| 12 | } | ||||||||||
| 13 | |||||||||||
| 14 | # ABSTRACT: Helper to be consumed by Action::Retry Strategies, to enable capping the sleep time | ||||||||||
| 15 | |||||||||||
| 16 | 1 | ▶ | use Moo::Role; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 17 | |||||||||||
| 18 | 1 | ▶ | use List::Util qw(min); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 19 | |||||||||||
| 20 | has capped_sleep_time => ( | ||||||||||
| 21 | is => 'ro', | ||||||||||
| 22 | lazy => 1, | ||||||||||
| 23 | 0 | ▶ | default => sub { undef }, | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 24 | 1 | ); | |||||||||
| 25 | |||||||||||
| 26 | 0 | ▶ | around compute_sleep_time => sub { | ||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||
| 27 | 0 | my $orig = shift; | |||||||||
| 28 | 0 | my $self = shift; | |||||||||
| 29 | |||||||||||
| 30 | 0 | ▶ | return defined $self->capped_sleep_time | ||||||||
|
Branch: 1 branch
| |||||||||||
| 31 | ? min($orig->($self, @_), $self->capped_sleep_time) | ||||||||||
| 32 | : $orig->($self, @_); | ||||||||||
| 33 | |||||||||||
| 34 | 1 | }; | |||||||||
| 35 | |||||||||||
| 36 | 1 | 1; | |||||||||
| 37 | |||||||||||
| 38 | __END__ | ||||||||||