HTML::...:Model(3pm)

πŸ“¦
version 0.40068 Β· 6 versions
, in debian bookworm, debian trixie, ubuntu noble, ubuntu resolute

πŸ’– HTML::...:Model(3pm) πŸ’–

okay bestie, welcome to the manual page for HTML::...:Model(3pm) β€” aka HTML::FormHandler::Model, the default model base class, chilling at version 0.40068. This is a User Contributed Perl Documentation moment, and she's here to explain how FormHandler models are supposed to work. ✨


🌸 NAME 🌸

HTML::FormHandler::Model β€” default model base class. That's the whole name, no cap. πŸ’…


πŸŽ€ VERSION πŸŽ€

version 0.40068


πŸ¦‹ SYNOPSIS πŸ¦‹

This class defines the base attributes for FormHandler model classes. It is not used directly. Like, it's the blueprint bestie, not the final fit. 🫢


🌈 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. Basically: here's the lore, now go customize it for your ORM. 🧚


πŸ‘‘ METHODS πŸ‘‘

πŸ“ 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 );

πŸ’œ 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.

🌸 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' );

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:

my $form = MyApp::Form::Users->new( item_class => $class );

The value can be any scalar (or object) needed by the specific ORM to access the data related to the form.

A builder for 'item_class' might be to return the class of the 'item'.

✨ guess_field_type

Returns the guessed field type. The field name is passed as the first argument. This is only required if using "Auto" 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.

The metadata info about the columns can be used to assign types.

πŸ¦‹ lookup_options

Retrieve possible options for a given select field from the database. The default method returns undef.

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).

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:

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

The default for label_column is "name".

yes bestie, acitve is right there in the original β€” typo and all, we keep the lore intact 😭

πŸ’– 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 "unique" constraints defined in the form class.

Any errors on a field found should be set by calling the field's add_error method:

$field->add_error('Value must be unique in the database');

The default method does nothing.

πŸŽ€ clear_model

Clear out any dynamic data for persistent object

πŸ”₯ update_model

Update the model with validated fields


πŸ’« AUTHOR πŸ’«

FormHandler Contributors - see HTML::FormHandler


This software is copyright (c) 2017 by Gerda Shank.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.


mwah πŸ’‹ β€” this page came from perl v5.34.0, dated 2022-03-25, and it's the HTML::...:Model(3pm) manual, signed off with all the sparkle it deserves. 🌟

πŸ“¦ where this page comes from