HTML::...ashRef(3pm)

πŸ“¦
version 2.07000 Β· 5 versions
, in debian bookworm, ubuntu jammy, ubuntu noble

πŸ’– 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_values in HTML::FormFu
  • by calling default_values of 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 πŸ’…)


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