Linux and UNIX Man Pages

Linux & Unix Commands - Search Man Pages

plack::middleware::conditional(3pm) [debian man page]

Plack::Middleware::Conditional(3pm)			User Contributed Perl Documentation		       Plack::Middleware::Conditional(3pm)

NAME
Plack::Middleware::Conditional - Conditional wrapper for Plack middleware SYNOPSIS
use Plack::Builder; builder { enable_if { $_[0]->{REMOTE_ADDR} eq '127.0.0.1' } 'StackTrace', force => 1; $app; }; # or using the OO interface: $app = Plack::Middleware::Conditional->wrap( $app, condition => sub { $_[0]->{REMOTE_ADDR} eq '127.0.0.1' }, builder => sub { Plack::Middleware::StackTrace->wrap($_[0], force => 1) }, ); DESCRIPTION
Plack::Middleware::Conditional is a piece of meta-middleware, to run a specific middleware component under runtime conditions. The goal of this middleware is to avoid baking runtime configuration options in individual middleware components, and rather share them as another middleware component. EXAMPLES
Note that some of the middleware component names are just made up for the explanation and might not exist. # Minify JavaScript if the browser is Firefox enable_if { $_[0]->{HTTP_USER_AGENT} =~ /Firefox/ } 'JavaScriptMinifier'; # Enable Stacktrace when being accessed from the local network enable_if { $_[0]->{REMOTE_ADDR} =~ /^10.0.1.*/ } 'StackTrace'; # Work with other conditional setter middleware: # Transcode Jpeg on the fly for mobile clients builder { enable 'MobileDetector'; enable_if { $_[0]->{'plack.mobile_detected'} } 'TranscodeJpeg', max_size => 30_000; $app; }; Note that in the last example MobileDetector should come first because the conditional check runs in pre-run conditions, which is from outer to inner: that is, from the top to the bottom in the Builder DSL code. AUTHOR
Tatsuhiko Miyagawa Steve Cook SEE ALSO
Plack::Builder perl v5.14.2 2012-04-14 Plack::Middleware::Conditional(3pm)

Check Out this Related Man Page

Plack::Middleware::Static(3pm)				User Contributed Perl Documentation			    Plack::Middleware::Static(3pm)

NAME
Plack::Middleware::Static - serve static files with Plack SYNOPSIS
use Plack::Builder; builder { enable "Plack::Middleware::Static", path => qr{^/(images|js|css)/}, root => './htdocs/'; $app; }; DESCRIPTION
Enable this middleware to allow your Plack-based application to serve static files. If the given request matches with the pattern defined in "path", this middleware will try to locate the file in "root". If the file exists it will be served but otherwise 404 response will be returned. See "pass_through" option below to change this behavior. If the requested document is not within the "root" (i.e. directory traversal) or the file is there but not readable, a 403 Forbidden response will be returned. The content type returned will be determined from the file extension based on Plack::MIME. CONFIGURATIONS
path, root enable "Plack::Middleware::Static", path => qr{^/static/}, root => 'htdocs/'; "path" specifies the URL pattern (regular expression) or a callback to match with requests to serve static files for. "root" specifies the root directory to serve those static files from. The default value of "root" is the current directory. This examples configuration serves "/static/foo.jpg" from "htdocs/static/foo.jpg". Note that the matched "/static/" portion is still appears in the local mapped path. If you don't like it, use a callback instead to munge $_: enable "Plack::Middleware::Static", path => sub { s!^/static/!! }, root => 'static-files/'; This configuration would serve "/static/foo.png" from "static-files/foo.png" (not "static-files/static/foo.png"). The callback specified in "path" option matches against $_ and then updates the value since it does s///, and returns the number of matches, so it will pass through when "/static/" doesn't match. If you want to map multiple static directories from different root, simply add "this", middleware multiple times with different configuration options. pass_through By turning on this option, this middleware will pass the request back to the application for further processing, if the incoming request path matches with the "path" but the requested file is not found on the file system. AUTHOR
Tokuhiro Matsuno, Tatsuhiko Miyagawa SEE ALSO
Plack::Middleware Plack::Builder perl v5.14.2 2011-06-22 Plack::Middleware::Static(3pm)
Man Page