summaryrefslogtreecommitdiff
path: root/lib/Plack/Middleware/Throttle/Backend/Hash.pm
diff options
context:
space:
mode:
authorfranck cuny <franck@lumberjaph.net>2010-03-31 22:30:23 +0200
committerfranck cuny <franck@lumberjaph.net>2010-03-31 22:30:23 +0200
commit2a68ed3d0138827f4fed8a3520f7859493da4e1b (patch)
tree9cb12972b32952c45d920ac1c906aedc6416a8c6 /lib/Plack/Middleware/Throttle/Backend/Hash.pm
parentinitial commit (diff)
downloadplack-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.pm20
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;