HTML::...ashRef(3pm)
π HTML::FormFu::Model::HashRef π
okay bestie, so this is a page from the User Contributed Perl Documentation section of the manual β HTML::FormFu::Model::HashRef(3pm), to be exact. And it's literally the model that handles hashrefs. That's the whole vibe. π
β¨ VERSION β¨
version 2.07 β she's grown, she's thriving π
πΈ SYNOPSIS πΈ
here's the whole setup, bestie, look:
---
elements:
- user_id
- user_name
- type: Repeatable
nested_name: addresses
elements:
- type: Hidden
name: id
- street
$form->model('HashRef')->default_values( {
user_id => 123,
user_name => 'Hans',
addresses => [
{ id => 2,
street => 'Somewhere' },
{ id => 3,
street => 'Somewhere Else' }
]
} );
$form->default_model('HashRef');
my $hashref = $form->model->create();
# $hashref is very much the same as the hashref you passed to default_values()
and yes the comment is real and yes it's iconic β the hashref you get back is very much the same as the one you passed in π«Ά
π¦ DESCRIPTION π¦
so if you need the content of a formular as a hashref, OR you wanna feed it to other modules like JSON, this model is the one. periodt. β¨
π METHODS π
π create
this method creates a hashref from a filled form. and how does the form get filled, you ask? three ways, bestie:
- by calling
default_valuesin HTML::FormFu - by calling
default_valuesof any other model class (e. g. HTML::FormFu::Model::DBIC) - or by simply submitting the form π
if deflators is true, all deflators are processed β and that defaults to 1.
if options is true, the value of all elements which have options β like HTML::FormFu::Element::Select β will be transformed. watch:
---
elements:
- type: Select
name: select
options:
- [1, "Foo"]
- [2, "Bar"]
if the value of select is 1, create will create this hashref:
{ 'select' => { label => 'Foo', value => 1 } }
and if there's more than one value selected, an arrayref is created instead:
{ 'select' => [ { label => 'Foo', value => 1 },
{ label => 'Bar', value => 2 } ] }
but if options is false, the output will look like this:
{ 'select' => 1 }
respectively:
{ 'select' => [1, 2] }
and listen β options is false by default. lowkey important, don't forget it π
okay so now, to get a flattened hash, you can set /flatten to a true value (defaults to 0). this will generate a hash which uses the nested name of each field as key and the value of this field as hash value. and if there's a field which has more than one value, a counter is added. the above example would result in a hash like this using /flatten:
{ 'select_0' => 1,
'select_1' => 2 }
ate. π₯
π update
alias for create. that's it. that's the section. π
π§ default_values
populate a form using a hashref. this hashref has the same format as the output of create. and if inflators is true, all inflators will be processed β defaults to 1. π«Ά
π CONFIGURATION π
β οΈ heads up bestie β these methods do not return the model object, so chaining is not possible! no cute little method chains here, sorry π
π options
adds the label of a value to the hashref if the element has options in HTML::FormFu::Role::Element::Group. see create for an example. defaults to 0.
π flatten
flattens the hash using Hash::Flatten. see create for an example. defaults to 0.
π deflators
if true, processes deflators in /create. defaults to 1.
π inflators
if true, processes inflators in /default_values. defaults to 1.
π SEE ALSO π
- HTML::FormFu
- Hash::Flatten
β AUTHOR β
Moritz Onken, onken@houseofdesign.de
β AUTHOR β
Carl Franks <cpan@fireartist.com>
(yeah there's two AUTHOR sections, she's got two icons and both of them ate π )
π COPYRIGHT AND LICENSE π
this software is copyright (c) 2018 by Carl Franks.
this is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. π«Ά
and that's the whole page, bestie β no cap, every single detail preserved, main character energy only π
signing off with the deets: this was perl v5.28.1, dated 2019-01-12, and the page is HTML::...ashRef(3pm) πβ¨ bye bestie, go make some hashrefs π
π¦ where this page comes from
- debian bookworm: libhtml-formfu-perl 2.07000-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu jammy: libhtml-formfu-perl 2.07000-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu noble: libhtml-formfu-perl 2.07000-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms