Skip to content

Instantly share code, notes, and snippets.

@jjn1056
Created March 14, 2012 13:36
Show Gist options
  • Save jjn1056/2036529 to your computer and use it in GitHub Desktop.
Save jjn1056/2036529 to your computer and use it in GitHub Desktop.
package Shutterstock::Example::Nonblock;
use Web::Simple;
use Plack::App::File;
use File::ShareDir::ProjectDistDir;
use File::Spec::Functions;
use Imager::Simple;
sub share { our $share ||= dist_dir 'Shutterstock-Example-Nonblock' }
sub dispatch_request {
sub (/) {
Plack::App::File->new(file =>
catfile shift->share, 'html', 'index.html')},
sub (/static/...) {
Plack::App::File->new(root =>
catdir shift->share, 'static')},
sub (/img/*) {
my ($self, $id) = @_;
[sub {
my $w = (my $respond = shift)
->([ 200, ['Content-Type' => 'image/jpeg'] ]);
my $img = Imager::Simple
->read(catfile $self->share, 'data', "$id.jpg")
->scale(200, 200, 'min');
$w->write($img->data);
$w->close
}]
}
}
__PACKAGE__->run_if_script;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment