.\" Automatically generated by Pod::Man 4.09 (Pod::Simple 3.35) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .if !\nF .nr F 0 .if \nF>0 \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} .\} .\" ======================================================================== .\" .IX Title "HTML::FormHandler::Model 3pm" .TH HTML::FormHandler::Model 3pm "2017-11-11" "perl v5.26.1" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" HTML::FormHandler::Model \- default model base class .SH "VERSION" .IX Header "VERSION" version 0.40068 .SH "SYNOPSIS" .IX Header "SYNOPSIS" This class defines the base attributes for FormHandler model classes. It is not used directly. .SH "DESCRIPTION" .IX Header "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. .PP This module provides instructions on methods to override to create a HTML::FormHandler::Model class to work with a specific object relational mapping (\s-1ORM\s0) tool. .SH "METHODS" .IX Header "METHODS" .SS "item, build_item" .IX Subsection "item, build_item" The \*(L"item\*(R" is initialized with \*(L"build_item\*(R" the first time \f(CW$form\fR\->item is called. \&\*(L"item\*(R" 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. .PP For example, with Class::DBI you might return: .PP .Vb 1 \& return $self\->item_class\->retrieve( $self\->item_id ); .Ve .SS "item_id" .IX Subsection "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. .SS "item_class" .IX Subsection "item_class" \&\*(L"item_class\*(R" sets and returns a value used by the model class to access the \s-1ORM\s0 class related to a form. .PP For example: .PP .Vb 1 \& has \*(Aq+item_class\*(Aq => ( default => \*(AqUser\*(Aq ); .Ve .PP This gives the model class a way to access the data store. If this is not a fixed value (as above) then do not define the method in your subclass and instead set the value when the form is created: .PP .Vb 1 \& my $form = MyApp::Form::Users\->new( item_class => $class ); .Ve .PP The value can be any scalar (or object) needed by the specific \s-1ORM\s0 to access the data related to the form. .PP A builder for 'item_class' might be to return the class of the 'item'. .SS "guess_field_type" .IX Subsection "guess_field_type" Returns the guessed field type. The field name is passed as the first argument. This is only required if using \*(L"Auto\*(R" type of fields in your form classes. You could override this in your form class, for example, if you use a field naming convention that indicates the field type. .PP The metadata info about the columns can be used to assign types. .SS "lookup_options" .IX Subsection "lookup_options" Retrieve possible options for a given select field from the database. The default method returns undef. .PP Returns an array reference of key/value pairs for the column passed in. These values are used for the values and labels for field types that provide a list of options to select from (e.g. Select, Multiple). .PP A 'Select' type field (or a field that inherits from HTML::FormHandler::Field::Select) can set a number of scalars that control how options are looked up: .PP .Vb 3 \& label_column() \- column that holds the label \& active_column() \- column that indicates if a row is acitve \& sort_column() \- column used for sorting the options .Ve .PP The default for label_column is \*(L"name\*(R". .SS "validate_model" .IX Subsection "validate_model" Validates fields that are dependent on the model. This is called via the validation process and the model class must at least validate \*(L"unique\*(R" constraints defined in the form class. .PP Any errors on a field found should be set by calling the field's add_error method: .PP .Vb 1 \& $field\->add_error(\*(AqValue must be unique in the database\*(Aq); .Ve .PP The default method does nothing. .SS "clear_model" .IX Subsection "clear_model" Clear out any dynamic data for persistent object .SS "update_model" .IX Subsection "update_model" Update the model with validated fields .SH "AUTHOR" .IX Header "AUTHOR" FormHandler Contributors \- see HTML::FormHandler .SH "COPYRIGHT AND LICENSE" .IX Header "COPYRIGHT AND LICENSE" This software is copyright (c) 2017 by Gerda Shank. .PP This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.