Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
4a98e32
Bump version number to 4.51
MartinMcGrath Jan 14, 2015
f5b53f4
update dist_author
MartinMcGrath Jan 14, 2015
26c2905
Update Repository URL
MartinMcGrath Jan 22, 2015
5630735
Change repo URL
MartinMcGrath Jan 22, 2015
eaf49fe
Update for developer release
MartinMcGrath Jan 22, 2015
ad2ab5f
Add bugtracker URL
MartinMcGrath Jan 23, 2015
96955df
Bump version number to 4.50_50
MartinMcGrath Jan 23, 2015
b62b501
Update AUTHORS
MartinMcGrath Jan 23, 2015
8ab7b0f
Add changes for 4.50_50 developer release
MartinMcGrath Jan 23, 2015
de44de3
Formatting
MartinMcGrath Jan 23, 2015
4a3245c
List formatting
MartinMcGrath Jan 29, 2015
064a44e
Fix release note for 4.50_50
MartinMcGrath Feb 16, 2015
0488c04
Ready 4.51
MartinMcGrath Feb 16, 2015
433f8ec
Add Scalar::Util to requires
MartinMcGrath Mar 3, 2015
1f9b154
Add .travis.yml for testing
MartinMcGrath Jun 25, 2015
fa98c99
Merge changes required for new CGI.pm warnings, PSGI commits.
MartinMcGrath Jul 15, 2015
4733c87
Add README in markdown format
MartinMcGrath Jul 16, 2015
997dde9
Prepare new development release
MartinMcGrath Jul 16, 2015
52fc327
Update Changes: Mark _51 as a developer release
MartinMcGrath Jul 18, 2015
e0463bd
Update .travis.yml - Add v5.22, 5.23
MartinMcGrath Jul 20, 2015
0e5d6e1
Fix typo
MartinMcGrath Jul 20, 2015
dd6e57a
Revert "Fix typo"
MartinMcGrath Jul 20, 2015
9856ee0
Revert "Update .travis.yml - Add v5.22, 5.23"
MartinMcGrath Jul 20, 2015
6559e37
switch to Travis-ci helpers
MartinMcGrath Nov 20, 2016
35b407a
Fix travis typos, specifiy CGI version
MartinMcGrath Nov 20, 2016
46a3c98
Get $env easier with $self->env
MaxPerl Nov 27, 2016
22651c9
Added pod Documentation
MaxPerl Nov 29, 2016
32a888a
Added patch and POD to psgi_app
MaxPerl Nov 29, 2016
a0c4fc7
Complete Docs
MaxPerl Dec 2, 2016
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
16 changes: 16 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -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
7 changes: 5 additions & 2 deletions Build.PL
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,21 @@ 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()
},
'dist_author' => [
'Jesse Erlbaum <jesse@erlbaum.net>',
'Mark Stosberg <mark@summersault.com>',
'Martin McGrath <marto@cpan.org>',
'with the help of many others!'
],
'dist_abstract' => 'Framework for building reusable web-applications',
Expand All @@ -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'
},
},
);
Expand Down
21 changes: 21 additions & 0 deletions Changes
Original file line number Diff line number Diff line change
@@ -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]
Expand Down
55 changes: 55 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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.
75 changes: 59 additions & 16 deletions lib/CGI/Application.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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})) {
Expand Down Expand Up @@ -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;
Expand All @@ -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(@_);
Expand Down Expand Up @@ -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";
}
Expand All @@ -358,7 +368,7 @@ sub dump_html {
# Dump run-mode
my $current_runmode = $self->get_current_runmode();
$output .= "<p>Current Run-mode:
'<strong>$current_runmode</strong>'</p>\n";
'<strong>$current_runmode</strong>'</p>\n";

# Dump Params
$output .= "<p>Query Parameters:</p>\n";
Expand Down Expand Up @@ -394,8 +404,8 @@ sub no_runmodes {
<p>Runmode called: $current_runmode"</p>
<p>Query paramaters:</p> $query_params
<p>Your application has not specified any runmodes.</p>
<p>Please read the <a href="http://search.cpan.org/~markstos/CGI-Appli
cation/">CGI::Application</a> documentation.</p>
<p>Please read the <a href="https://metacpan.org/pod/CGI::Application">
CGI::Application</a> documentation.</p>
};

$output .= $query->end_html();
Expand Down Expand Up @@ -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) = @_;
Expand Down Expand Up @@ -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<ENV> - 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<PARAMS> - 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
Expand Down Expand Up @@ -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<CGI:::PSGI> 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<CGI:::PSGI> 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;

Expand Down Expand Up @@ -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<CGI::PSGI>. This query object must provide L<psgi_header>
and L<psgi_redirect> 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;
Expand Down Expand Up @@ -1546,6 +1578,16 @@ you can pass it to c<query()> 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
Expand Down Expand Up @@ -2533,7 +2575,7 @@ B<Source Code>

This project is managed using git and is available on Github:

https://github.com/markstos/CGI--Application
L<https://github.com/MartinMcGrath/CGI--Application>

=head1 SEE ALSO

Expand Down Expand Up @@ -2572,8 +2614,9 @@ they provide to the Perl community!

Jesse Erlbaum <jesse@erlbaum.net>

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

Expand Down
2 changes: 1 addition & 1 deletion t/lib/TestApp14.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down