diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..e7dab77 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,16 @@ +language: perl +perl: + - "5.22" + - "5.20" + - "5.18" + - "5.16" + - "5.14" + - "5.12" + - "5.10" + - "5.8" + - "5.6" + - "blead" +sudo: false +before_install: + - git clone git://github.com/travis-perl/helpers ~/travis-perl-helpers + - source ~/travis-perl-helpers/init --auto \ No newline at end of file diff --git a/Build.PL b/Build.PL index 71ee02c..b97d154 100644 --- a/Build.PL +++ b/Build.PL @@ -5,12 +5,13 @@ my $build = Module::Build->new license => 'perl', requires => { 'Module::Build' => 0, - 'CGI' => 0, + 'CGI' => 4.21, 'HTML::Template' => 0, 'Test::More' => 0.47, 'Test::Requires' => 0, 'Carp' => 0, 'Class::ISA' => 0, + 'Scalar::Util' => 0, }, recommends => { CGI::PSGI => 0.09, # If you want to use run_as_psgi() @@ -18,6 +19,7 @@ my $build = Module::Build->new 'dist_author' => [ 'Jesse Erlbaum ', 'Mark Stosberg ', + 'Martin McGrath ', 'with the help of many others!' ], 'dist_abstract' => 'Framework for building reusable web-applications', @@ -27,7 +29,8 @@ my $build = Module::Build->new }, meta_merge => { resources => { - repository => 'https://github.com/markstos/CGI--Application', + repository => 'https://github.com/MartinMcGrath/CGI--Application', + bugtracker => 'https://github.com/MartinMcGrath/CGI--Application/issues' }, }, ); diff --git a/Changes b/Changes index ab160b6..f37cd3c 100644 --- a/Changes +++ b/Changes @@ -1,5 +1,26 @@ Revision history for CGI::Application. +4.50.51 (developer release) 2015-07-16 + + [BUGS] + - Create new CGI::PSGI object unconditionally in psgi_app()/Bug #88506 (allter) + + [DOCUMENTATION] + - Introduced Travis CI (Martin McGrath) + +4.50_50 (developer release) Fri Jun 23, 2014 + + - Add PSGI Streaming methods (Mike Tonks) + - Added CGI.pm dependency, it is no longer a core module (Martin McGrath) + + [BUGS] + - Fixed rt #84403 - Security problem: missing "start" mode dumps ENV to output page. (Martin McGrath) + - Ensure dump_html() returns valid HTML. (Martin McGrath) + + [DOCUMENTATION] + - Changes to repository URL and bug tracker, added Martin McGrath as a co-maintainer + - Typo fixes (David Steinbrunner) + 4.50 Thu Jun 16, 2011 [FEATURES] diff --git a/README.md b/README.md new file mode 100644 index 0000000..49e2097 --- /dev/null +++ b/README.md @@ -0,0 +1,55 @@ +# CGI::Application - Framework for building reusable web-applications + +![Current build status](https://travis-ci.org/MartinMcGrath/CGI--Application.svg?branch=master) + +CGI::Application is intended to make it easier to create sophisticated, +reusable web-based applications. This module implements a methodology which, +if followed, will make your web software easier to design, easier to +document, easier to write, and easier to evolve. + +Download site for CGI::Application: + + http://search.cpan.org/dist/CGI-Application/ + +See the 'Changes' file for recent changes. + +For more information about this module, please see our website at: + +http://www.cgi-app.org/ + +#### How do I install it? + +To install this module, `cd` to the directory that contains this README +file and type the following: + +``` +perl Makefile.PL +make +make test +make install +``` + +CGI::Application builds on standard, non-proprietary technologies and +techniques, such as the Common Gateway Interface and Lincoln D. Stein's +excellent CGI.pm module. CGI::Application judiciously avoids employing +technologies and techniques which would bind a developer to any one set +of tools, operating system or web server. + +The guiding philosophy behind CGI::Application is that a web-based +application can be organized into a specific set of "Run Modes." Each +Run Mode is roughly analogous to a single screen (a form, some output, etc). +All the Run Modes are managed by a single "Application Module" which is a +Perl module. In your web server's document space there is an "Instance +Script" which is called by the web server as a CGI (or an Apache::Registry +script if you're using Apache + mod_perl). + +CGI::Application is an Object-Oriented Perl module which implements an +Abstract Class. It is not intended that this package be instantiated +directly. Instead, it is intended that your Application Module will be +implemented as a Sub-Class of CGI::Application. + +If you have any questions, comments, bug reports or feature suggestions, +post them to the support mailing list! To join the mailing list, simply +send a blank message to "cgiapp-subscribe@lists.erlbaum.net". + +We also have an IRC channel named #cgiapp on irc.perl.org. diff --git a/lib/CGI/Application.pm b/lib/CGI/Application.pm index bf5cb1e..6528b92 100644 --- a/lib/CGI/Application.pm +++ b/lib/CGI/Application.pm @@ -4,7 +4,7 @@ use strict; use Class::ISA; use Scalar::Util; -$CGI::Application::VERSION = '4.50'; +$CGI::Application::VERSION = '4.50_51'; my %INSTALLED_CALLBACKS = ( # hook name package sub @@ -60,6 +60,11 @@ sub new { if (exists($rprops->{QUERY})) { $self->query($rprops->{QUERY}); } + + # Set the ENV variable for PSGI Application + if (exists($rprops->{ENV})) { + $self->env($rprops->{ENV}); + } # Set up init param() values if (exists($rprops->{PARAMS})) { @@ -243,11 +248,13 @@ sub psgi_app { return sub { my $env = shift; - - if (not defined $args_to_new->{QUERY}) { + + # PR from alter https://github.com/markstos/CGI--Application/pull/17 + #if (not defined $args_to_new->{QUERY}) { + $args_to_new->{ENV} = $env; require CGI::PSGI; $args_to_new->{QUERY} = CGI::PSGI->new($env); - } + #} my $webapp = $class->new($args_to_new); return $webapp->run_as_psgi; @@ -257,6 +264,8 @@ sub psgi_app { sub run_as_psgi { my $self = shift; $self->{__IS_PSGI} = 1; + my $env = shift; + $self->env($env); # Run doesn't officially support any args, but pass them through in case some sub-class uses them. return $self->run(@_); @@ -332,10 +341,11 @@ sub dump { $output .= "Current Run mode: '$current_runmode'\n"; # Dump Params + # updated ->param to ->multi_param to silence CGI.pm warning $output .= "\nQuery Parameters:\n"; - my @params = $self->query->param(); + my @params = $self->query->multi_param(); foreach my $p (sort(@params)) { - my @data = $self->query->param($p); + my @data = $self->query->multi_param($p); my $data_str = "'".join("', '", @data)."'"; $output .= "\t$p => $data_str\n"; } @@ -358,7 +368,7 @@ sub dump_html { # Dump run-mode my $current_runmode = $self->get_current_runmode(); $output .= "

