Acme-Urinal

 view release on metacpan or  search on metacpan

lib/Acme/Urinal.pm  view on Meta::CPAN

=head1 NAME

Acme::Urinal - assign resources using the same algorithm used by men choosing which urinal to use

=head1 SYNOPSIS

  use Acme::Urinal;

  my $urinals = Acme::Urinal->new(8);

  say $urinal->pick_one; # prints 1
  say $urinal->pick_one; # prints 3
  say $urinal->pick_one; # prints 5
  say $urinal->pick_one; # prints 7
  say $urinal->pick_one; # prints 2
  say $urinal->pick_one; # prints 4
  say $urinal->pick_one; # prints 6
  say $urinal->pick_one; # prints 0
  say $urinal->pick_one; # prints nothing, triggers an uninit warning

  $urinal->leave(3);
  $urinal->leave(4);
  say $urinal->pick_one; # prints 4

  $urinal->leave(2);
  $urinal->leave(1);
  say $urinal->pick_one; # prints 1


=head1 DESCRIPTION

When men use a bathroom with multiple urinals. The way the urinal to use is
chosen is nearly deterministic. This module allocates resources in a way that
emulates this process.

Basically, a L<Acme::Urinal> object keeps track of a list of resources. You can
then request these resources be allocated and used by asking for one using the



( run in 0.980 second using v1.01-cache-2.11-cpan-96521ef73a4 )