Linux and UNIX Man Pages

Linux & Unix Commands - Search Man Pages

plack::test(3pm) [debian man page]

Plack::Test(3pm)					User Contributed Perl Documentation					  Plack::Test(3pm)

NAME
Plack::Test - Test PSGI applications with various backends SYNOPSIS
use Plack::Test; # named params test_psgi app => sub { my $env = shift; return [ 200, [ 'Content-Type' => 'text/plain' ], [ "Hello World" ] ], }, client => sub { my $cb = shift; my $req = HTTP::Request->new(GET => "http://localhost/hello"); my $res = $cb->($req); like $res->content, qr/Hello World/; }; use HTTP::Request::Common; # positional params (app, client) my $app = sub { return [ 200, [], [ "Hello "] ] }; test_psgi $app, sub { my $cb = shift; my $res = $cb->(GET "/"); is $res->content, "Hello"; }; DESCRIPTION
Plack::Test is a unified interface to test PSGI applications using HTTP::Request and HTTP::Response objects. It also allows you to run PSGI applications in various ways. The default backend is "Plack::Test::MockHTTP", but you may also use any Plack::Handler implementation to run live HTTP requests against at web server FUNCTIONS
test_psgi test_psgi $app, $client; test_psgi app => $app, client => $client; Runs the client test code $client against a PSGI application $app. The client callback gets one argument $cb, a callback that accepts an "HTTP::Request" object and returns an "HTTP::Response" object. Use HTTP::Request::Common to import shortcuts for creating requests for "GET", "POST", "DELETE", and "PUT" operations. For your convenience, the "HTTP::Request" given to the callback automatically uses the HTTP protocol and the localhost (127.0.0.1 by default), so the following code just works: use HTTP::Request::Common; test_psgi $app, sub { my $cb = shift; my $res = $cb->(GET "/hello"); }; Note that however, it is not a good idea to pass an arbitrary (i.e. user-input) string to "GET" or even "HTTP::Request->new" by assuming that it always represents a path, because: my $req = GET "//foo/bar"; would represent a request for a URL that has no scheme, has a hostname foo and a path /bar, instead of a path //foo/bar which you might actually want. OPTIONS
Specify the Plack::Test backend using the environment variable "PLACK_TEST_IMPL" or $Plack::Test::Impl package variable. The available values for the backend are: MockHTTP (Default) Creates a PSGI env hash out of HTTP::Request object, runs the PSGI application in-process and returns HTTP::Response. Server Runs one of Plack::Handler backends ("Standalone" by default) and sends live HTTP requests to test. ExternalServer Runs tests against an external server specified in the "PLACK_TEST_EXTERNALSERVER_URI" environment variable instead of spawning the application in a server locally. For instance, test your application with the "HTTP::Server::ServerSimple" server backend with: > env PLACK_TEST_IMPL=Server PLACK_SERVER=HTTP::Server::ServerSimple prove -l t/test.t AUTHOR
Tatsuhiko Miyagawa perl v5.14.2 2011-09-20 Plack::Test(3pm)

Check Out this Related Man Page

Plack(3pm)						User Contributed Perl Documentation						Plack(3pm)

NAME
Plack - Perl Superglue for Web frameworks and Web Servers (PSGI toolkit) DESCRIPTION
Plack is a set of tools for using the PSGI stack. It contains middleware components, a reference server and utilities for Web application frameworks. Plack is like Ruby's Rack or Python's Paste for WSGI. See PSGI for the PSGI specification and PSGI::FAQ to know what PSGI and Plack are and why we need them. MODULES AND UTILITIES
Plack::Handler Plack::Handler and its subclasses contains adapters for web servers. We have adapters for the built-in standalone web server HTTP::Server::PSGI, CGI, FCGI, Apache1, Apache2 and HTTP::Server::Simple included in the core Plack distribution. There are also many HTTP server implementations on CPAN that have Plack handlers. See Plack::Handler when writing your own adapters. Plack::Loader Plack::Loader is a loader to load one Plack::Handler adapter and run a PSGI application code reference with it. Plack::Util Plack::Util contains a lot of utility functions for server implementors as well as middleware authors. .psgi files A PSGI application is a code reference but it's not easy to pass code reference via the command line or configuration files, so Plack uses a convention that you need a file named "app.psgi" or similar, which would be loaded (via perl's core function "do") to return the PSGI application code reference. # Hello.psgi my $app = sub { my $env = shift; # ... return [ $status, $headers, $body ]; }; If you use a web framework, chances are that they provide a helper utility to automatically generate these ".psgi" files for you, such as: # MyApp.psgi use MyApp; my $app = sub { MyApp->run_psgi(@_) }; It's important that the return value of ".psgi" file is the code reference. See "eg/dot-psgi" directory for more examples of ".psgi" files. plackup, Plack::Runner plackup is a command line launcher to run PSGI applications from command line using Plack::Loader to load PSGI backends. It can be used to run standalone servers and FastCGI daemon processes. Other server backends like Apache2 needs a separate configuration but ".psgi" application file can still be the same. If you want to write your own frontend that replaces, or adds functionalities to plackup, take a look at the Plack::Runner module. Plack::Middleware PSGI middleware is a PSGI application that wraps an existing PSGI application and plays both side of application and servers. From the servers the wrapped code reference still looks like and behaves exactly the same as PSGI applications. Plack::Middleware gives you an easy way to wrap PSGI applications with a clean API, and compatibility with Plack::Builder DSL. Plack::Builder Plack::Builder gives you a DSL that you can enable Middleware in ".psgi" files to wrap existent PSGI applications. Plack::Request, Plack::Response Plack::Request gives you a nice wrapper API around PSGI $env hash to get headers, cookies and query parameters much like Apache::Request in mod_perl. Plack::Response does the same to construct the response array reference. Plack::Test Plack::Test is a unified interface to test your PSGI application using standard HTTP::Request and HTTP::Response pair with simple callbacks. Plack::Test::Suite Plack::Test::Suite is a test suite to test a new PSGI server backend. CONTRIBUTING
Patches and Bug Fixes Small patches and bug fixes can be either submitted via nopaste on IRC <irc://irc.perl.org/#plack> or the github issue tracker <http://github.com/miyagawa/Plack/issues>. Forking on github <http://github.com/miyagawa/Plack> is another good way if you intend to make larger fixes. See also <http://contributing.appspot.com/plack> when you think this document is terribly outdated. Module Namespaces Modules added to the Plack:: sub-namespaces should be reasonably generic components which are useful as building blocks and not just simply using Plack. Middleware authors are free to use the Plack::Middleware:: namespace for their middleware components. Middleware must be written in the pipeline style such that they can chained together with other middleware components. The Plack::Middleware:: modules in the core distribution are good examples of such modules. It is recommended that you inherit from Plack::Middleware for these types of modules. Not all middleware components are wrappers, but instead are more like endpoints in a middleware chain. These types of components should use the Plack::App:: namespace. Again, look in the core modules to see excellent examples of these (Plack::App::File, Plack::App::Directory, etc.). It is recommended that you inherit from Plack::Component for these types of modules. DO NOT USE Plack:: namespace to build a new web application or a framework. It's like naming your application under CGI:: namespace if it's supposed to run on CGI and that is a really bad choice and would confuse people badly. AUTHOR
Tatsuhiko Miyagawa COPYRIGHT
The following copyright notice applies to all the files provided in this distribution, including binary files, unless explicitly noted otherwise. Copyright 2009-2011 Tatsuhiko Miyagawa CONTRIBUTORS
Yuval Kogman (nothingmuch) Tokuhiro Matsuno (tokuhirom) Kazuhiro Osawa (Yappo) Kazuho Oku Florian Ragwitz (rafl) Chia-liang Kao (clkao) Masahiro Honma (hiratara) Daisuke Murase (typester) John Beppu Matt S Trout (mst) Shawn M Moore (Sartak) Stevan Little Hans Dieter Pearcey (confound) Tomas Doran (t0m) mala Mark Stosberg Aaron Trevena SEE ALSO
The PSGI specification upon which Plack is based. <http://plackperl.org/> The Plack wiki: <https://github.com/miyagawa/Plack/wiki> The Plack FAQ: <https://github.com/miyagawa/Plack/wiki/Faq> LICENSE
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. perl v5.14.2 2012-06-21 Plack(3pm)
Man Page