Skip to content

Instantly share code, notes, and snippets.

@zby
Created December 23, 2010 09:05
Show Gist options
  • Save zby/752761 to your computer and use it in GitHub Desktop.
Save zby/752761 to your computer and use it in GitHub Desktop.
Constructing a Plack app with images search path and sessions
around psgi_callback => sub {
my $orig = shift;
my $self = shift;
my $cascade = Plack::App::Cascade->new;
my $favicon_c = Plack::App::Cascade->new;
for my $root ( $self->static_roots ){
$cascade->add( Plack::App::File->new(root => $root )->to_app );
$favicon_c->add( Plack::App::File->new( file => "$root/images/favicon.ico" )->to_app );
};
my $app = Plack::App::URLMap->new;
$app->map( '/static', $cascade );
$app->map( '/favicon.ico', $favicon_c );
$app->map( '/', $self->$orig( @_ ) );
return Plack::Middleware::Session->wrap(
$app->to_app,
store => Plack::Session::Store::Cache->new(
cache => CHI->new(driver => 'FastMmap')
)
);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment