summary refs log tree commit diff
path: root/lib/Plack/Middleware/Throttle/Hourly.pm
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Plack/Middleware/Throttle/Hourly.pm')
-rw-r--r--lib/Plack/Middleware/Throttle/Hourly.pm17
1 files changed, 17 insertions, 0 deletions
diff --git a/lib/Plack/Middleware/Throttle/Hourly.pm b/lib/Plack/Middleware/Throttle/Hourly.pm
new file mode 100644
index 0000000..818d70b
--- /dev/null
+++ b/lib/Plack/Middleware/Throttle/Hourly.pm
@@ -0,0 +1,17 @@
+package Plack::Middleware::Throttle::Hourly;
+
+use Moose;
+extends 'Plack::Middleware::Throttle::Limiter';
+
+sub cache_key {
+    my ( $self, $env ) = @_;
+    $self->client_identifier($env) . "_"
+        . DateTime->now->strftime("%Y-%m-%d-%H");
+}
+
+sub reset_time {
+    my $dt = DateTime->now;
+    3600 - (( 60 * $dt->minute ) + $dt->second);
+}
+
+1;