.\" Automatically generated by Pod::Man 4.10 (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 .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" ======================================================================== .\" .IX Title "HTML::FormFu::Model::HashRef 3pm" .TH HTML::FormFu::Model::HashRef 3pm "2019-01-12" "perl v5.28.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::FormFu::Model::HashRef \- handle hashrefs .SH "VERSION" .IX Header "VERSION" version 2.07 .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 10 \& \-\-\- \& elements: \& \- user_id \& \- user_name \& \- type: Repeatable \& nested_name: addresses \& elements: \& \- type: Hidden \& name: id \& \- street \& \& \& $form\->model(\*(AqHashRef\*(Aq)\->default_values( { \& user_id => 123, \& user_name => \*(AqHans\*(Aq, \& addresses => [ \& { id => 2, \& street => \*(AqSomewhere\*(Aq }, \& { id => 3, \& street => \*(AqSomewhere Else\*(Aq } \& ] \& } ); \& \& $form\->default_model(\*(AqHashRef\*(Aq); \& my $hashref = $form\->model\->create(); \& \& # $hashref is very much the same as the hashref you passed to default_values() .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" If you need the content of a formular as hashref or for processing with other modules like \f(CW\*(C`JSON\*(C'\fR you can use this model. .SH "METHODS" .IX Header "METHODS" .SS "create" .IX Subsection "create" This method creates a hashref from a filled form. This form can be filled by calling \&\*(L"default_values\*(R" in HTML::FormFu, default_values of any other model class (e. g. HTML::FormFu::Model::DBIC) or by simply submitting the form. .PP If \*(L"deflators\*(R" is true all deflators are processed (defaults to \f(CW1\fR). .PP If \*(L"options\*(R" is true the value of all elements which have options like HTML::FormFu::Element::Select will be transformed. .PP .Vb 7 \& \-\-\- \& elements: \& \- type: Select \& name: select \& options: \& \- [1, "Foo"] \& \- [2, "Bar"] .Ve .PP If the value of \f(CW\*(C`select\*(C'\fR is \f(CW1\fR, create will create this hashref: .PP .Vb 1 \& { \*(Aqselect\*(Aq => { label => \*(AqFoo\*(Aq, value => 1 } } .Ve .PP If there is more than one value selected, an arrayref is created instead: .PP .Vb 2 \& { \*(Aqselect\*(Aq => [ { label => \*(AqFoo\*(Aq, value => 1 }, \& { label => \*(AqBar\*(Aq, value => 2 } ] } .Ve .PP If \*(L"options\*(R" is false, the output will look like this: .PP .Vb 1 \& { \*(Aqselect\*(Aq => 1 } .Ve .PP respectively .PP .Vb 1 \& { \*(Aqselect\*(Aq => [1, 2] } .Ve .PP \&\*(L"options\*(R" is false by default. .PP To get a flattened hash, you can set \f(CW\*(C`/flatten\*(C'\fR to a true value (defaults to \f(CW0\fR). This will generate a hash which uses the nested name of each field as key and the value of this field as hash value. If there is a field which has more than one value, a counter is added. The above example would result in a hash like this using \f(CW\*(C`/flatten\*(C'\fR: .PP .Vb 2 \& { \*(Aqselect_0\*(Aq => 1, \& \*(Aqselect_1\*(Aq => 2 } .Ve .SS "update" .IX Subsection "update" Alias for \*(L"create\*(R". .SS "default_values" .IX Subsection "default_values" Populate a form using a hashref. This hashref has the same format as the output of \*(L"create\*(R". If \*(L"inflators\*(R" is true, all inflators will be processed (defaults to \f(CW1\fR). .SH "CONFIGURATION" .IX Header "CONFIGURATION" These methods do not return the model object so chaining is not possible! .SS "options" .IX Subsection "options" Adds the label of a value to the hashref if the element has \*(L"options\*(R" in HTML::FormFu::Role::Element::Group. See \*(L"create\*(R" for an example. Defaults to \f(CW0\fR. .SS "flatten" .IX Subsection "flatten" Flattens the hash using Hash::Flatten. See \*(L"create\*(R" for an example. Defaults to \f(CW0\fR. .SS "deflators" .IX Subsection "deflators" If true, processes deflators in \f(CW\*(C`/create\*(C'\fR. Defaults to \f(CW1\fR. .SS "inflators" .IX Subsection "inflators" If true, processes inflators in \f(CW\*(C`/default_values\*(C'\fR. Defaults to \f(CW1\fR. .SH "SEE ALSO" .IX Header "SEE ALSO" HTML::FormFu, Hash::Flatten .SH "AUTHOR" .IX Header "AUTHOR" Moritz Onken, \f(CW\*(C`onken@houseofdesign.de\*(C'\fR .SH "AUTHOR" .IX Header "AUTHOR" Carl Franks .SH "COPYRIGHT AND LICENSE" .IX Header "COPYRIGHT AND LICENSE" This software is copyright (c) 2018 by Carl Franks. .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.