Background:
I'm using a CRUD framework in Catalyst that auto-generates forms and lists for all tables in a given database. For example:
/admin/list/person or /admin/add/person or /admin/edit/person/3 all dynamically generate pages or forms as appropriate for the table 'person'. (In other words, Admin.pm has actions edit, list, add, delete and so on that expect a table argument and possibly a row-identifying argument.)
Question:
In the particular application I'm building, the database will be used by multiple customers, so I want to introduce a URI scheme where the first element is the customer's identifier, followed by the administrative action/table etc:
/cust1/admin/list/person
/cust2/admin/add/person
/cust2/admin/edit/person/3
This is for "branding" purposes, and also to ensure that bookmarks or URLs passed from one user to another do the expected thing.
But I'm having a lot of trouble getting this to work. I would prefer not to have to modify the subs in the existing framework, so I've been trying variations on the following:
sub customer : Regex('^(\w+)/(admin)$') {
my ($self, $c, @args) = @_;
#validation of captured arg snipped..
my $path = join('/', 'admin', @args);
$c->request->path($path);
$c->dispatcher->prepare_action($c);
$c->forward($c->action, $c->req->args);
}
But it just will not behave. I've used regex matching actions many times, but putting one in the very first 'barrel' of a URI seems unusually traumatic. Any suggestions gratefully received.