[Catalyst-commits] r12196 - in trunk/Catalyst-Controller-WrapCGI: .
lib/Catalyst/Controller lib/CatalystX
caelum at dev.catalyst.perl.org
caelum at dev.catalyst.perl.org
Sun Dec 6 05:19:14 GMT 2009
Author: caelum
Date: 2009-12-06 05:19:14 +0000 (Sun, 06 Dec 2009)
New Revision: 12196
Modified:
trunk/Catalyst-Controller-WrapCGI/Changes
trunk/Catalyst-Controller-WrapCGI/lib/Catalyst/Controller/CGIBin.pm
trunk/Catalyst-Controller-WrapCGI/lib/Catalyst/Controller/WrapCGI.pm
trunk/Catalyst-Controller-WrapCGI/lib/CatalystX/GlobalContext.pm
Log:
handle scripts that override $SIG{__DIE__} and $SIG{__WARN__}
Modified: trunk/Catalyst-Controller-WrapCGI/Changes
===================================================================
--- trunk/Catalyst-Controller-WrapCGI/Changes 2009-12-06 03:50:13 UTC (rev 12195)
+++ trunk/Catalyst-Controller-WrapCGI/Changes 2009-12-06 05:19:14 UTC (rev 12196)
@@ -1,5 +1,8 @@
Revision history for Catalyst-Controller-WrapCGI
+0.022 2009-12-06 05:18:08
+ - handle scripts that override $SIG{__DIE__} and $SIG{__WARN__}
+
0.021 2009-12-04 21:05:14
- better is_perl_cgi determination that also allows using MyApp->foo
methods
Modified: trunk/Catalyst-Controller-WrapCGI/lib/Catalyst/Controller/CGIBin.pm
===================================================================
--- trunk/Catalyst-Controller-WrapCGI/lib/Catalyst/Controller/CGIBin.pm 2009-12-06 03:50:13 UTC (rev 12195)
+++ trunk/Catalyst-Controller-WrapCGI/lib/Catalyst/Controller/CGIBin.pm 2009-12-06 05:19:14 UTC (rev 12196)
@@ -24,11 +24,11 @@
=head1 VERSION
-Version 0.021
+Version 0.022
=cut
-our $VERSION = '0.021';
+our $VERSION = '0.022';
=head1 SYNOPSIS
@@ -259,9 +259,13 @@
my $code = slurp $cgi;
- $code =~ s/^__DATA__(?:\r?\n|\r\n?)(.*)//ms;
+ $code =~ s/^__DATA__\n(.*)//ms;
my $data = $1;
+ my $orig_exit = \*CORE::GLOBAL::exit;
+ my $orig_die = $SIG{__DIE__};
+ my $orig_warn = $SIG{__WARN__};
+
my $coderef = do {
no warnings;
# catch exit() and turn it into (effectively) a return
@@ -269,17 +273,19 @@
# overridden CORE::GLOBAL::exit in view
#
# set $0 to the name of the cgi file in case it's used there
- eval '
+ my $source = '
my $cgi_exited = "EXIT\n";
BEGIN { *CORE::GLOBAL::exit = sub (;$) {
die [ $cgi_exited, $_[0] || 0 ];
} }
package Catalyst::Controller::CGIBin::_CGIs_::'.$action_name.';
- sub {'
- . 'local *DATA;'
- . q{open DATA, '<', \$data;}
- . qq{local \$0 = "\Q$cgi\E";}
- . q/my $rv = eval {/
+ sub {'."\n"
+ . 'local *DATA;'."\n"
+ . q{open DATA, '<', \$data;}."\n"
+ . qq{local \$0 = "\Q$cgi\E";}."\n"
+ . q/my $rv = eval {/."\n"
+ . 'local $SIG{__DIE__} = $SIG{__DIE__} || sub { die @_ };'."\n"
+ . 'local $SIG{__WARN__} = $SIG{__WARN__} || sub { warn @_ };'."\n"
. $code
. q/};/
. q{
@@ -292,11 +298,17 @@
return $rv;
}
. '}';
+ eval $source;
};
+ # clean up
+ *CORE::GLOBAL::exit = $orig_exit;
+ $SIG{__DIE__} = $orig_die;
+ $SIG{__WARN__} = $orig_warn;
+
croak __PACKAGE__ . ": Could not compile $cgi to coderef: $@" if $@;
- $coderef
+ return $coderef
}
=head2 wrap_nonperl_cgi
Modified: trunk/Catalyst-Controller-WrapCGI/lib/Catalyst/Controller/WrapCGI.pm
===================================================================
--- trunk/Catalyst-Controller-WrapCGI/lib/Catalyst/Controller/WrapCGI.pm 2009-12-06 03:50:13 UTC (rev 12195)
+++ trunk/Catalyst-Controller-WrapCGI/lib/Catalyst/Controller/WrapCGI.pm 2009-12-06 05:19:14 UTC (rev 12196)
@@ -20,11 +20,11 @@
=head1 VERSION
-Version 0.021
+Version 0.022
=cut
-our $VERSION = '0.021';
+our $VERSION = '0.022';
=head1 SYNOPSIS
Modified: trunk/Catalyst-Controller-WrapCGI/lib/CatalystX/GlobalContext.pm
===================================================================
--- trunk/Catalyst-Controller-WrapCGI/lib/CatalystX/GlobalContext.pm 2009-12-06 03:50:13 UTC (rev 12195)
+++ trunk/Catalyst-Controller-WrapCGI/lib/CatalystX/GlobalContext.pm 2009-12-06 05:19:14 UTC (rev 12196)
@@ -15,11 +15,11 @@
=head1 VERSION
-Version 0.021
+Version 0.022
=cut
-our $VERSION = '0.021';
+our $VERSION = '0.022';
=head1 SYNOPSIS
More information about the Catalyst-commits
mailing list