->req->remote_user support, new release
Rafael Kitover [Tue, 26 May 2009 22:46:25 +0000 (22:46 +0000)]
Changes
Makefile.PL
lib/Catalyst/Controller/CGIBin.pm
lib/Catalyst/Controller/WrapCGI.pm
lib/CatalystX/GlobalContext.pm
t/lib/TestApp/Controller/Root.pm
t/wrap-cgi.t

diff --git a/Changes b/Changes
index 4e7db3c..c6b20b1 100644 (file)
--- 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)
 
index 716a09c..d0146e8 100644 (file)
@@ -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;
index ef1ed86..bad6d1d 100644 (file)
@@ -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<root/cgi-bin> such as C<foo/bar.cgi> and returns
 the action name it is registered as. See L</DESCRIPTION> 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<root/cgi-bin> such as C<foo/bar.cgi> 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<Catalyst::Controller::WrapCGI>.)
@@ -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.
 
index 0a2d748..09f3a7a 100644 (file)
@@ -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<Catalyst> 5.8 onward.
 
 If you just want to run CGIs from files, see L<Catalyst::Controller::CGIBin>.
 
+C<REMOTE_USER> 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<HTTP::Request::AsCGI>, returns an
 L<HTTP::Response>.
 
-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</SYNOPSIS> 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</FILTERED ENVIRONMENT>.
 
 Used by L</cgi_to_response>, 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 };
index d3f13b5..44f9b10 100644 (file)
@@ -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
 
index d691011..b473a81 100644 (file)
@@ -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;
index 2c98bda..57f4ff9 100644 (file)
@@ -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');