Skip to content

Instantly share code, notes, and snippets.

@mix3
Created March 7, 2013 17:16
Show Gist options
  • Save mix3/5109843 to your computer and use it in GitHub Desktop.
Save mix3/5109843 to your computer and use it in GitHub Desktop.
Plack::App::Directoryで(gif|png|jpe?g)を展開するだけ
package Plack::App::Directory::ImageView;
use parent qw(Plack::App::Directory);
sub serve_path {
my($self, $env, $dir, $fullpath) = @_;
my $ret = $self->SUPER::serve_path($env, $dir, $fullpath);
return $ret if (ref($ret->[2]) eq 'Plack::Util::IOWithPath');
$ret->[2][0] =~ s/<a href='(.+?)'>(.+?)\.(gif|png|jpe?g)<\/a>/<a href='\1'><img src='\1' \/><\/a><br \/>\2\.\3/g;
$ret;
}
1;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment