[Catalyst] Help with static and RegEx

Mike McKay mike at vdomck.org
Wed Jun 29 11:38:17 CEST 2005


Will Hawes wrote:
> I think ideally Catalyst should test for that and throw an error.

That would be great.

By the way, below is what I finally came up with. Not that I think this 
is best practice, or even the assumed usage for Catalyst::Plugin::Static 
but in case it would be useful to have some more code in the docs. I 
need to to make it ignore case, like m/foo/i - but I don't now how to do 
it with the Regex notation - can anyone help?

# want to match booking/style.css
# and style.css
# match anything after the last slash that is not a slash
sub staticFiles : Regex('^.*?/*([^/]*\.(css|js|html))$') {
     my ( $self, $c ) = @_;
     my ($file, $extension) = @{ $c->req->snippets };
     $c->req->path( "$file" );
     $c->serve_static;
}

sub images : Regex('^.*?/*([^/]*\.(jpg|png|gif|ico))$') {
     my ( $self, $c ) = @_;
     my ($file, $extension) = @{ $c->req->snippets };
     $c->req->path( "img/$file" );
     $c->serve_static;
}


>>Answering my own question:
>>
>>Mike McKay wrote:
>>
>>>So I am trying to serve all static pages out of the root directory. 
>>>Should be simple, but I am having trouble. It seems that the regex 
>>>matches, but then the handler doesn't execute:
>>>
>>># match anything after the slash that is not a slash
>>>sub files : Regex('/*([^/]*\.(css|js|html))$') {
>>
>><snip/>
>>
>>>code in the files method it never shows it. What is happening?
>>
>> From the documentation:
>>---
>>If you want to pass variable arguments at the end of a URL, you must
>>use regex actions keys with '^' and '$' anchors, and the arguments must
>>be separated with forward slashes (/) in the URL
>>---
>>
>>So boys and girls, today Mike learned that all RegEx URL handlers need 
>>to start with a caret.
>>
>>Cheers,
>>Mike
>>
>>
>>_______________________________________________
>>Catalyst mailing list
>>Catalyst at lists.rawmode.org
>>http://lists.rawmode.org/mailman/listinfo/catalyst
>>
>>
> 
> 
> 
> _______________________________________________
> Catalyst mailing list
> Catalyst at lists.rawmode.org
> http://lists.rawmode.org/mailman/listinfo/catalyst




More information about the Catalyst mailing list