Show
Ignore:
Timestamp:
02/14/09 15:55:13 (4 years ago)
Author:
yappo
Message:

Static: yaml friendly

Location:
lang/perl/HTTP-Engine-Middleware/trunk
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • lang/perl/HTTP-Engine-Middleware/trunk/lib/HTTP/Engine/Middleware/Static.pm

    r30044 r30048  
    77use Cwd; 
    88use MouseX::Types::Path::Class; 
     9use Mouse::Util::TypeConstraints; 
    910use File::Spec::Unix; 
     11 
     12# corece of Regexp 
     13subtype 'HTTP::Engine::Middleware::Static::Regexp' 
     14    => as 'RegexpRef'; 
     15coerce 'HTTP::Engine::Middleware::Static::Regexp' 
     16    => from 'Str' => via { qr/$_/ }; 
    1017 
    1118has 'regexp' => ( 
    1219    is       => 'ro', 
    13     isa      => 'Regexp', 
     20    isa      => 'HTTP::Engine::Middleware::Static::Regexp', 
     21    coerce   => 1, 
    1422    required => 1, 
    1523); 
     
    162170    # to get the your application response 
    163171 
     172Will you want to set config from yaml? 
     173 
     174    my $mw = HTTP::Engine::Middleware->new; 
     175    $mw->install( 'HTTP::Engine::Middleware::Static' => { 
     176        regexp  => '^/(robots.txt|favicon.ico|(?:css|img)/.+|js/(?!dynamic).+)$', 
     177        docroot => '/path/to/htdocs/', 
     178    }); 
     179    HTTP::Engine->new( 
     180        interface => { 
     181            module => 'YourFavoriteInterfaceHere', 
     182            request_handler => $mw->handler( \&handler ), 
     183        } 
     184    )->run(); 
     185 
     186    # $ GET http//localhost/js/jquery.js 
     187    # to get the /path/to/htdocs/js/jquery.js 
     188 
     189    # $ GET http//localhost/js/dynamic-json.js 
     190    # to get the your application response 
    164191 
    165192=head1 DESCRIPTION 
  • lang/perl/HTTP-Engine-Middleware/trunk/t/200_middlewares/static.t

    r30044 r30048  
    6262    my @config2 = ( 
    6363        'HTTP::Engine::Middleware::Static' => { 
    64             regexp  => qr{^(/(?:css|js|img)/(?!dynamic).+|/manual/.*|/robots\.txt)$}, 
     64            regexp  => '(/(?:css|js|img)/(?!dynamic).+|/manual/.*|/robots\.txt)$', 
    6565            docroot => Path::Class::Dir->new('t', 'htdocs')->stringify, 
    6666            directory_index => 'index.html',