first draft psgi middleware support complete
[catagits/Catalyst-Runtime.git] / t / lib / TestMiddleware.pm
1 package TestMiddleware;
2
3 use Moose;
4 use Plack::Middleware::Static;
5 use Plack::App::File;
6 use Catalyst;
7
8 extends 'Catalyst';
9
10 my $static = Plack::Middleware::Static->new(
11   path => qr{^/static/}, root => TestMiddleware->path_to('share'));
12
13 __PACKAGE__->config(
14   'Controller::Root', { namespace => '' },
15   'psgi_middleware', [
16     'Head',
17     $static,
18     'Static', { path => qr{^/static2/}, root => TestMiddleware->path_to('share') },
19     'Runtime',
20     '+TestMiddleware::Custom', { path => qr{^/static3/}, root => TestMiddleware->path_to('share') },
21     sub {
22       my $app = shift;
23       return sub {
24         my $env = shift;
25         if($env->{PATH_INFO} =~m/forced/) {
26           Plack::App::File->new(file=>TestMiddleware->path_to(qw/share static forced.txt/))
27             ->call($env);
28         } else {
29           return $app->($env);
30         }
31       },
32     },
33
34   ],
35 );
36
37 __PACKAGE__->setup;
38