From: Hans Dieter Pearcey Date: Sun, 26 Apr 2009 00:36:57 +0000 (+0000) Subject: allow overriding of public cgi-bin paths X-Git-Tag: 0.030~49 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=9cc2dd4cf91d00221ca404219404c1b9bfbf8a80;p=catagits%2FCatalyst-Controller-WrapCGI.git allow overriding of public cgi-bin paths --- diff --git a/Changes b/Changes index d3497c8..b897206 100644 --- a/Changes +++ b/Changes @@ -25,3 +25,6 @@ Revision history for Catalyst-Controller-WrapCGI 0.0028 2009-04-24 04:40:39 Add support for __DATA__ sections in cgis for C::CGIBin + +0.0029 + Allow more control over public paths to CGIBin actions. diff --git a/lib/Catalyst/Controller/CGIBin.pm b/lib/Catalyst/Controller/CGIBin.pm index 3ffc19b..5859ad8 100644 --- a/lib/Catalyst/Controller/CGIBin.pm +++ b/lib/Catalyst/Controller/CGIBin.pm @@ -91,8 +91,9 @@ sub register_actions { my $path = join '/' => splitdir($cgi_path); my $action_name = $self->cgi_action($path); + my $public_path = $self->cgi_path($path); my $reverse = $namespace ? "$namespace/$action_name" : $action_name; - my $attrs = { Path => [ "cgi-bin/$path" ], Args => [ 0 ] }; + my $attrs = { Path => [ $public_path ], Args => [ 0 ] }; my ($cgi, $type); @@ -134,7 +135,7 @@ sub register_actions { =head1 METHODS -=head2 $self->cgi_action($cgi_path) +=head2 $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 @@ -151,6 +152,20 @@ sub cgi_action { $action_name } +=head2 $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. + +The default is C. + +=cut + +sub cgi_path { + my ($self, $cgi) = @_; + return "cgi-bin/$cgi"; +} + =head2 $self->is_perl_cgi($path) Tries to figure out whether the CGI is Perl or not. diff --git a/t/cgibin.t b/t/cgibin.t index f8271fa..8340633 100644 --- a/t/cgibin.t +++ b/t/cgibin.t @@ -14,7 +14,7 @@ use HTTP::Request::Common; # this should be ignored $ENV{MOD_PERL} = "mod_perl/2.0"; -my $response = request POST '/cgi-bin/path/test.pl', [ +my $response = request POST '/my-bin/path/test.pl', [ foo => 'bar', bar => 'baz' ]; @@ -41,5 +41,5 @@ SKIP: { skip "Can't run shell scripts on non-*nix", 1 if $^O eq 'MSWin32' || $^O eq 'VMS'; - is(get('/cgi-bin/test.sh'), "Hello!\n", 'Non-Perl CGI File'); + is(get('/my-bin/test.sh'), "Hello!\n", 'Non-Perl CGI File'); } diff --git a/t/lib/TestCGIBin/Controller/CGIHandler.pm b/t/lib/TestCGIBin/Controller/CGIHandler.pm index 12c4592..0e18ee6 100644 --- a/t/lib/TestCGIBin/Controller/CGIHandler.pm +++ b/t/lib/TestCGIBin/Controller/CGIHandler.pm @@ -2,6 +2,11 @@ package TestCGIBin::Controller::CGIHandler; use parent 'Catalyst::Controller::CGIBin'; +sub cgi_path { + my ($self, $cgi) = @_; + return "my-bin/$cgi"; +} + # try out a forward sub dongs : Local Args(0) { my ($self, $c) = @_;