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.

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/