NAME
Catalyst::Model::Enzyme::CRUD - CRUD Model Component
SYNOPSIS
DESCRIPTION
CRUD Model Component.
MODEL CONFIGURATION
This is how to configure your model classes' meta data.
__PACKAGE__->config( crud => {} )
Some things are configured
- moniker
-
Human readable name for this model.
E.g. "Shop Location".
Default: MyApp::Model::CDBI::ShopLocation becomes "Shop Location".
- column_monikers
-
Column monikers. Hash ref with (key: column name: value: moniker).
Default: based on the column name. Override specific column names like this:
column_monikers => { __PACKAGE__->default_column_monikers, url => "URL" },
- data_form_validator
-
Validation rules for the data fields.
Default: no validation
Note that you need to provide the entire config hashref for Data::FormValidator.
- rows_per_page
-
Number of rows per page when using a pager (which will happen unless paging is disabled by setting this value is 0).
Default: 20
Class::DBI configuration
- Stringified column
-
Let's say your Model class Book has a Foreign Key (FK) genre_id to the Genre Model class.
In the list of Books, the Genre will just be displayed with this identifier, whereas you really would like it to display the Genre name.
In the Genre model class, define the column group Stringify, like this:
__PACKAGE__->columns(Stringify => qw/ name /);
This magic is performed by Class::DBI and Class::DBI::AsForm's to_field method.
- Fields to display
-
__PACKAGE__->columns(crud_view_columns => qw/ COLUMNS /);
Default: all columns.
- Fields to display in lists
-
__PACKAGE__->columns(crud_list_columns => qw/ COLUMNS /);
Default: all columns.
Example
use Data::FormValidator::Constraints qw(:regexp_common);
__PACKAGE__->columns(Stringify => qw/ url /);
__PACKAGE__->config(
crud => {
moniker => "URL",
rows_per_page => 20,
data_form_validator => {
optional => [ __PACKAGE__->columns ],
required => [ "url" ],
constraint_methods => {
url => FV_URI(),
},
msgs => {
format => '%s',
constraints => {
FV_URI => "Not a URL",
},
},
},
},
);
CLASS METHODS
default_column_monikers()
Return hash ref with the default column monikers (display names) for all columns.
You can use this to setup a Model's crud config like this:
__PACKAGE__->config(
crud => {
column_monikers => { __PACKAGE__->default_column_monikers, url_id => "URL" };
},
);
default_column_moniker($column)
Return default name for $column.
Remove _id$ and ^id_.
Exemple: author_name_id --> Author Name
AUTHOR
Johan Lindstrom <johanl ÄT cpan.org>
LICENSE
This library is free software . You can redistribute it and/or modify it under the same terms as perl itself.
1 POD Error
The following errors were encountered while parsing the POD:
- Around line 200:
Non-ASCII character seen before =encoding in 'ÄT'. Assuming CP1252