Combine with configuration
package MyApp::BaseController::CRUD;
use base 'Catalyst::Controller';
sub show_all :Local {
my ($self, $c) = @_;
my $model_name = $self->{model_name} || die 'Need model name';
$c->stash->{records} = [ $c->model("DBIC::$model_name")->all ];
}
package MyApp::Controller::Users;
use base 'MyApp::BaseController::CRUD';
__PACKAGE__->config( model_name => 'User' );
- then you have /users/show_all
- add another table + controller, and it just works
- i rarely write an application that doesn't do this