Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Plack::Handler::Apache[12]: delete $ENV{MOD_PERL}, don't just localiz…

…e it

Some software such as CGI::Cookie does "exists $ENV{MOD_PERL}" to
check if it's running under mod_perl instead of just checking whether
$ENV{MOD_PERL} is true.

So that code that does this doesn't assume it's running under Apache
locally delete $ENV{MOD_PERL} instead of just setting its value to
undef.

Note that we're not doing "delete local $ENV{MOD_PERL}" because that
construct was introduced in 5.12, also note why we're doing it this
way in the code
http://perldoc.perl.org/5.12.0/perldelta.html#delete-local

So before we'd have:

    $ perl -MData::Dumper -wle 'our %hash = qw(MOD_PERL yes foo bar); { local $hash{MOD_PERL}; print Dumper \%hash; } print Dumper \%hash'
    $VAR1 = {
              'foo' => 'bar',
              'MOD_PERL' => undef
            };
    $VAR1 = {
              'foo' => 'bar',
              'MOD_PERL' => 'yes'
            };

And now we have:

    $ perl -MData::Dumper -wle 'our %hash = qw(MOD_PERL yes foo bar); { local $hash{MOD_PERL}; delete $hash{MOD_PERL}; print Dumper \%hash; } print Dumper \%hash'
    $VAR1 = {
              'foo' => 'bar'
            };
    $VAR1 = {
              'foo' => 'bar',
              'MOD_PERL' => 'yes'
            };
  • Loading branch information...
commit b7a63de6f71380adee522e4f5c6714930b51317a 1 parent aae534a
@avar avar authored
Showing with 22 additions and 2 deletions.
  1. +11 −1 lib/Plack/Handler/Apache1.pm
  2. +11 −1 lib/Plack/Handler/Apache2.pm
View
12 lib/Plack/Handler/Apache1.pm
@@ -20,7 +20,17 @@ sub preload {
sub load_app {
my($class, $app) = @_;
return $apps{$app} ||= do {
- local $ENV{MOD_PERL}; # trick Catalyst/CGI.pm etc.
+ # Trick Catalyst, CGI.pm, CGI::Cookie and others that check
+ # for $ENV{MOD_PERL}.
+ #
+ # Note that we delete it instead of just localizing
+ # $ENV{MOD_PERL} because some users may check if the key
+ # exists, and we do it this way because "delete local" is new
+ # in 5.12:
+ # http://perldoc.perl.org/5.12.0/perldelta.html#delete-local
+ local $ENV{MOD_PERL};
+ delete $ENV{MOD_PERL};
+
Plack::Util::load_psgi $app;
};
}
View
12 lib/Plack/Handler/Apache2.pm
@@ -28,7 +28,17 @@ sub preload {
sub load_app {
my($class, $app) = @_;
return $apps{$app} ||= do {
- local $ENV{MOD_PERL}; # trick Catalyst/CGI.pm etc.
+ # Trick Catalyst, CGI.pm, CGI::Cookie and others that check
+ # for $ENV{MOD_PERL}.
+ #
+ # Note that we delete it instead of just localizing
+ # $ENV{MOD_PERL} because some users may check if the key
+ # exists, and we do it this way because "delete local" is new
+ # in 5.12:
+ # http://perldoc.perl.org/5.12.0/perldelta.html#delete-local
+ local $ENV{MOD_PERL};
+ delete $ENV{MOD_PERL};
+
Plack::Util::load_psgi $app;
};
}
Please sign in to comment.
Something went wrong with that request. Please try again.