[Catalyst] Loading CRUD for all tables

Frank Wiegand frank.wiegand at gmail.com
Mon Apr 11 16:00:36 CEST 2005


Hi,

sometimes when developing a new app, using CatMCDBI::CRUD can be tedious.

Instead of writing 

    __PACKAGE__->action(
        $table => sub my ( $self, $c ) = @_;
        $c->form( optional => [ $class ] );
        $c->forward($class);
    );

for all of my tables, I just define these actions dynamically in my
app's '!default' action:

    __PACKAGE__->action(
        '!default' => sub {
            my ( $self, $c ) = @_;
            for my $class ( $c->comp("MyApp::Model::CDBI")->loader->classes ) {
                __PACKAGE__->action(
                    $class->table => sub {
                        my ( $self, $c ) = @_;
                        $c->form( optional => [ $class ] );
                        $c->forward($class);
                    }
                );
            }

            # ... more default stuff goes here
        }
    };

Maybe this is helpful for somebody ...


Thanks, Frank



More information about the Catalyst mailing list