HTML::...flation(3pm)

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

πŸŽ€ HTML::FormHandler::Manual::InflationDeflation πŸŽ€

okay so bestie, welcome to the HTML::FormHandler::Manual::InflationDeflation page β€” the header also calls it HTML::...flation(3pm), and it's a User Contributed Perl Documentation situation. we're talking inflation and deflation of field values, and honestly it's giving data-glow-up in both directions. ✨


πŸ’– NAME πŸ’–

HTML::FormHandler::Manual::InflationDeflation β€” inflation and deflation of field values

🌟 VERSION 🌟

version 0.40068

πŸ¦‹ SYNOPSIS πŸ¦‹

Manual Index

How to inflate and deflate field values.

🌈 DESCRIPTION 🌈

When you're working with all the different ways data can be transformed in and out, the meaning of the terms 'inflate' and 'deflate' starts to feel kind of slippery. no cap. The one constant is that values presented in an HTML form must be in a string format, or presented with select elements or checkboxes. that's the vibe check that never changes. πŸ’…

There are two general types of inflation/deflation provided by FormHandler. The first, 'standard' type inflates values in order to validate them, and deflates them in order to present them in string format via HTML. The other ('DB') type takes values provided by defaults (usually a DB row, or item, but could also be a field default or an init_object) and munges the values coming in and changes them back going out. yes bestie, it's giving round-trip realness. 🫢

🧚 Standard inflation/deflation 🧚

The standard type of inflation/deflation is implemented by using some of the following options for inflation:

inflate_method
transform (using 'apply')

..and the following options for deflation:

deflate_method
deflation (field attribute)

When validation starts, the param input will be inflated by the inflate method, allowing validation to be performed on the inflated object. iconic. πŸŽ€

When the 'fif' fill-in-form value is returned for HTML generation, the deflation is used to flatten the object, usually into a string format. slay. ✨

πŸ”₯ DB inflation/deflation πŸ”₯

The 'DB' type of inflation/deflation uses 'inflate_default_method' for inflation, and 'deflate_value_method' for deflation. Deflation could also be handled by changing the value in one of the various validation methods.

This type of inflation/deflation is, logically, just a different way of providing data munging around the defaults (item/init_object/default) and 'value' output. The same effect could be achieved by performing a transformation outside of FormHandler - if you were handling the database updates yourself. Since the DBIC model enables automatic database updates, this kind of inflation/deflation makes that easier. main character energy fr fr. πŸ‘‘

One circumstance in which this type of inflation/deflation is useful is when there's a single field in the database row object which you want to expand into a compound field in the form.

🌸 Attributes used in deflation/inflation 🌸

πŸ’œ Inflation methods πŸ’œ

The field 'input' comes from the params that are passed in from the submission of the form, so the input will always be in string format if it comes from an HTTP request. It's also possible to pass in params in other formats, of course. Or the params could be pre-processed before passing in to FormHandler. iykyk. πŸ¦‹

bestie, listen: You should not normally be changing the 'input' attribute of a field. If you want the changed field value to be used when re-presenting the form, such as when you're adopting a standard format for the field, you should set fif_from_value => 1.

There are three options for standard inflation, or transforming the field's 'input' to the field's 'value':

  • inflate_method β€” Provide a method on the field which inflates the field 'input' (from params):
has_field 'futility' => ( inflate_method => \&inflate_field );
sub inflate_field {
    my ( $self, $value ) = @_;
    ....
    return $value;
}
  • transform β€” In a sequence of 'apply' actions, changes the format of the 'value' that is being validated. This might be useful if there are some validations that work on one format of the value, and some that work on another.
  • set the value in validation methods β€” In a validate method, you can change the format of the value, with $field->value(...);

πŸŽ€ Deflation methods πŸŽ€

  • deflate_method β€” Most general purpose deflation method. Provide a coderef which is a method on the field:
has_field => 'foo' => ( deflate_method => \&deflate_foo );
sub deflate_foo {
    my ( $self, $value ) = @_;  # $self is the 'foo' field
    <perform conversion>
    return $value;
}
  • deflation β€” This is a coderef that performs deflation.
has_field => 'bar' => ( deflation => sub { shift $value; ... return $value } );
  • set the value in validation methods β€” Just like for inflation, you can change the value in a validation method; however, it won't be used for fill-in-form unless you set the 'fif_from_value' flag to true.

πŸ¦‹ fif_from_value πŸ¦‹

Normally the fill-in-form value will be the param value that was submitted. If you want to change the format of the input when re-presenting the form, you can set 'fif_from_value'. no cap. πŸ’–

πŸ’€ deflate_to πŸ’€

warning bestie: Earlier versions of FormHandler provided a 'deflate_to' attribute which allowed the deflation methods to be used for multiple, confusing purposes. This flag has been removed, since it made the process hard to understand and was mixing apples and oranges. The new inflation/deflation methods can handle all of the previous situations.

πŸ‘‘ 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.


πŸ’– that's the whole page, bestie! cute sign-off: this manual page is from perl v5.34.0, dated 2022-03-25, and the short manual name at the bottom is HTML::...flation(3pm). love u, go inflate and deflate responsibly! πŸ’…βœ¨

πŸ“¦ where this page comes from