diff options
| author | franck cuny <franck@lumberjaph.net> | 2010-03-31 22:30:23 +0200 |
|---|---|---|
| committer | franck cuny <franck@lumberjaph.net> | 2010-03-31 22:30:23 +0200 |
| commit | 2a68ed3d0138827f4fed8a3520f7859493da4e1b (patch) | |
| tree | 9cb12972b32952c45d920ac1c906aedc6416a8c6 /lib/Plack/Middleware/Throttle/Backend/Hash.pm | |
| parent | initial commit (diff) | |
| download | plack-middleware-throttle-2a68ed3d0138827f4fed8a3520f7859493da4e1b.tar.gz | |
import old Plack::Middleware::APIRateLimit (renamed as miyagawa's suggestion) and stole API from rack::throttle
Diffstat (limited to '')
| -rw-r--r-- | lib/Plack/Middleware/Throttle/Backend/Hash.pm | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/lib/Plack/Middleware/Throttle/Backend/Hash.pm b/lib/Plack/Middleware/Throttle/Backend/Hash.pm new file mode 100644 index 0000000..9144e36 --- /dev/null +++ b/lib/Plack/Middleware/Throttle/Backend/Hash.pm @@ -0,0 +1,20 @@ +package Plack::Middleware::Throttle::Backend::Hash; + +use Moose; + +has store => ( + is => 'rw', + isa => 'HashRef', + traits => ['Hash'], + lazy => 1, + default => sub { {} }, + handles => { get => 'get', set => 'set' } +); + +sub incr { + my ( $self, $key ) = @_; + my $value = ( $self->get($key) || 0 ) + 1; + $self->set( $key => $value ); +} + +1; |
