tags:

views:

188

answers:

2

Hello!

I have trouble creating a Catalyst action that would match a single file in the root directory. I would like to match URLs that look like this:

http://foo:3000/about.html

I have written the following action in the root controller:

sub static :Path :Args(1)
{
    my ($self, $c, $file) = @_;
    …
}

But the action does not match, Catalyst runs the default action instead. What am I doing wrong?

+2  A: 

OK, this seems to be some kind of backwards compatibility bug. The following works (just declare the handle_404 action before the other actions in the controller:

package TestApp::Controller::Root;

use strict;
use warnings;
use parent 'Catalyst::Controller';

__PACKAGE__->config->{namespace} = '';

sub handle_404 :Path {
    my ( $self, $c ) = @_;
    $c->response->body( 'Page not found' );
    $c->response->status(404);
}

sub anaction :Path : Args(1) {
    my ($self, $c, $arg) = @_;
    $c->res->body($arg);
}

sub end : ActionClass('RenderView') {}

1;

and then run the test script:

$ CATALYST_DEBUG=0 script/testapp_test.pl /foo
foo
singingfish
Yes, this works. Thank you very much.
zoul
+4  A: 

rev 10406 in the Catalyst subversion is a failing test for your issue, we can confirm that it's a bug. This has been broken forever, it's unfortunate that nobody has given us a bug report or 'officially' discovered it before :/

I'll try to fix that (or get someone else to fix it) this week, and we'll ship 5.80005 once that's done as there are enough other fixes ready in trunk for that to be worthwhile.

Thanks everyone who brought this to the core team's attention, singingfish++