[Catalyst-commits] r12589 - in
Catalyst-Runtime/5.80/branches/psgi/lib: . Catalyst Plack
Plack/Middleware
rafl at dev.catalyst.perl.org
rafl at dev.catalyst.perl.org
Sun Jan 10 04:09:53 GMT 2010
Author: rafl
Date: 2010-01-10 04:09:52 +0000 (Sun, 10 Jan 2010)
New Revision: 12589
Added:
Catalyst-Runtime/5.80/branches/psgi/lib/Plack/
Catalyst-Runtime/5.80/branches/psgi/lib/Plack/Middleware/
Catalyst-Runtime/5.80/branches/psgi/lib/Plack/Middleware/OverrideEnv.pm
Modified:
Catalyst-Runtime/5.80/branches/psgi/lib/Catalyst/Test.pm
Log:
Add a way to specify additional psgi values in the psgi env via Catalyst::Test.
Modified: Catalyst-Runtime/5.80/branches/psgi/lib/Catalyst/Test.pm
===================================================================
--- Catalyst-Runtime/5.80/branches/psgi/lib/Catalyst/Test.pm 2010-01-10 02:00:30 UTC (rev 12588)
+++ Catalyst-Runtime/5.80/branches/psgi/lib/Catalyst/Test.pm 2010-01-10 04:09:52 UTC (rev 12589)
@@ -5,6 +5,7 @@
use Test::More ();
use Plack::Test;
+use Plack::Middleware::OverrideEnv;
use Catalyst::Exception;
use Catalyst::Utils;
use Class::MOP;
@@ -225,10 +226,17 @@
my $app = shift;
my $request = Catalyst::Utils::request(shift);
- _customize_request($request, @_);
+ my %extra_env;
+ _customize_request($request, \%extra_env, @_);
my $ret;
- test_psgi app => $app, client => sub { $ret = shift->($request) };
+ test_psgi
+ app => Plack::Middleware::OverrideEnv->wrap(
+ $app, env_override => \%extra_env,
+ ),
+ client => sub {
+ $ret = shift->($request);
+ };
return $ret;
}
@@ -303,11 +311,16 @@
sub _customize_request {
my $request = shift;
+ my $extra_env = shift;
my $opts = pop(@_) || {};
$opts = {} unless ref($opts) eq 'HASH';
if ( my $host = exists $opts->{host} ? $opts->{host} : $default_host ) {
$request->header( 'Host' => $host );
}
+
+ if (my $extra = $opts->{extra_env}) {
+ @{ $extra_env }{keys %{ $extra }} = values %{ $extra };
+ }
}
=head2 action_ok
Added: Catalyst-Runtime/5.80/branches/psgi/lib/Plack/Middleware/OverrideEnv.pm
===================================================================
--- Catalyst-Runtime/5.80/branches/psgi/lib/Plack/Middleware/OverrideEnv.pm (rev 0)
+++ Catalyst-Runtime/5.80/branches/psgi/lib/Plack/Middleware/OverrideEnv.pm 2010-01-10 04:09:52 UTC (rev 12589)
@@ -0,0 +1,14 @@
+package Plack::Middleware::OverrideEnv;
+
+use strict;
+use warnings;
+use parent 'Plack::Middleware';
+
+use Plack::Util::Accessor qw(env_override);
+
+sub call {
+ my ($self, $env) = @_;
+ return $self->app->({ %{ $env }, %{ $self->env_override || {} } });
+}
+
+1;
More information about the Catalyst-commits
mailing list