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