HTML-FormHandler
view release on metacpan or search on metacpan
lib/HTML/FormHandler/Model.pm view on Meta::CPAN
package HTML::FormHandler::Model;
# ABSTRACT: default model base class
$HTML::FormHandler::Model::VERSION = '0.40068';
use Moose::Role;
use Carp;
has 'item' => (
is => 'rw',
lazy => 1,
builder => 'build_item',
clearer => 'clear_item',
trigger => sub { shift->set_item(@_) }
);
sub build_item { return }
sub set_item {
my ( $self, $item ) = @_;
$self->item_class( ref $item );
}
has 'item_id' => (
is => 'rw',
clearer => 'clear_item_id',
trigger => sub { shift->set_item_id(@_) }
);
sub set_item_id { }
has 'item_class' => (
isa => 'Str',
is => 'rw',
);
sub guess_field_type {
Carp::confess "Don't know how to determine field type of [$_[1]]";
}
sub lookup_options { }
sub validate_model { }
sub clear_model { }
sub update_model { }
use namespace::autoclean;
1;
__END__
=pod
=encoding UTF-8
=head1 NAME
HTML::FormHandler::Model - default model base class
=head1 VERSION
version 0.40068
=head1 SYNOPSIS
This class defines the base attributes for FormHandler model
classes. It is not used directly.
=head1 DESCRIPTION
This is an empty base class that defines methods called by
HTML::FormHandler to support interfacing forms with a data store
such as a database.
This module provides instructions on methods to override to create
a HTML::FormHandler::Model class to work with a specific object relational
mapping (ORM) tool.
=head1 METHODS
=head2 item, build_item
The "item" is initialized with "build_item" the first time $form->item is called.
"item" must be defined in the model class to fetch the object based on the item id.
It should return the item's object. Column values are fetched and updated
by calling methods on the returned object.
For example, with Class::DBI you might return:
return $self->item_class->retrieve( $self->item_id );
=head2 item_id
The id (primary key) of the item (object) that the form is updating
or has just created. The model class should have a build_item method that can
fetch the object from the item_class for this id.
=head2 item_class
"item_class" sets and returns a value used by the model class to access
the ORM class related to a form.
For example:
has '+item_class' => ( default => 'User' );
( run in 0.432 second using v1.01-cache-2.11-cpan-e93a5daba3e )