1# $Id: /mirror/gungho/lib/Gungho/Component/Throttle/Simple.pm 31301 2007-11-29T11:51:44.807693Z lestrrat $ 2# 3# Copyright (c) 2007 Daisuke Maki <daisuke@endeworks.jp> 4# All rights reserved. 5 6package Gungho::Component::Throttle::Simple; 7use strict; 8use warnings; 9use base qw(Gungho::Component::Throttle::Throttler); 10 11sub setup 12{ 13 my $self = shift; 14 15 my $config = $self->config->{throttle}{simple}; 16 17 $self->prepare_throttler( 18 map { ($_ => $config->{$_}) } 19 qw(max_items interval db_file throttler cache) 20 ); 21 $self->next::method(@_); 22} 23 24sub throttle 25{ 26 my $c = shift; 27 my $request = shift; 28 my $t = $c->throttler; 29 30 if ( ! $t->try_push() ) { 31 $c->log->debug("[THROTTLE] " . $request->uri . " throttled by Throttle::Simple"); 32 return (); 33 } 34 35 return $c->next::method($request); 36} 37 381; 39 40__END__ 41 42=head1 NAME 43 44Gungho::Component::Throttle::Simple - Throttle By Number Of Requests 45 46=head1 SYNOPSIS 47 48 --- 49 throttle: 50 simple: 51 max_items 1000 52 interval: 3600 53 components: 54 - Throttle::Simple 55 56=head1 METHODS 57 58=head2 setup 59 60=head2 throttle($request) 61 62Checks if a request can be executed succesfully. Returns 1 if it's ok to 63execute the request. 64 65=cut 66