Plack::Middleware::Delay - Put delays on your requests
version 0.01
use Plack::Builder; builder { enable 'Delay', delay => 5; # delays the response by five seconds $app; }; # or, if you're in an AnyEvent-based PSGI server... builder { enable 'Delay', delay => 5, sleep_fn => sub { my ( $delay, $invoke ) = @_; my $timer; $timer = AnyEvent->timer( after => $delay, cb => sub { undef $timer; $invoke->(); }, ); }; $app; };
This middleware imposes an artifical delay on requests, for purposes of testing. It could also be used to implement http://xkcd.com/862/.
The number of seconds to sleep. It can be an integer or a float; however, the default sleep_fn only works on integers.
A subroutine reference that will be called when it's time to go to sleep. The subroutine reference will be provided two arguments: the number of seconds to sleep (ie. the value you provided to "delay"), and a subroutine reference that will continue the PSGI application as normal (think of it as a continuation).
Plack
Rob Hoelz <rob@hoelz.ro>
This software is copyright (c) 2011 by Rob Hoelz.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
Please report any bugs or feature requests on the bugtracker website http://github.com/hoelzro/plack-middleware-delay/issues
When submitting a bug or request, please include a test-file or a patch to an existing test-file that illustrates the bug or desired feature.
To install Plack::Middleware::Delay, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Plack::Middleware::Delay
CPAN shell
perl -MCPAN -e shell install Plack::Middleware::Delay
For more information on module installation, please visit the detailed CPAN module installation guide.