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

Matt S Trout dbix-class at trout.me.uk
Sun Jan 15 22:42:36 CET 2006


On Sat, Jan 14, 2006 at 04:57:39PM -0800, apv wrote:
> Using an .htaccess rewrite like so (partially cargo culted):
> 
>  DirectoryIndex index.fcgi index.pl
> 
>  RewriteCond %{REQUEST_FILENAME}   !-d
>  RewriteCond %{REQUEST_FILENAME}   !-f
>  RewriteRule ^(.*) index.fcgi/$1 [QSA,L]
> 
> I can get nice relative URIs from wherever the app is. But they get the
>   /wherever/index.fcgi/path/args
> with the index file inserted in there. Nothing wrong with it but it's
> not necessary, terse, or pretty. So I'm overriding uri_for() like so:
> 
>  *Catalyst::uri_for =
>  sub {
>  # nothing changes until last line, then we
>  # tweak the $res before returning it
>      $res =~ s{/index.(?:fcgi|pl)}{};
>      $res;
>  };
> 
> I think there is probably a better way to do this, yes?

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;
}

-- 
     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/ +



More information about the Catalyst mailing list