Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved documentation for psgi_app #8

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 25 additions & 1 deletion lib/CGI/Application.pm
Original file line number Diff line number Diff line change
Expand Up @@ -1078,12 +1078,36 @@ support to it.
The simplest way to create and return a PSGI-compatible coderef. Pass in
arguments to a hashref just as would to new. This returns a PSGI-compatible
coderef, using L<CGI:::PSGI> as the query object. To use a different query
object, construct your own object using C<< run_as_psgi() >>, as shown below.
object, you have to construct your own object using C<< run_as_psgi() >>,
as shown below, because C<< psgi_app >> creates a new CGI::PSGI object
unconditionally on every request and therefore overrides a own query object.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Initial version looked better IMHO. The only thing that should be added/highlighted is that QUERY parameter is not supported and will be overwritten.

I would even add a warning / exception in the code if we detect that it was passed.


It's possible that we'll change from CGI::PSGI to a different-but-compatible
query object for PSGI support in the future, perhaps if CGI.pm adds native
PSGI support.

The use of psgi_app might look like this:

package WebApp;
use base "CGI::Application";

sub setup {
my $self = shift;
$self->start_mode('welcome');
$self->mode_param('rm');
$self->run_modes(
'welcome' => 'welcome'
);
}

sub welcome {
return "Hello World";
}

package main;

my $app = WebApp->psgi_app();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think that there's a need for this example here. The example I was talking about at #7 was essentially the one above: line
$psgi_coderef = WebApp->psgi_app({ ... args to new() ... }); - should be changed to something like
$psgi_coderef = WebApp->psgi_app({ ... args to new() without QUERY... }); - that's it.

=head3 run_as_psgi()

my $psgi_aref = $webapp->run_as_psgi;
Expand Down