Gert Burger wrote: > -Using the game as part of the url, eg > http://bla/games/ageofempires3/gamebooking, this will complicate the > controller's methods a bit as each method will be a regex.
The game-as-part-of-URL seem to be the cleanest approach to me:
Why not extend prepare_path globally with something like (untested):
sub prepare_path {
my $c = shift;
$c->NEXT::prepare_path(@_);
my $base = $c->req->base;
my $path = $c->req->path;
if ($path =~ m!^(game1|game2)/!) {
my $game = $1;
$c->stash->{game} = $game;
## optionally rm $game from URL
$path =~ s!^$game/!!;
$c->req->path($path);
}
return;
}
Now game can be found in $c->stash->{game}
You my also overwrite the behavior of $c->uri_for by using a Plugin
(again untested):
package Catalyst::Plugin::GameContext;
use strict;
use Next;
use URI;
sub uri_for {
my $c = shift;
my $uri = URI->new( $c->NEXT::uri_for( @_ ) );
$uri->path( $c->stash->{game} . $uri->path )
unless $uri->path =~ m!/(?:css|i|js)/!;
return $uri->as_string;
}
and include it with
use Catalyst qw(ConfigLoader DefaultEnd GameContext Static::Simple);
-Thomas
smime.p7s
Description: S/MIME Cryptographic Signature
_______________________________________________ List: [email protected] Listinfo: http://lists.rawmode.org/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/[email protected]/ Dev site: http://dev.catalyst.perl.org/
