GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages
Catalyst::Enzyme::CRUD::Model(3) User Contributed Perl Documentation Catalyst::Enzyme::CRUD::Model(3)

Catalyst::Enzyme::CRUD::Model - CRUD Model Component

CRUD Model Component.

This is how to configure your model classes' meta data.

Some things are Enzyme related configurations. These go in the:

    __PACKAGE__->config( crud => {} )

hash ref.

Human readable name for this model.

E.g. "Shop Location".

Default: MyApp::Model::CDBI::ShopLocation becomes "Shop Location".

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" },

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.

Number of rows per page when using a pager (which will happen unless paging is disabled by setting this value is 0).

Default: 20

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.

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.

    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",
                    },
                },
            },
        },
    );

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" };
        },
    );

Return default name for $column.

Remove _id$ and ^id_.

Exemple: author_name_id --> Author Name

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.

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.

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.

Return array with the column names identified by __PACKAGE__->columns($group_name).

Configure this with:

    __PACKAGE__->columns($group_name => qw/ column names /);

Return array with the default column names suitable for an object in this Model.

This is all column names, except PK columns.

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.

Johan Lindstrom <johanl ÄT cpan.org>

This library is free software . You can redistribute it and/or modify it under the same terms as perl itself.

Hey! The above document had some coding errors, which are explained below:
Around line 348:
Non-ASCII character seen before =encoding in 'ÄT'. Assuming CP1252
2006-01-14 perl v5.32.1

Search for    or go to Top of page |  Section 3 |  Main Index

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with ManDoc.