.\" 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 "Mojolicious::Validator 3pm" .TH Mojolicious::Validator 3pm "2019-02-05" "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" Mojolicious::Validator \- Validate values .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 1 \& use Mojolicious::Validator; \& \& my $validator = Mojolicious::Validator\->new; \& my $v = $validator\->validation; \& $v\->input({foo => \*(Aqbar\*(Aq}); \& $v\->required(\*(Aqfoo\*(Aq)\->like(qr/ar$/); \& say $v\->param(\*(Aqfoo\*(Aq); .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" Mojolicious::Validator validates values for Mojolicious. .SH "CHECKS" .IX Header "CHECKS" These validation checks are available by default. .SS "equal_to" .IX Subsection "equal_to" .Vb 1 \& $v = $v\->equal_to(\*(Aqfoo\*(Aq); .Ve .PP String value needs to be equal to the value of another field. .SS "in" .IX Subsection "in" .Vb 1 \& $v = $v\->in(\*(Aqfoo\*(Aq, \*(Aqbar\*(Aq, \*(Aqbaz\*(Aq); .Ve .PP String value needs to match one of the values in the list. .SS "like" .IX Subsection "like" .Vb 1 \& $v = $v\->like(qr/^[A\-Z]/); .Ve .PP String value needs to match the regular expression. .SS "num" .IX Subsection "num" .Vb 4 \& $v = $v\->num; \& $v = $v\->num(2, 5); \& $v = $v\->num(2, undef); \& $v = $v\->num(undef, 5); .Ve .PP String value needs to be a non-fractional number and if provided in the given range. .SS "size" .IX Subsection "size" .Vb 1 \& $v = $v\->size(2, 5); .Ve .PP String value length or size of Mojo::Upload object in bytes needs to be between these two values. .SS "upload" .IX Subsection "upload" .Vb 1 \& $v = $v\->upload; .Ve .PP Value needs to be a Mojo::Upload object, representing a file upload. .SH "FILTERS" .IX Header "FILTERS" These filters are available by default. .SS "trim" .IX Subsection "trim" .Vb 1 \& $v = $v\->optional(\*(Aqfoo\*(Aq, \*(Aqtrim\*(Aq); .Ve .PP Trim whitespace characters from both ends of string value with \&\*(L"trim\*(R" in Mojo::Util. .SH "ATTRIBUTES" .IX Header "ATTRIBUTES" Mojolicious::Validator implements the following attributes. .SS "checks" .IX Subsection "checks" .Vb 2 \& my $checks = $validator\->checks; \& $validator = $validator\->checks({size => sub {...}}); .Ve .PP Registered validation checks, by default only \*(L"equal_to\*(R", \*(L"in\*(R", \&\*(L"like\*(R", \*(L"num\*(R", \*(L"size\*(R" and \*(L"upload\*(R" are already defined. .SH "METHODS" .IX Header "METHODS" Mojolicious::Validator inherits all methods from Mojo::Base and implements the following new ones. .SS "add_check" .IX Subsection "add_check" .Vb 1 \& $validator = $validator\->add_check(size => sub {...}); .Ve .PP Register a validation check. .PP .Vb 5 \& $validator\->add_check(foo => sub { \& my ($v, $name, $value, @args) = @_; \& ... \& return undef; \& }); .Ve .SS "add_filter" .IX Subsection "add_filter" .Vb 1 \& $validator = $validator\->add_filter(trim => sub {...}); .Ve .PP Register a new filter. .PP .Vb 5 \& $validator\->add_filter(foo => sub { \& my ($v, $name, $value) = @_; \& ... \& return $value; \& }); .Ve .SS "new" .IX Subsection "new" .Vb 1 \& my $validator = Mojolicious::Validator\->new; .Ve .PP Construct a new Mojolicious::Validator object. .SS "validation" .IX Subsection "validation" .Vb 1 \& my $v = $validator\->validation; .Ve .PP Build Mojolicious::Validator::Validation object to perform validations. .PP .Vb 4 \& my $v = $validator\->validation; \& $v\->input({foo => \*(Aqbar\*(Aq}); \& $v\->required(\*(Aqfoo\*(Aq)\->size(1, 5); \& say $v\->param(\*(Aqfoo\*(Aq); .Ve .SH "SEE ALSO" .IX Header "SEE ALSO" Mojolicious, Mojolicious::Guides, .