Skip to content

Commit

Permalink
Merge pull request #1 from koba04/nomaxrate
Browse files Browse the repository at this point in the history
Sub::Rate::NoMaxRate accept a value bigger than max rate
  • Loading branch information
typester committed Dec 6, 2012
2 parents c709469 + 9979aff commit 95c98f1
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
9 changes: 9 additions & 0 deletions lib/Sub/Rate/NoMaxRate.pm
Expand Up @@ -7,6 +7,15 @@ use List::Util 'sum';

extends 'Sub::Rate';

before add => sub {
my ($self, $rate) = @_;

my $max_rate = sum map { $_->[0] } @{ $self->_func };
$max_rate += $rate;
$self->max_rate($max_rate);
};


before generate => sub {
my ($self) = @_;

Expand Down
5 changes: 5 additions & 0 deletions t/nomaxrate.t
Expand Up @@ -22,4 +22,9 @@ is $loop_count, $r1 + $r2, 'loop count same as $r1 + $r2';

ok 2.0*0.95 <= $r2 / $r1 && $r2 / $r1 <= 2.0*1.05, '$r2/$1 about 20/10 ok';

$sub->clear;

eval { $sub->add(1000 => sub {}) };
ok !$@, 'no error ok (over default max_rate)';

done_testing;

0 comments on commit 95c98f1

Please sign in to comment.