Current Run-mode: -'$current_runmode'

\n"; + '$current_runmode'

\n"; # Dump Params $output .= "

Query Parameters:

\n"; @@ -394,8 +404,8 @@ sub no_runmodes {

Runmode called: $current_runmode"

Query paramaters:

$query_params

Your application has not specified any runmodes.

-

Please read the CGI::Application documentation.

+

Please read the + CGI::Application documentation.

}; $output .= $query->end_html(); @@ -533,7 +543,17 @@ sub delete { delete $self->{__PARAMS}->{$param}; } - +sub env { + my $self = shift; + my ($env) = @_; + + # If data is provided, set it! + if (defined($env)) { + $self->{__ENV} = $env; + } + + return $self->{__ENV}; +} sub query { my $self = shift; my ($query) = @_; @@ -1016,6 +1036,11 @@ CGI::Application will instantiate its own CGI.pm query object. Under certain conditions, it might be useful to be able to use one which has already been created. +B - This optional parameter allows you to save the PSGI environment hash. +This is useful, because you can later get this environment hash in your Application +Module with the method $self->env which could be important for using Plack::Middlewares +and similiar. + B - This parameter, if used, allows you to set a number of custom parameters at run-time. By passing in different values in different instance scripts which use the same application @@ -1075,14 +1100,16 @@ 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 as the query object. To use a different query -object, construct your own object using C<< run_as_psgi() >>, as shown below. +coderef, using L as the query object and saving the PSGI +environment hash in the key ENV so that it can be accesed with C<< $self->env >>. +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() +=head3 run_as_psgi($env) my $psgi_aref = $webapp->run_as_psgi; @@ -1113,6 +1140,11 @@ PSGI spec. to handle the input, you need to use a CGI.pm-like query object that is PSGI-compliant, such as L. This query object must provide L and L methods. +You can pass the PSGI enivornment hash as first argument to the run_as_psgi. This +is the same as passing C<< {ENV => $env} >> to the method C<< new >> or C<< as_psgi >>. +The benefit of this is that you can later in your Application Module easily access to this +PSGI environment hash by C<< $self->env >> + The final result might look like this: use WebApp; @@ -1546,6 +1578,16 @@ you can pass it to c like this: $webapp->query($new_query_object); my $q = $webapp->query(); # now uses $new_query_object +=head3 env() + + my $q = $webapp->env(); + my $session = Plack::Session->new($env); + +This method retrieves the PSGI environment hash which has been created +by instantiating your Application Module as a psgi script. This is important +for using Plack::Middlewares, such as Plack::Middleware::Session in the +example above. + =head3 run_modes() # The common usage: an arrayref of run mode names that exactly match subroutine names @@ -2533,7 +2575,7 @@ B This project is managed using git and is available on Github: - https://github.com/markstos/CGI--Application + L =head1 SEE ALSO @@ -2572,8 +2614,9 @@ they provide to the Perl community! Jesse Erlbaum -Mark Stosberg has served as a co-maintainer since version 3.2, with the help of -the numerous contributors documented in the Changes file. +Mark Stosberg has served as a co-maintainer since version 3.2, Martin McGrath +became a co-maintainer as of version 4.51, with the help of the numerous +contributors documented in the Changes file. =head1 CREDITS diff --git a/t/lib/TestApp14.pm b/t/lib/TestApp14.pm index 40ef997..d209112 100644 --- a/t/lib/TestApp14.pm +++ b/t/lib/TestApp14.pm @@ -13,7 +13,7 @@ sub start { my $self = shift; my $t = $self->load_tmpl('test.tmpl'); - $t->param(ping => $self->query->param('message')); + $t->param(ping => scalar $self->query->param('message')); return $t->output(); }