.\" Automatically generated by Pod::Man 4.09 (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 .. .if !\nF .nr F 0 .if \nF>0 \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} .\} .\" ======================================================================== .\" .IX Title "HTML::FormHandler::Manual::InflationDeflation 3pm" .TH HTML::FormHandler::Manual::InflationDeflation 3pm "2017-11-11" "perl v5.26.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::FormHandler::Manual::InflationDeflation \- inflation and deflation of field values .SH "VERSION" .IX Header "VERSION" version 0.40068 .SH "SYNOPSIS" .IX Header "SYNOPSIS" Manual Index .PP How to inflate and deflate field values. .SS "\s-1DESCRIPTION\s0" .IX Subsection "DESCRIPTION" When working with the various ways that data can be transformed, in and out, the meaning of the terms 'inflate' and 'deflate' starts to feel kind of slippery. The one constant is that values presented in an \s-1HTML\s0 form must be in a string format, or presented with select elements or checkboxes. .PP 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 \s-1HTML.\s0 The other ('\s-1DB\s0') type takes values provided by defaults (usually a \s-1DB\s0 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. .SS "Standard inflation/deflation" .IX Subsection "Standard inflation/deflation" The standard type of inflation/deflation is implemented by using some of the following options for inflation: .PP .Vb 2 \& inflate_method \& transform (using \*(Aqapply\*(Aq) .Ve .PP \&..and the following options for deflation: .PP .Vb 2 \& deflate_method \& deflation (field attribute) .Ve .PP When validation starts, the param input will be inflated by the inflate method, allowing validation to be performed on the inflated object. .PP When the 'fif' fill-in-form value is returned for \s-1HTML\s0 generation, the deflation is used to flatten the object, usually into a string format. .SS "\s-1DB\s0 inflation/deflation" .IX Subsection "DB inflation/deflation" The '\s-1DB\s0' 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. .PP 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 \s-1DBIC\s0 model enables automatic database updates, this kind of inflation/deflation makes that easier. .PP 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. .SS "Attributes used in deflation/inflation" .IX Subsection "Attributes used in deflation/inflation" \fIInflation methods\fR .IX Subsection "Inflation methods" .PP 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 \&\s-1HTTP\s0 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. .PP 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 \&\f(CW\*(C`fif_from_value => 1\*(C'\fR. .PP There are three options for standard inflation, or transforming the field's \&'input' to the field's 'value': .IP "inflate_method" 4 .IX Item "inflate_method" Provide a method on the field which inflates the field 'input' (from params): .Sp .Vb 6 \& has_field \*(Aqfutility\*(Aq => ( inflate_method => \e&inflate_field ); \& sub inflate_field { \& my ( $self, $value ) = @_; \& .... \& return $value; \& } .Ve .IP "transform" 4 .IX Item "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. .IP "set the value in validation methods" 4 .IX Item "set the value in validation methods" In a validate method, you can change the format of the value, with \f(CW$field\fR\->value(...); .PP \fIDeflation methods\fR .IX Subsection "Deflation methods" .IP "deflate_method" 4 .IX Item "deflate_method" Most general purpose deflation method. Provide a coderef which is a method on the field: .Sp .Vb 6 \& has_field => \*(Aqfoo\*(Aq => ( deflate_method => \e&deflate_foo ); \& sub deflate_foo { \& my ( $self, $value ) = @_; # $self is the \*(Aqfoo\*(Aq field \& \& return $value; \& } .Ve .IP "deflation" 4 .IX Item "deflation" This is a coderef that performs deflation. .Sp .Vb 1 \& has_field => \*(Aqbar\*(Aq => ( deflation => sub { shift $value; ... return $value } ); .Ve .IP "set the value in validation methods" 4 .IX Item "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. .PP \fIfif_from_value\fR .IX Subsection "fif_from_value" .PP 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'. .PP \fIdeflate_to\fR .IX Subsection "deflate_to" .PP 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. .SH "AUTHOR" .IX Header "AUTHOR" FormHandler Contributors \- see HTML::FormHandler .SH "COPYRIGHT AND LICENSE" .IX Header "COPYRIGHT AND LICENSE" This software is copyright (c) 2017 by Gerda Shank. .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.