NAME
Catalyst::Enzyme::CRUD::Model - CRUD Model Component
SYNOPSIS
DESCRIPTION
CRUD Model Component.
This is how to configure your model classes' meta data.
ENZYME MODEL CONFIGURATION:
Some things are Enzyme related configurations. These go in the:
__PACKAGE__->config( crud => {} )
hash ref.
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 (id_% and %id removed, the capitalized).
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, all columns are optional.
Note that you need to provide the entire config hashref that Data::FormValidator expects.
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
CDBI 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.
When objects are displayed in a list
, the text in the Stringify column will become a link to view
the object.
Fields to display
The following set of columns can be defined for various uses in the templates. The column names both define which columns to display, and in which order.
__PACKAGE__->columns(view_columns => qw/ COLUMNS /);
__PACKAGE__->columns(edit_columns => qw/ COLUMNS /);
__PACKAGE__->columns(list_columns => qw/ COLUMNS /);
The default is all columns except primary keys.
These are pre-entered by the Model helper so it's easy for you to remove or change the order. If you like it the way it is, just delete the lines altogether.
EXAMPLE
use Data::FormValidator::Constraints qw(:regexp_common);
__PACKAGE__->columns(Stringify => qw/ url /);
__PACKAGE__->columns(list_columns=> qw/ name email url /);
__PACKAGE__->columns(view_columns=> qw/ name email url phone /);
__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
list_columns()
Return array with the column names suitable for a list of the objects in this Model.
Configure this with:
__PACKAGE__->columns(list_columns => qw/ column names /);
Default: the default_columns.
view_columns()
Return array with the column names suitable for viewing an object in this Model.
Configure this with:
__PACKAGE__->columns(view_columns => qw/ column names /);
Default: the default_columns.
edit_columns()
Return array with the column names suitable for editing an object in this Model.
Configure this with:
__PACKAGE__->columns(edit_columns => qw/ column names /);
Default: edit_columns (if specified), otherwise the default_columns.
named_columns($group_name)
Return array with the column names identified by __PACKAGE__->columns($group_name).
Configure this with:
__PACKAGE__->columns($group_name => qw/ column names /);
default_columns()
Return array with the default column names suitable for an object in this Model.
This is all column names, except PK columns.
namespace_of_column_has_a($c, $column)
If $column has a has_a relationship to another table, return the Model's Controller's namespace (or the first if there are many).
Return "" if there are no related tables.
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 348:
Non-ASCII character seen before =encoding in 'ÄT'. Assuming CP1252