Skip to content

Instantly share code, notes, and snippets.

@j1n3l0
Created October 8, 2018 11:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save j1n3l0/7d60f25e9f9dc5a6a3c21e25b083d2b6 to your computer and use it in GitHub Desktop.
Save j1n3l0/7d60f25e9f9dc5a6a3c21e25b083d2b6 to your computer and use it in GitHub Desktop.
use 5.026;
use Test::Most;
{
package Process;
use Moo;
has state => ( is => 'ro', lazy => 1, default => sub { { } } );
sub at_max_retries { $_[0]->state->{retries} // 0 >= 10 }
sub retry { $_[0]->state->{retries}++ }
}
my $process = new_ok Process => [];
cmp_methods(
$process,
[
at_max_retries => bool(0),
state => { },
],
'not yet at max retries and state is empty',
);
$process->retry for 1 .. 10;
cmp_methods(
$process,
[
at_max_retries => bool(1),
state => { retries => 10 },
],
'at max retries and state contains retries',
);
done_testing;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment