Christopher H. Laco > Handel-1.00014 > Handel::Components::DefaultValues

Download:
Handel-1.00014.tar.gz

Dependencies

Annotate this POD

CPAN RT

New  1
Open  0
View/Report Bugs
Source  

NAME ^

Handel::Components::DefaultValues - Set default values for undefined columns

SYNOPSIS ^

    package MySchema::Table;
    use strict;
    use warnings;
    use base qw/DBIx::Class/;
    
    __PACKAGE__->load_components('+Handel::Component::DefaultValues');
    __PACKAGE__->default_values({
        col1 => 0,
        col2 => 'My New Item',
        col3 => \&subref
    });
    
    1;

DESCRIPTION ^

Handel::Components::DefaultValues is a simple way to set default column values before inserts/updates.

There is no real reason to load this component into your schema table classes directly. If you add default values using Handel::Storage->default_values, this component will be loaded into the appropriate schema source class automatically.

METHODS ^

default_values

Arguments: \%values

Gets/sets the default values to be used for this result sources columns. Hash values can be either simple scalar values or code references that will be executed and their return values inserted into the columns.

Note: Always use the real column name in the database, not the accessor alias for the column.

insert

Calls set_default_values and then inserts the row. See "insert" in DBIx::Class::Row for more information about insert.

update

Calls set_default_values and then updates the row. See "update" in DBIx::Class::Row for more information about update.

set_default_values

This loops through all of the configured default values and sets the appropriate column to that value if the column is undefined.

AUTHOR ^

    Christopher H. Laco
    CPAN ID: CLACO
    claco@chrislaco.com
    http://today.icantfocus.com/blog/
syntax highlighting: