[Catalyst-commits] r8624 - in trunk/Catalyst-Controller-WrapCGI: .
lib/Catalyst/Controller t/lib t/lib/TestApp/Controller
caelum at dev.catalyst.perl.org
caelum at dev.catalyst.perl.org
Wed Nov 19 23:59:31 GMT 2008
Author: caelum
Date: 2008-11-19 23:59:31 +0000 (Wed, 19 Nov 2008)
New Revision: 8624
Modified:
trunk/Catalyst-Controller-WrapCGI/META.yml
trunk/Catalyst-Controller-WrapCGI/lib/Catalyst/Controller/CGIBin.pm
trunk/Catalyst-Controller-WrapCGI/lib/Catalyst/Controller/WrapCGI.pm
trunk/Catalyst-Controller-WrapCGI/t/lib/TestApp.pm
trunk/Catalyst-Controller-WrapCGI/t/lib/TestApp/Controller/Root.pm
trunk/Catalyst-Controller-WrapCGI/t/lib/TestCGIBin.pm
Log:
WrapCGI: fix for 5.8
Modified: trunk/Catalyst-Controller-WrapCGI/META.yml
===================================================================
--- trunk/Catalyst-Controller-WrapCGI/META.yml 2008-11-19 19:30:34 UTC (rev 8623)
+++ trunk/Catalyst-Controller-WrapCGI/META.yml 2008-11-19 23:59:31 UTC (rev 8624)
@@ -5,11 +5,11 @@
build_requires:
Test::More: 0
distribution_type: module
-generated_by: 'Module::Install version 0.75'
+generated_by: 'Module::Install version 0.77'
license: perl
meta-spec:
- url: http://module-build.sourceforge.net/META-spec-v1.3.html
- version: 1.3
+ url: http://module-build.sourceforge.net/META-spec-v1.4.html
+ version: 1.4
name: Catalyst-Controller-WrapCGI
no_index:
directory:
@@ -25,4 +25,6 @@
Task::Weaken: 0
URI: 0
parent: 0
-version: 0.0023
+resources:
+ license: http://dev.perl.org/licenses/
+version: 0.0024
Modified: trunk/Catalyst-Controller-WrapCGI/lib/Catalyst/Controller/CGIBin.pm
===================================================================
--- trunk/Catalyst-Controller-WrapCGI/lib/Catalyst/Controller/CGIBin.pm 2008-11-19 19:30:34 UTC (rev 8623)
+++ trunk/Catalyst-Controller-WrapCGI/lib/Catalyst/Controller/CGIBin.pm 2008-11-19 23:59:31 UTC (rev 8624)
@@ -22,11 +22,11 @@
=head1 VERSION
-Version 0.002
+Version 0.003
=cut
-our $VERSION = '0.002';
+our $VERSION = '0.003';
=head1 SYNOPSIS
@@ -87,24 +87,24 @@
next if any { $_ eq '.svn' } splitdir $cgi_path;
+ my $path = join '/' => splitdir($cgi_path);
+ my $action_name = $self->cgi_action($path);
+ my $reverse = $namespace ? "$namespace/$action_name" : $action_name;
+ my $attrs = { Path => [ "cgi-bin/$path" ], Args => [ 0 ] };
+
my ($cgi, $type);
if ($self->is_perl_cgi($file)) { # syntax check passed
$type = 'Perl';
- $cgi = $self->wrap_perl_cgi($file);
+ $cgi = $self->wrap_perl_cgi($file, $action_name);
} else {
$type = 'Non-Perl';
- $cgi = $self->wrap_nonperl_cgi($file);
+ $cgi = $self->wrap_nonperl_cgi($file, $action_name);
}
$app->log->info("Registering root/cgi-bin/$cgi_path as a $type CGI.")
if $app->debug;
- my $path = join '/' => splitdir($cgi_path);
- my $action_name = $self->cgi_action($path);
- my $reverse = $namespace ? "$namespace/$action_name" : $action_name;
- my $attrs = { Path => [ "cgi-bin/$path" ], Args => [ 0 ] };
-
my $code = sub {
my ($controller, $context) = @_;
$controller->cgi_to_response($context, $cgi)
@@ -173,15 +173,13 @@
$? >> 8 == 0
}
-=head2 $self->wrap_perl_cgi($path)
+=head2 $self->wrap_perl_cgi($path, $action_name)
Takes the path to a Perl CGI and returns a coderef suitable for passing to
cgi_to_response (from L<Catalyst::Controller::WrapCGI>.)
-By default returns:
+C<$action_name> is the generated name for the action representing the CGI file.
- eval 'sub {' . slurp($path) . '}'
-
This is similar to how L<ModPerl::Registry> works, but will only work for
well-written CGIs. Otherwise, you may have to override this method to do
something more involved (see L<ModPerl::PerlRun>.)
@@ -189,15 +187,23 @@
=cut
sub wrap_perl_cgi {
- my ($self, $cgi) = @_;
+ my ($self, $cgi, $action_name) = @_;
- do { no warnings; eval 'sub {' . slurp($cgi) . '}' }
+ do {
+ no warnings;
+# CGIs import stuff, so putting them into this package breaks Cat 5.8
+ eval '
+ package Catalyst::Controller::CGIBin::_CGIs_::'.$action_name.';
+ sub {' . slurp($cgi) . '}'
+ }
}
-=head2 $self->wrap_nonperl_cgi($path)
+=head2 $self->wrap_nonperl_cgi($path, $action_name)
Takes the path to a non-Perl CGI and returns a coderef for executing it.
+C<$action_name> is the generated name for the action representing the CGI file.
+
By default returns:
sub { system $path }
@@ -205,7 +211,7 @@
=cut
sub wrap_nonperl_cgi {
- my ($self, $cgi) = @_;
+ my ($self, $cgi, $action_name) = @_;
sub { system $cgi }
}
Modified: trunk/Catalyst-Controller-WrapCGI/lib/Catalyst/Controller/WrapCGI.pm
===================================================================
--- trunk/Catalyst-Controller-WrapCGI/lib/Catalyst/Controller/WrapCGI.pm 2008-11-19 19:30:34 UTC (rev 8623)
+++ trunk/Catalyst-Controller-WrapCGI/lib/Catalyst/Controller/WrapCGI.pm 2008-11-19 23:59:31 UTC (rev 8624)
@@ -15,27 +15,27 @@
=head1 VERSION
-Version 0.0023
+Version 0.0024
=cut
-our $VERSION = '0.0023';
+our $VERSION = '0.0024';
=head1 SYNOPSIS
package MyApp::Controller::Foo;
use parent qw/Catalyst::Controller::WrapCGI/;
+ use CGI ();
sub hello : Path('cgi-bin/hello.cgi') {
my ($self, $c) = @_;
$self->cgi_to_response($c, sub {
- use CGI ':standard';
-
- print header, start_html('Hello'),
- h1('Catalyst Rocks!'),
- end_html;
+ my $q = CGI->new;
+ print $q->header, $q->start_html('Hello'),
+ $q->h1('Catalyst Rocks!'),
+ $q->end_html;
});
}
@@ -55,6 +55,9 @@
Allows you to run Perl code in a CGI environment derived from your L<Catalyst>
context.
+B<*WARNING*>: do not export L<CGI> functions into a Controller, it will break
+with L<Catalyst> 5.8 onward.
+
If you just want to run CGIs from files, see L<Catalyst::Controller::CGIBin>.
=head1 CONFIGURATION
Modified: trunk/Catalyst-Controller-WrapCGI/t/lib/TestApp/Controller/Root.pm
===================================================================
--- trunk/Catalyst-Controller-WrapCGI/t/lib/TestApp/Controller/Root.pm 2008-11-19 19:30:34 UTC (rev 8623)
+++ trunk/Catalyst-Controller-WrapCGI/t/lib/TestApp/Controller/Root.pm 2008-11-19 23:59:31 UTC (rev 8624)
@@ -1,14 +1,14 @@
package TestApp::Controller::Root;
use parent 'Catalyst::Controller::WrapCGI';
+use CGI ();
__PACKAGE__->config->{namespace} = '';
my $cgi = sub {
- use CGI ':standard';
-
- print header;
- print 'foo:',param('foo'),' bar:',param('bar')
+ my $cgi = CGI->new;
+ print $cgi->header;
+ print 'foo:',$cgi->param('foo'),' bar:',$cgi->param('bar')
};
sub handle_cgi : Path('/cgi-bin/test.cgi') {
Modified: trunk/Catalyst-Controller-WrapCGI/t/lib/TestApp.pm
===================================================================
--- trunk/Catalyst-Controller-WrapCGI/t/lib/TestApp.pm 2008-11-19 19:30:34 UTC (rev 8623)
+++ trunk/Catalyst-Controller-WrapCGI/t/lib/TestApp.pm 2008-11-19 23:59:31 UTC (rev 8624)
@@ -1,6 +1,7 @@
package TestApp;
-use Catalyst;
+use Catalyst::Runtime '5.70';
+use parent 'Catalyst';
__PACKAGE__->setup;
Modified: trunk/Catalyst-Controller-WrapCGI/t/lib/TestCGIBin.pm
===================================================================
--- trunk/Catalyst-Controller-WrapCGI/t/lib/TestCGIBin.pm 2008-11-19 19:30:34 UTC (rev 8623)
+++ trunk/Catalyst-Controller-WrapCGI/t/lib/TestCGIBin.pm 2008-11-19 23:59:31 UTC (rev 8624)
@@ -1,6 +1,7 @@
package TestCGIBin;
-use Catalyst;
+use Catalyst::Runtime '5.70';
+use parent 'Catalyst';
__PACKAGE__->setup;
More information about the Catalyst-commits
mailing list