Skip to content

Instantly share code, notes, and snippets.

@cho45
Created July 20, 2010 11:34
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cho45/482846 to your computer and use it in GitHub Desktop.
Save cho45/482846 to your computer and use it in GitHub Desktop.
package Plack::Middleware::Random;
use strict;
use warnings;
use parent qw(Plack::Middleware);
use POSIX qw(floor);
my $known_requests = [];
sub call {
my ($self, $env) = @_;
push @$known_requests, $env;
shift @$known_requests while (@$known_requests > 50);
$env = $known_requests->[floor(@$known_requests * rand())];
$self->app->($env);
}
1;
__END__
=head1 NAME
Plack::Middleware::Random - serve contents randomly
=head1 SYNOPSIS
use Plack::Builder;
builder {
enable "Plack::Middleware::Random"; # write this first
enable "Plack::Middleware::Static",
path => qr{^/(images|js|css)/}, root => './htdocs/';
$app;
};
=back
=head1 AUTHOR
cho45
=head1 SEE ALSO
L<Plack::Middleware> L<Plack::Builder>
=cut
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment