1Catalyst::PSGI(3) User Contributed Perl Documentation Catalyst::PSGI(3)
2
3
4
6 Catalyst::PSGI - How Catalyst and PSGI work together
7
9 The PSGI specification defines an interface between web servers and
10 Perl-based web applications and frameworks. It supports the writing of
11 portable applications that can be run using various methods (as a
12 standalone server, or using mod_perl, FastCGI, etc.). Plack is an
13 implementation of the PSGI specification for running Perl applications.
14
15 Catalyst used to contain an entire set of "Catalyst::Engine::XXXX"
16 classes to handle various web servers and environments (e.g. CGI,
17 FastCGI, mod_perl) etc.
18
19 This has been changed in Catalyst 5.9 so that all of that work is done
20 by Catalyst implementing the PSGI specification, using Plack's adaptors
21 to implement that functionality.
22
23 This means that we can share common code, and share fixes for specific
24 web servers.
25
27 If you already have a Catalyst application, then you should be able to
28 upgrade to the latest release with little or no trouble (see the notes
29 in Catalyst::Upgrading for specifics about your web server deployment).
30
32 What is a .psgi file?
33 A ".psgi" file lets you control how your application code reference is
34 built. Catalyst will automatically handle this for you, but it's
35 possible to do it manually by creating a "myapp.psgi" file in the root
36 of your application.
37
38 Why would I want to write my own .psgi file?
39 Writing your own .psgi file allows you to use the alternate plackup
40 command to start your application, and allows you to add classes and
41 extensions that implement Plack::Middleware, such as
42 Plack::Middleware::ErrorDocument or Plack::Middleware::AccessLog.
43
44 The simplest ".psgi" file for an application called "TestApp" would be:
45
46 use strict;
47 use warnings;
48 use TestApp;
49
50 my $app = TestApp->psgi_app(@_);
51
52 Note that Catalyst will apply a number of middleware components for you
53 automatically, and these will not be applied if you manually create a
54 psgi file yourself. Details of these components can be found below.
55
56 Additional information about psgi files can be found at:
57 <http://search.cpan.org/dist/Plack/lib/Plack.pm#.psgi_files>
58
59 What is in the .psgi file Catalyst generates by default?
60 Catalyst generates an application which, if the "using_frontend_proxy"
61 setting is on, is wrapped in Plack::Middleware::ReverseProxy, and
62 contains some engine-specific fixes for uniform behaviour, as contained
63 in:
64
65 Plack::Middleware::LighttpdScriptNameFix
66 Plack::Middleware::IIS6ScriptNameFix
67
68 If you override the default by providing your own ".psgi" file, then
69 none of these things will be done automatically for you by the PSGI
70 application returned when you call "MyApp->psgi_app". Thus, if you need
71 any of this functionality, you'll need to implement this in your
72 ".psgi" file yourself.
73
74 An apply_default_middlewares method is supplied to wrap your
75 application in the default middlewares if you want this behaviour and
76 you are providing your own .psgi file.
77
78 This means that the auto-generated (no .psgi file) code looks something
79 like this:
80
81 use strict;
82 use warnings;
83 use TestApp;
84
85 my $app = TestApp->apply_default_middlewares(TestApp->psgi_app(@_));
86
88 Catalyst::Upgrading, Plack, PSGI::FAQ, PSGI.
89
91 Catalyst Contributors, see Catalyst.pm
92
94 This library is free software. You can redistribute it and/or modify it
95 under the same terms as Perl itself.
96
97
98
99perl v5.28.0 2015-06-03 Catalyst::PSGI(3)