[Catalyst] Branding - or path prefix

phaylon phaylon at dunkelheit.at
Mon Aug 1 17:23:41 CEST 2005


Hi there, me again.

Am Sonntag, den 31.07.2005, 17:31 +0200 schrieb phaylon:

> Someone hit me if I'm wrong, but this should be possible by overloading
> prepare_request with NEXT. I don't know if the stash is already available
> at that time, but you could also store it in your App's config space.
> 
> It get's the arguments passed, so you'd just have to work on them before
> passing them to $c->NEXT::prepare_request.

Well, I was wrong. prepare_request gets @arguments, but i don't know
what it contains. $c->req->args is set at the beginning of
prepare_action, so I overloaded this, to have direct access to the
arguments afterwards. Here's a quick example Plugin:

#===/ C::P::PathPrefix /===
package Catalyst::Plugin::PathPrefix;
use strict;
use NEXT;
                                                                                                                                            
sub prepare_action {
    my ( $c, @rest ) = @_;
    my $r = $c->NEXT::prepare_action( @rest );

    #-- this line cuts of the first arg and puts it in the stash
    $c->stash->{path_prefix} = shift @{ $c->request->args };  

    $c->log->debug( 'Prefix is ' . $c->stash->{path_prefix} );
    return $r;
}

1;
__END__


Hope that helps. I'd have a productive plugin, but I didn't need the
behaviour yet.

-- 
http://www.dunkelheit.at/
thou shallst fear ..





More information about the Catalyst mailing list