Created
March 14, 2012 13:36
-
-
Save jjn1056/2036529 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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