Algorithm-TokenBucket
view release on metacpan or search on metacpan
The constructor requires at least the `rate of information` in items per
second and the `burst size` in items as its input parameters. It can also
take the current token counter and last check time but this usage is mostly
intended for restoring a saved bucket. See ["state()"](#state).
- state()
Returns the state of the bucket as a list. Use it for storing purposes.
Buckets also natively support freezing and thawing with [Storable](https://metacpan.org/pod/Storable) by
providing `STORABLE_*` callbacks.
- conform($)
This method returns true if the bucket contains at least _N_ tokens and
false otherwise. In the case that it is true, it is allowed to transmit or
process _N_ items (not exactly right because _N_ can be fractional) from
the stream. A bucket never conforms to an _N_ greater than `burst size`.
- count($)
lib/Algorithm/TokenBucket.pm view on Meta::CPAN
$self->{_last_check_time} ||= time;
$self->{_tokens} ||= 0;
return $self;
}
=item state()
Returns the state of the bucket as a list. Use it for storing purposes.
Buckets also natively support freezing and thawing with L<Storable> by
providing C<STORABLE_*> callbacks.
=cut
sub state {
my Algorithm::TokenBucket $self = shift;
return @$self{qw/info_rate burst_size _tokens _last_check_time/};
}
use constant PACK_FORMAT => "d4"; # "F4" is not 5.6 compatible
( run in 1.050 second using v1.01-cache-2.11-cpan-10033ea8487 )