[Catalyst] Loading CRUD for all tables
Michael Reece
mreece at sacbee.com
Fri Apr 15 19:07:32 CEST 2005
> I tried "shift @$c->req->args" but that doesn't work as args() is
> a rvalue-only accessor (?).
$c->req->args should return an array-ref.
shift @{ $c->req->args };
worked for me, when I was taking that approach.
(I have since shifted to having the CRUD controller -- MyApp::C::CRUD --
separate from the model classes, which also looks for
MyApp::C::CRUD::MyTable and uses that if present. The CRUD controllers have
methods like _action_list, _action_view, etc, which are dispatched via 'sub
process'. It's working out pretty well, and removed a lot of concerns I had
with the provided C::M::CRUD's willingness to call any method it can().
Though it is Cat4 code, I would be willing to share it though it is not
really 'release-ready' (no POD, few comments). I think it will translate
pretty well to Cat5, too, when that is stable enough for me to upgrade to.)
On 4/14/05 9:24 PM, "Torsten Seemann"
<torsten.seemann at infotech.monash.edu.au> wrote:
> Marcus,
>
>> my %db_class;
>> sub default : Private {
>> my ($self,$c,$table) = @_;
>> %db_class=map {$_->table,$_ }
>> $c->comp("MyApp::Model::CDBI")->loader->classes
>> unless scalar keys %db_class;
>> if ($db_class{$table}) {
>> $c->form( optional => [ $class ] );
>
> # minor fix:
> $c->form( optional => [ $db_class{$table}->columns ] );
>
>> $c->forward($db_class{$table});
>> } else {
>> $c->res->output ($table. ' not found');
>> }
>> }
>
> Ignoring the simple bug fix above, this snippet you produced *almost*
> works. Under your scheme the request arguments look like:
>
> $c->req->args = [ 'TABLE_NAME', 'TABLE_ACTION', 'ROW_ID?', ... ]
>
> wherease CDBI.pm & CRUD.pm expect it to look like:
>
> $c->req->args = [ 'TABLE_ACTION', 'ROW_ID?', ... ]
>
> I tried "shift @$c->req->args" but that doesn't work as args() is
> a rvalue-only accessor (?).
>
> Any ideas?
More information about the Catalyst
mailing list