1HTML::FormHandler::ModeUls:e:rCDCBoIn(t3r)ibuted Perl DoHcTuMmLe:n:tFaotrimoHnandler::Model::CDBI(3)
2
3
4
6 HTML::FormHandler::Model::CDBI - Class::DBI model class
7 (non-functioning)
8
10 version 0.40068
11
13 package MyApplication::Form::User;
14 use strict;
15 use base 'HTML::FormHandler::Model::CDBI';
16
17
18 # Associate this form with a CDBI class
19 has '+item_class' => ( default => 'MyDB::User' );
20
21 # Define the fields that this form will operate on
22 sub field_list {
23 return {
24 [
25 name => 'Text',
26 age => 'PosInteger',
27 sex => 'Select',
28 birthdate => 'DateTimeDMYHM',
29 ]
30 };
31 }
32
34 A Class::DBI database model for HTML::FormHandler
35
36 I don't use CDBI, so this module almost certainly doesn't work. It is
37 only being left here as a starting point in case somebody is interested
38 in getting it to work.
39
40 Patches and tests gratefully accepted.
41
43 item_class
44 The name of your database class.
45
46 init_item
47 This is called first time $form->item is called. It does the
48 equivalent of:
49
50 return $self->item_class->retrieve( $self->item_id );
51
52 guess_field_type
53 Pass in a column and assigns field types. Must set $self->item_class
54 to return the related item class. Returns the type in scalar context,
55 returns the type and maybe the related table in list context.
56
57 Currently returns:
58
59 DateTime - for a has_a relationship that isa DateTime
60 Select - for a has_a relationship
61 Multiple - for a has_many
62 DateTime - if the field ends in _time
63 Text - otherwise
64
65 lookup_options
66 Returns a array reference of key/value pairs for the column passed in.
67 Calls $field->label_column to get the column name to use as the label.
68 The default is "name". The labels are sorted by Perl's cmp sort.
69
70 If there is an "active" column then only active are included, with the
71 exception being if the form (item) has currently selected the inactive
72 item. This allows existing records that reference inactive items to
73 still have those as valid select options. The inactive labels are
74 formatted with brackets to indicate in the select list that they are
75 inactive.
76
77 The active column name is determined by calling:
78
79 $active_col = $form->can( 'active_column' )
80 ? $form->active_column
81 : $field->active_column;
82
83 Which allows setting the name of the active column globally if your
84 tables are consistently named (all lookup tables have the same column
85 name to indicate they are active), or on a per-field basis.
86
87 In addition, if the foreign class is the same as the item's class (or
88 the class returned by item_class) then options pointing to item are
89 excluded. The reason for this is for a table column that points to the
90 same table (self referenced), such as a "parent" column. The
91 assumption is that a record cannot be its own parent.
92
93 init_value
94 Populate $field->value with object ids from the CDBI object. If the
95 column expands to more than one object then an array ref is set.
96
97 validate_model
98 Validates fields that are dependent on the model. Currently, "unique"
99 fields are checked to make sure they are unique.
100
101 This validation happens after other form validation. The form already
102 has any field values entered in $field->value at this point.
103
104 validate_unique
105 Checks that the value for the field is not currently in the database.
106
107 items_same
108 Returns true if the two passed in cdbi objects are the same object. If
109 both are undefined returns true.
110
111 obj_key
112 returns a key for a given object, or undef if the object is undefined.
113
115 FormHandler Contributors - see HTML::FormHandler
116
118 This software is copyright (c) 2017 by Gerda Shank.
119
120 This is free software; you can redistribute it and/or modify it under
121 the same terms as the Perl 5 programming language system itself.
122
123
124
125perl v5.36.0 2022-07-22 HTML::FormHandler::Model::CDBI(3)