Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

C::C::CGIBin: add support for __DATA__ sections in CGIs

  • Loading branch information...
commit 1ce18a56f230cec72ad9a2c94eabb4b4103851ab 1 parent 46a4350
@rkitover rkitover authored
View
3  Changes
@@ -22,3 +22,6 @@ Revision history for Catalyst-Controller-WrapCGI
0.0027 2009-04-03 14:55:34
Add 'kill_env' and default to killing 'MOD_PERL' from environment.
+
+0.0028 2009-04-24 04:40:39
+ Add support for __DATA__ sections in cgis for C::CGIBin
View
8 Makefile.PL
@@ -6,7 +6,6 @@ author 'Matt S. Trout <mst@shadowcat.co.uk>';
include 'Module::AutoInstall';
requires 'Catalyst' => '5.7007';
-requires 'Class::C3' => '0.20';
requires 'parent';
requires 'Task::Weaken';
requires 'HTTP::Request::AsCGI';
@@ -16,6 +15,13 @@ requires 'List::MoreUtils';
requires 'File::Slurp';
requires 'namespace::clean';
+requires 'MRO::Compat';
+
+if($] < 5.009_005) {
+ requires 'Class::C3::XS' => '0.08';
+ requires 'Class::C3' => '0.20';
+}
+
test_requires 'Catalyst::Plugin::Static::Simple';
build_requires 'Test::More' => '0.86';
View
27 lib/Catalyst/Controller/CGIBin.pm
@@ -3,7 +3,8 @@ package Catalyst::Controller::CGIBin;
use strict;
use warnings;
-use Class::C3;
+use MRO::Compat;
+use mro 'c3';
use File::Slurp 'slurp';
use File::Find::Rule ();
use Catalyst::Exception ();
@@ -12,6 +13,7 @@ use IPC::Open3;
use Symbol 'gensym';
use List::MoreUtils 'any';
use IO::File ();
+use Carp;
use namespace::clean -except => 'meta';
use parent 'Catalyst::Controller::WrapCGI';
@@ -22,11 +24,11 @@ Catalyst::Controller::CGIBin - Serve CGIs from root/cgi-bin
=head1 VERSION
-Version 0.005
+Version 0.006
=cut
-our $VERSION = '0.005';
+our $VERSION = '0.006';
=head1 SYNOPSIS
@@ -194,12 +196,25 @@ something more involved (see L<ModPerl::PerlRun>.)
sub wrap_perl_cgi {
my ($self, $cgi, $action_name) = @_;
- do {
+ my $code = slurp $cgi;
+
+ $code =~ s/^__DATA__\r?\n(.*)//ms;
+ my $data = $1;
+
+ my $coderef = do {
no warnings;
eval '
package Catalyst::Controller::CGIBin::_CGIs_::'.$action_name.';
- sub {' . slurp($cgi) . '}'
- }
+ sub {'
+ . 'local *DATA;'
+ . q{open DATA, '<', \$data;}
+ . $code
+ . '}';
+ };
+
+ croak __PACKAGE__ . ": Could not compile $cgi to coderef: $@" if $@;
+
+ $coderef
}
=head2 $self->wrap_nonperl_cgi($path, $action_name)
View
4 lib/Catalyst/Controller/WrapCGI.pm
@@ -15,11 +15,11 @@ Catalyst::Controller::WrapCGI - Run CGIs in Catalyst
=head1 VERSION
-Version 0.0027
+Version 0.0028
=cut
-our $VERSION = '0.0027';
+our $VERSION = '0.0028';
=head1 SYNOPSIS
Please sign in to comment.
Something went wrong with that request. Please try again.