Created
February 18, 2014 07:31
-
-
Save nanto/9066170 to your computer and use it in GitHub Desktop.
Run legacy applications which depend on environment variables.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package Plack::Middleware::ENV; | |
use strict; | |
use warnings; | |
use parent qw(Plack::Middleware); | |
sub call { | |
my ($self, $env) = @_; | |
my @fields = grep { m/^(?:HTTP.*|REMOTE_ADDR)$/ } keys %$env; | |
local @ENV{@fields} = @$env{@fields}; | |
return $self->app->($env); | |
} | |
1; | |
package main; | |
use Test::More; | |
use Plack::Builder; | |
$INC{'Plack/Middleware/ENV.pm'} = __FILE__; | |
my $app = builder { | |
enable 'Plack::Middleware::ENV'; | |
sub { | |
is $ENV{HTTP_USER_AGENT}, 'MyAgent/1.0'; | |
}; | |
}; | |
$app->({ HTTP_USER_AGENT => 'MyAgent/1.0' }); | |
done_testing; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment