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