r75859 - in /trunk/libcgi-application-perl: Build.PL Changes MANIFEST META.json META.yml Makefile.PL debian/changelog lib/CGI/Application.pm t/header_props.t t/run_as_psgi.t
periapt-guest at users.alioth.debian.org
periapt-guest at users.alioth.debian.org
Fri Jun 17 06:02:17 UTC 2011
Author: periapt-guest
Date: Fri Jun 17 06:02:06 2011
New Revision: 75859
URL: http://svn.debian.org/wsvn/pkg-perl/?sc=1&rev=75859
Log:
New upstream release
Added:
trunk/libcgi-application-perl/META.json
- copied unchanged from r75858, branches/upstream/libcgi-application-perl/current/META.json
trunk/libcgi-application-perl/t/run_as_psgi.t
- copied unchanged from r75858, branches/upstream/libcgi-application-perl/current/t/run_as_psgi.t
Modified:
trunk/libcgi-application-perl/Build.PL
trunk/libcgi-application-perl/Changes
trunk/libcgi-application-perl/MANIFEST
trunk/libcgi-application-perl/META.yml
trunk/libcgi-application-perl/Makefile.PL
trunk/libcgi-application-perl/debian/changelog
trunk/libcgi-application-perl/lib/CGI/Application.pm
trunk/libcgi-application-perl/t/header_props.t
Modified: trunk/libcgi-application-perl/Build.PL
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/libcgi-application-perl/Build.PL?rev=75859&op=diff
==============================================================================
--- trunk/libcgi-application-perl/Build.PL (original)
+++ trunk/libcgi-application-perl/Build.PL Fri Jun 17 06:02:06 2011
@@ -1,17 +1,18 @@
-# $Id: Build.PL,v 1.2 2004/02/14 02:09:17 mark Exp $
use Module::Build;
my $build = Module::Build->new
(
module_name => 'CGI::Application',
license => 'perl',
requires => {
- # For Moved vs Found change
'CGI' => 0,
'HTML::Template' => 0,
'Test::More' => 0.47,
'Carp' => 0,
'Class::ISA' => 0,
},
+ recommends => {
+ CGI::PSGI => 0.09, # If you want to use run_as_psgi()
+ },
'dist_author' => [
'Jesse Erlbaum <jesse at erlbaum.net>',
'Mark Stosberg <mark at summersault.com>',
Modified: trunk/libcgi-application-perl/Changes
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/libcgi-application-perl/Changes?rev=75859&op=diff
==============================================================================
--- trunk/libcgi-application-perl/Changes (original)
+++ trunk/libcgi-application-perl/Changes Fri Jun 17 06:02:06 2011
@@ -1,4 +1,25 @@
Revision history for CGI::Application.
+
+4.50 Thu Jun 16, 2011
+
+ [FEATURES]
+ Better PSGI support in the core
+ - run_as_psgi() works like run, but directly returns the expected PSGI response structure
+ - psgi_app() wraps up all the PSGI bits to call and run the application and return a PSGI
+ code ref:
+
+ $psgi_coderef = WebApp->psgi_app({ ... args to new() ... });
+
+ [DOCUMENTATION]
+ - docs for header_props() were improved
+
+ [INTERNAL]
+ - source control management was moved from darcs to git. Those who prefer
+ darcs are are more familiar with it are advised to try the darcs-git.py
+ wrapper for git.
+
+ - The test file psgi_app.t is missing from this release and will be added later.
+
4.31 Wed Jul 29, 2009
Modified: trunk/libcgi-application-perl/MANIFEST
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/libcgi-application-perl/MANIFEST?rev=75859&op=diff
==============================================================================
--- trunk/libcgi-application-perl/MANIFEST (original)
+++ trunk/libcgi-application-perl/MANIFEST Fri Jun 17 06:02:06 2011
@@ -28,6 +28,7 @@
t/mode_param_overwritten.t
t/load_tmpl_hook.t
t/query.t
+t/run_as_psgi.t
t/lib/TestApp.pm
t/lib/TestApp2.pm
t/lib/TestApp3.pm
@@ -44,3 +45,4 @@
t/lib/TestApp14.pm
t/lib/TestCGI.pm
t/lib/templates/test.tmpl
+META.json
Modified: trunk/libcgi-application-perl/META.yml
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/libcgi-application-perl/META.yml?rev=75859&op=diff
==============================================================================
--- trunk/libcgi-application-perl/META.yml (original)
+++ trunk/libcgi-application-perl/META.yml Fri Jun 17 06:02:06 2011
@@ -1,29 +1,36 @@
---
-name: CGI-Application
-version: 4.31
+abstract: 'Framework for building reusable web-applications'
author:
- 'Jesse Erlbaum <jesse at erlbaum.net>'
- 'Mark Stosberg <mark at summersault.com>'
- - "with the help of many others!"
-abstract: Framework for building reusable web-applications
+ - 'with the help of many others!'
+build_requires: {}
+configure_requires:
+ Module::Build: 0.38
+dynamic_config: 1
+generated_by: 'Module::Build version 0.38, CPAN::Meta::Converter version 2.110930'
license: perl
+meta-spec:
+ url: http://module-build.sourceforge.net/META-spec-v1.4.html
+ version: 1.4
+name: CGI-Application
+no_index:
+ file: []
+provides:
+ CGI::Application:
+ file: lib/CGI/Application.pm
+ version: 4.50
+ CGI::Application::Mailform:
+ file: lib/CGI/Application/Mailform.pm
+ version: 0
+recommends:
+ CGI::PSGI: 0.09
requires:
CGI: 0
Carp: 0
Class::ISA: 0
HTML::Template: 0
Test::More: 0.47
-generated_by: Module::Build version 0.32
-meta-spec:
- url: http://module-build.sourceforge.net/META-spec-v1.2.html
- version: 1.2
-no_index:
- file:
-provides:
- CGI::Application:
- file: lib/CGI/Application.pm
- version: 4.31
- CGI::Application::Mailform:
- file: lib/CGI/Application/Mailform.pm
resources:
- license: ~
+ license: http://dev.perl.org/licenses/
+version: 4.50
Modified: trunk/libcgi-application-perl/Makefile.PL
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/libcgi-application-perl/Makefile.PL?rev=75859&op=diff
==============================================================================
--- trunk/libcgi-application-perl/Makefile.PL (original)
+++ trunk/libcgi-application-perl/Makefile.PL Fri Jun 17 06:02:06 2011
@@ -1,7 +1,8 @@
-# Note: this file was auto-generated by Module::Build::Compat version 0.32
+# Note: this file was auto-generated by Module::Build::Compat version 0.3800
use ExtUtils::MakeMaker;
WriteMakefile
(
+ 'PL_FILES' => {},
'INSTALLDIRS' => 'site',
'NAME' => 'CGI::Application',
'EXE_FILES' => [],
Modified: trunk/libcgi-application-perl/debian/changelog
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/libcgi-application-perl/debian/changelog?rev=75859&op=diff
==============================================================================
--- trunk/libcgi-application-perl/debian/changelog (original)
+++ trunk/libcgi-application-perl/debian/changelog Fri Jun 17 06:02:06 2011
@@ -1,11 +1,12 @@
-libcgi-application-perl (4.31-3) UNRELEASED; urgency=low
+libcgi-application-perl (4.50-1) UNRELEASED; urgency=low
NOTE: Please leave until libcgi-application-basic-plugin-bundle-perl
is in Debian Perl.
* Added myself to Uploaders
-
- -- Nicholas Bamber <nicholas at periapt.co.uk> Fri, 17 Jun 2011 06:59:32 +0100
+ * New upstream release
+
+ -- Nicholas Bamber <nicholas at periapt.co.uk> Fri, 17 Jun 2011 07:03:06 +0100
libcgi-application-perl (4.31-2) unstable; urgency=low
Modified: trunk/libcgi-application-perl/lib/CGI/Application.pm
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/libcgi-application-perl/lib/CGI/Application.pm?rev=75859&op=diff
==============================================================================
--- trunk/libcgi-application-perl/lib/CGI/Application.pm (original)
+++ trunk/libcgi-application-perl/lib/CGI/Application.pm Fri Jun 17 06:02:06 2011
@@ -3,7 +3,7 @@
use strict;
use Class::ISA;
-$CGI::Application::VERSION = '4.31';
+$CGI::Application::VERSION = '4.50';
my %INSTALLED_CALLBACKS = (
# hook name package sub
@@ -196,21 +196,50 @@
# Call cgiapp_postrun() hook
$self->call_hook('postrun', \$body);
- # Set up HTTP headers
- my $headers = $self->_send_headers();
-
- # Build up total output
- my $output = $headers.$body;
-
- # Send output to browser (unless we're in serious debug mode!)
- unless ($ENV{CGI_APP_RETURN_ONLY}) {
- print $output;
- }
+ my $return_value;
+ if ($self->{__IS_PSGI}) {
+ my ($status, $headers) = $self->_send_psgi_headers();
+ $return_value = [ $status, $headers, [ $body ]];
+ }
+ else {
+ # Set up HTTP headers non-PSGI responses
+ my $headers = $self->_send_headers();
+
+ # Build up total output
+ $return_value = $headers.$body;
+ print $return_value unless $ENV{CGI_APP_RETURN_ONLY};
+ }
# clean up operations
$self->call_hook('teardown');
- return $output;
+ return $return_value;
+}
+
+
+sub psgi_app {
+ my $class = shift;
+ my $args_to_new = shift;
+
+ return sub {
+ my $env = shift;
+
+ if (not defined $args_to_new->{QUERY}) {
+ require CGI::PSGI;
+ $args_to_new->{QUERY} = CGI::PSGI->new($env);
+ }
+
+ my $webapp = $class->new($args_to_new);
+ return $webapp->run_as_psgi;
+ }
+}
+
+sub run_as_psgi {
+ my $self = shift;
+ $self->{__IS_PSGI} = 1;
+
+ # Run doesn't officially support any args, but pass them through in case some sub-class uses them.
+ return $self->run(@_);
}
@@ -601,6 +630,7 @@
###########################
+# return headers as a string
sub _send_headers {
my $self = shift;
my $q = $self->query;
@@ -611,6 +641,20 @@
: $type eq 'header' ? $q->header ( $self->header_props )
: $type eq 'none' ? ''
: croak "Invalid header_type '$type'"
+}
+
+# return a 2 element array modeling the first PSGI redirect values: status code and arrayref of header pairs
+sub _send_psgi_headers {
+ my $self = shift;
+ my $q = $self->query;
+ my $type = $self->header_type;
+
+ return
+ $type eq 'redirect' ? $q->psgi_redirect( $self->header_props )
+ : $type eq 'header' ? $q->psgi_header ( $self->header_props )
+ : $type eq 'none' ? ''
+ : croak "Invalid header_type '$type'"
+
}
@@ -671,6 +715,10 @@
my $webapp = WebApp->new();
$webapp->run();
+ ### Or, in a PSGI file, webapp.psgi
+ use WebApp;
+ WebApp->psgi_app();
+
=head1 INTRODUCTION
CGI::Application makes it easier to create sophisticated, high-performance,
@@ -971,7 +1019,69 @@
the specified mode is not found in the run_modes() table, run() will
croak().
-=head2 Methods to possibly override
+=head2 PSGI support
+
+CGI::Application offers native L<PSGI> support. The default query object
+for this is L<CGI::PSGI>, which simply wrappers CGI.pm to provide PSGI
+support to it.
+
+=head3 psgi_app()
+
+ $psgi_coderef = WebApp->psgi_app({ ... args to new() ... });
+
+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.
+
+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.
+
+=head3 run_as_psgi()
+
+ my $psgi_aref = $webapp->run_as_psgi;
+
+Just like C<< run >>, but prints no output and returns the data structure
+required by the L<PSGI> specification. Use this if you want to run the
+application on top of a PSGI-compatible handler, such as L<Plack> provides.
+
+If you are just getting started, just use C<< run() >>. It's easy to switch to using
+C<< run_as_psgi >> later.
+
+Why use C<< run_as_psgi() >>? There are already solutions to run
+CGI::Application-based projects on several web servers with dozens of plugins.
+Running as a PSGI-compatible application provides the ability to run on
+additional PSGI-compatible servers, as well as providing access to all of the
+"Middleware" solutions available through the L<Plack> project.
+
+The structure returned is an arrayref, containing the status code, an arrayref
+of header key/values and an arrayref containing the body.
+
+ [ 200, [ 'Content-Type' => 'text/html' ], [ $body ] ]
+
+By default the body is a single scalar, but plugins may modify this to return
+other value PSGI values. See L<PSGI/"The Response"> for details about the
+response format.
+
+Note that calling C<< run_as_psgi >> only handles the I<output> portion of the
+PSGI spec. to handle the input, you need to use a CGI.pm-like query object that
+is PSGI-compliant, such as L<CGI::PSGI>. This query object must provide L<psgi_header>
+and L<psgi_redirect> methods.
+
+The final result might look like this:
+
+ use WebApp;
+ use CGI::PSGI;
+
+ my $handler = sub {
+ my $env = shift;
+ my $webapp = WebApp->new({ QUERY => CGI::PSGI->new($env) });
+ $webapp->run_as_psgi;
+ };
+
+
+=head2 Methods to possibly override
CGI::Application implements some methods which are expected to be overridden
by implementing them in your sub-class module. These methods are as follows:
@@ -1596,17 +1706,24 @@
=head3 header_props()
- $webapp->header_props(-type=>'image/gif',-expires=>'+3d');
+ # Set a complete set of headers
+ %set_headers = $webapp->header_props(-type=>'image/gif',-expires=>'+3d');
+
+ # clobber / reset all headers
+ %set_headers = $webapp->header_props({});
+
+ # Just retrieve the headers
+ %set_headers = $webapp->header_props();
The C<header_props()> method expects a hash of CGI.pm-compatible
HTTP header properties. These properties will be passed directly
-to CGI.pm's C<header()> or C<redirect()> methods. Refer to L<CGI>
-for exact usage details.
-
-Calling header_props any arguments will clobber any existing headers that have
+to the C<header()> or C<redirect()> methods of the query() object. Refer
+to the docs of your query object for details. (Be default, it's L<CGI>.pm).
+
+Calling header_props with an empty hashref clobber any existing headers that have
previously set.
-C<header_props()> return a hash of all the headers that have currently been
+C<header_props()> returns a hash of all the headers that have currently been
set. It can be called with no arguments just to get the hash current headers
back.
@@ -2349,10 +2466,9 @@
B<Source Code>
-This project is managed using the darcs source control system (
-http://www.darcs.net/ ). The darcs archive is here:
-http://mark.stosberg.com/darcs_hive/cgi-app
-
+This project is managed using git and is available on Github:
+
+ https://github.com/markstos/CGI--Application
=head1 SEE ALSO
Modified: trunk/libcgi-application-perl/t/header_props.t
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/libcgi-application-perl/t/header_props.t?rev=75859&op=diff
==============================================================================
--- trunk/libcgi-application-perl/t/header_props.t (original)
+++ trunk/libcgi-application-perl/t/header_props.t Fri Jun 17 06:02:06 2011
@@ -1,6 +1,6 @@
use strict;
-use Test::More tests => 6;
+use Test::More tests => 9;
BEGIN{use_ok('CGI::Application');}
@@ -63,3 +63,32 @@
);
}
+{
+ my $app = CGI::Application->new;
+
+ $app->header_props({ -type => 'banana/ripe' });
+
+ like(
+ $app->run,
+ qr{Content-type: banana/ripe}i,
+ "headed added via hashref arg to header_props",
+ );
+
+ $app->header_props();
+
+ like(
+ $app->run,
+ qr{Content-type: banana/ripe}i,
+ "Calling with no args is safe",
+ );
+
+ $app->header_props({});
+
+ unlike(
+ $app->run,
+ qr{Content-type: banana/ripe}i,
+ "Calling with an empty hashref clobbers existing data",
+ );
+
+}
+
More information about the Pkg-perl-cvs-commits
mailing list