From: Rafael Kitover Date: Tue, 26 May 2009 22:46:25 +0000 (+0000) Subject: ->req->remote_user support, new release X-Git-Tag: 0.030~25 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Controller-WrapCGI.git;a=commitdiff_plain;h=b9548267055b5d4dd01a342a40cc6e0ddf166460 ->req->remote_user support, new release --- diff --git a/Changes b/Changes index 4e7db3c..c6b20b1 100644 --- a/Changes +++ b/Changes @@ -1,5 +1,9 @@ Revision history for Catalyst-Controller-WrapCGI +0.016 2009-05-26 22:35:09 + - fallback to $c->req->remote_user for $ENV{REMOTE_USER} + - fix POD + 0.0037 2009-05-06 20:07:00 - pass captures in SCRIPT_NAME (caelum) diff --git a/Makefile.PL b/Makefile.PL index 716a09c..d0146e8 100644 --- a/Makefile.PL +++ b/Makefile.PL @@ -21,8 +21,7 @@ test_requires 'CGI'; build_requires 'Test::More' => '0.86'; +auto_provides; auto_install; - resources repository => 'http://dev.catalyst.perl.org/repos/Catalyst/trunk/Catalyst-Controller-WrapCGI/'; - WriteAll; diff --git a/lib/Catalyst/Controller/CGIBin.pm b/lib/Catalyst/Controller/CGIBin.pm index ef1ed86..bad6d1d 100644 --- a/lib/Catalyst/Controller/CGIBin.pm +++ b/lib/Catalyst/Controller/CGIBin.pm @@ -23,11 +23,11 @@ Catalyst::Controller::CGIBin - Serve CGIs from root/cgi-bin =head1 VERSION -Version 0.015 +Version 0.016 =cut -our $VERSION = '0.015'; +our $VERSION = '0.016'; =head1 SYNOPSIS @@ -154,7 +154,7 @@ sub register_actions { =head2 cgi_action -C<<$self->cgi_action($cgi)>> +C<< $self->cgi_action($cgi) >> Takes a path to a CGI from C such as C and returns the action name it is registered as. See L for a discussion on how @@ -182,7 +182,7 @@ sub cgi_action { =head2 cgi_path -C<<$self->cgi_path($cgi)>> +C<< $self->cgi_path($cgi) >> Takes a path to a CGI from C such as C and returns the public path it should be registered under. @@ -202,7 +202,7 @@ sub cgi_path { =head2 is_perl_cgi -C<<$self->is_perl_cgi($path)>> +C<< $self->is_perl_cgi($path) >> Tries to figure out whether the CGI is Perl or not. @@ -230,7 +230,7 @@ sub is_perl_cgi { =head2 wrap_perl_cgi -C<<$self->wrap_perl_cgi($path, $action_name)>> +C<< $self->wrap_perl_cgi($path, $action_name) >> Takes the path to a Perl CGI and returns a coderef suitable for passing to cgi_to_response (from L.) @@ -294,7 +294,7 @@ sub wrap_perl_cgi { =head2 wrap_nonperl_cgi -C<<$self->wrap_nonperl_cgi($path, $action_name)>> +C<< $self->wrap_nonperl_cgi($path, $action_name) >> Takes the path to a non-Perl CGI and returns a coderef for executing it. diff --git a/lib/Catalyst/Controller/WrapCGI.pm b/lib/Catalyst/Controller/WrapCGI.pm index 0a2d748..09f3a7a 100644 --- a/lib/Catalyst/Controller/WrapCGI.pm +++ b/lib/Catalyst/Controller/WrapCGI.pm @@ -20,11 +20,11 @@ Catalyst::Controller::WrapCGI - Run CGIs in Catalyst =head1 VERSION -Version 0.0037 +Version 0.016 =cut -our $VERSION = '0.0037'; +our $VERSION = '0.016'; =head1 SYNOPSIS @@ -66,6 +66,9 @@ with L 5.8 onward. If you just want to run CGIs from files, see L. +C will be set to C<< $c->user->obj->$username_field >> if +available, or to C<< $c->req->remote_user >> otherwise. + =head1 CONFIGURATION =head2 pass_env @@ -104,7 +107,7 @@ open my $REAL_STDOUT, ">>&=".fileno(*STDOUT); =head2 cgi_to_response -C<<$self->cgi_to_response($c, $coderef)>> +C<< $self->cgi_to_response($c, $coderef) >> Does the magic of running $coderef in a CGI environment, and populating the appropriate parts of your Catalyst context with the results. @@ -134,16 +137,17 @@ sub cgi_to_response { =head2 wrap_cgi -C<<$self->wrap_cgi($c, $coderef)>> +C<< $self->wrap_cgi($c, $coderef) >> Runs $coderef in a CGI environment using L, returns an L. -The CGI environment is set up based on $c. +The CGI environment is set up based on C<$c>. The environment variables to pass on are taken from the configuration for your Controller, see L for an example. If you don't supply a list of -environment variables to pass, the whole of %ENV is used. +environment variables to pass, the whole of %ENV is used (with exceptions listed +in L. Used by L, which is probably what you want to use as well. @@ -203,6 +207,8 @@ sub wrap_cgi { ? eval { $c->user->obj->$username_field } : ''); + $username ||= $c->req->remote_user if $c->req->can('remote_user'); + my $path_info = '/'.join '/' => map { utf8::is_utf8($_) ? uri_escape_utf8($_) : uri_escape($_) } @{ $c->req->args }; diff --git a/lib/CatalystX/GlobalContext.pm b/lib/CatalystX/GlobalContext.pm index d3f13b5..44f9b10 100644 --- a/lib/CatalystX/GlobalContext.pm +++ b/lib/CatalystX/GlobalContext.pm @@ -15,11 +15,11 @@ CatalystX::GlobalContext - Export Catalyst Context =head1 VERSION -Version 0.01 +Version 0.016 =cut -our $VERSION = '0.01'; +our $VERSION = '0.016'; =head1 SYNOPSIS diff --git a/t/lib/TestApp/Controller/Root.pm b/t/lib/TestApp/Controller/Root.pm index d691011..b473a81 100644 --- a/t/lib/TestApp/Controller/Root.pm +++ b/t/lib/TestApp/Controller/Root.pm @@ -57,4 +57,14 @@ sub test_script_name : Chained('test_script_name_root') PathPart('test_scriptnam }); } +sub test_remote_user : Path('/cgi-bin/test_remote_user.cgi') Args(0) { + my ($self, $c) = @_; + + $self->cgi_to_response($c, sub { + my $cgi = CGI->new; + print $cgi->header; + print $ENV{REMOTE_USER} + }); +} + 1; diff --git a/t/wrap-cgi.t b/t/wrap-cgi.t index 2c98bda..57f4ff9 100644 --- a/t/wrap-cgi.t +++ b/t/wrap-cgi.t @@ -6,7 +6,7 @@ use warnings; use FindBin '$Bin'; use lib "$Bin/lib"; -use Test::More tests => 6; +use Test::More tests => 7; use Catalyst::Test 'TestApp'; use HTTP::Request::Common; @@ -52,3 +52,7 @@ is($response->content, '/test_filepath_info/path/%2Finfo', $response = request '/cgi-bin/mtfnpy/test_scriptname.cgi/foo/bar'; is($response->content, '/cgi-bin/mtfnpy/test_scriptname.cgi', 'SCRIPT_NAME is correct'); + +$ENV{REMOTE_USER} = 'TEST_USER'; +$response = request '/cgi-bin/test_remote_user.cgi'; +is($response->content, 'TEST_USER', 'REMOTE_USER was passed');