Background:
I use the CRUD structure in Catalyst, which automatically generates forms and lists for all tables in this database. For example: / admin / list / person or / admin / add / person or / admin / edit / person / 3 all dynamically generate pages or forms corresponding to the person table. (In other words, Admin.pm has actions that edit, list, add, delete, etc. that expect a table argument and possibly a row identification argument.)
Question:
In the specific application that I create, the database will be used by several clients, so I want to introduce a URI scheme, where the first element is the client identifier, and then the administrative action / table, etc.:
- / cust1 / admin / list / person
- / cust2 / admin / add / person
- / cust2 / admin / edit / person / 3
This is for branding purposes, as well as to ensure that bookmarks or URLs passed from one user to another do the expected thing.
But I have a lot of problems getting this to work. I would prefer not to modify the children in the existing structure, so I tried to change the following options:
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 won't behave. I have used regular expressions many times, but putting one in the very first โbarrelโ of a URI seems unusually traumatic. Any suggestions gratefully received.
source share