[Catalyst] Overriding uri_for() -- sane? better way

apv apv at sedition.com
Sun Jan 15 23:32:45 CET 2006


Okay, here's the "final" less-brittle (I hope) setup for running 
transparent URIs through uri_for() with CGI and FastCGI. With previous 
.htaccess rewriting taken as given.

# in MyApp
use File::Spec;
__PACKAGE__->config( script => (File::Spec->splitpath($0))[-1] );

sub uri_for {
     my $self = shift;
     my $uri = $self->NEXT::uri_for(@_);
     my $script = $self->config->{script};
     $uri =~ s{/$script(?=/)}{};
     $uri;
}

I thought about adding it to the wiki but couldn't think of a 
reasonable title or place.

-Ashley

On Sunday, January 15, 2006, at 02:22  PM, Matt S Trout wrote:

> On Sun, Jan 15, 2006 at 01:53:34PM -0800, apv wrote:
>> On Sunday, January 15, 2006, at 01:42  PM, Matt S Trout wrote:
>>> Why not just add a uri_for method to MyApp?
>>>
>>> sub uri_for {
>>>  my $self = shift;
>>>  my $uri = $self->NEXT::uri_for(@_);
>>>  $uri =~ s{/index.(?:fcgi|pl)}{};
>>>  $uri;
>>> }
>>
>> Why not? Because I are too dumb. Thanks! I promise to read the full
>> NEXT related docs before asking any more questions today.
>
> Well, in this case SUPER would probably have worked just fine too :P
>
> -- 
>      Matt S Trout       Offering custom development, consultancy and 
> support
>   Technical Director    contracts for Catalyst, DBIx::Class and BAST. 
> Contact
> Shadowcat Systems Ltd.  mst (at) shadowcatsystems.co.uk for more 
> information
>
>  + Help us build a better perl ORM: 
> http://dbix-class.shadowcatsystems.co.uk/ +
>
> _______________________________________________
> Catalyst mailing list
> Catalyst at lists.rawmode.org
> http://lists.rawmode.org/mailman/listinfo/catalyst
>
>




More information about the Catalyst mailing list