Add a value. You can add NOT already value. Returned value is 1 or 0, but if error is undef.
use Test::More;
my $dwr = Data::WeightedRoundRobin->new([qw/foo bar/]);
is $dwr->add('baz'), 1, 'added baz';
is $dwr->add('foo'), 0, 'foo is exists';
is $dwr->add({ value => 'hoge', weight => 80 }), 1, 'added hoge with weight 80';
is $dwr->add(), undef, 'error';
- `replace($value:SCALAR || $value::HASHREF)`
Replace a value. Returned value is 1 or 0, but if error is undef.
use Test::More;
my $dwr = Data::WeightedRoundRobin->new([qw/foo/, { value => 'bar', weight => 50 }]);
is $dwr->replace('baz'), 1, 'replaced bar';
is $dwr->replace('hoge'), 0, 'hoge is not found';
is $dwr->replace({ value => 'foo', weight => 80 }), 1, 'replaced foo with weight 80';
is $dwr->replace(), undef, 'error';
- `remove($value:SCALAR)`
Remove a value. Returned value is 1 or 0, but if error is undef.
use Test::More;
my $dwr = Data::WeightedRoundRobin->new([qw/foo bar/]);
is $dwr->remove('foo'), 1, 'removed foo';
is $dwr->remove('hoge'), 0, 'hoge is not found';
is $dwr->remove(), undef, 'error';
- `save()`
When destroyed `$guard` is gone, will return to the saved state.
my $dwr = Data::WeightedRoundRobin->new([qw/foo bar/]);
{
my $guard = $drw->save;
$drw->remove('foo');
is $drw->next, 'bar';
}
# return to saved state
my $data = $dwr->next; # foo or bar
# AUTHOR
xaicron <xaicron {at} cpan.org>
# COPYRIGHT
Copyright 2011 - xaicron
# LICENSE
This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.