.\" Automatically generated by Pod::Man 2.28 (Pod::Simple 3.28) .\" .\" 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 turned on, 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 .\" .\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2). .\" Fear. Run. Save yourself. No user-serviceable parts. . \" fudge factors for nroff and troff .if n \{\ . ds #H 0 . ds #V .8m . ds #F .3m . ds #[ \f1 . ds #] \fP .\} .if t \{\ . ds #H ((1u-(\\\\n(.fu%2u))*.13m) . ds #V .6m . ds #F 0 . ds #[ \& . ds #] \& .\} . \" simple accents for nroff and troff .if n \{\ . ds ' \& . ds ` \& . ds ^ \& . ds , \& . ds ~ ~ . ds / .\} .if t \{\ . ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u" . ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u' . ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u' . ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u' . ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u' . ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u' .\} . \" troff and (daisy-wheel) nroff accents .ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V' .ds 8 \h'\*(#H'\(*b\h'-\*(#H' .ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#] .ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H' .ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u' .ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#] .ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#] .ds ae a\h'-(\w'a'u*4/10)'e .ds Ae A\h'-(\w'A'u*4/10)'E . \" corrections for vroff .if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u' .if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u' . \" for low resolution devices (crt and lpr) .if \n(.H>23 .if \n(.V>19 \ \{\ . ds : e . ds 8 ss . ds o a . ds d- d\h'-1'\(ga . ds D- D\h'-1'\(hy . ds th \o'bp' . ds Th \o'LP' . ds ae ae . ds Ae AE .\} .rm #[ #] #H #V #F C .\" ======================================================================== .\" .IX Title "MooseX::Params::Validate 3pm" .TH MooseX::Params::Validate 3pm "2015-02-08" "perl v5.20.2" "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" MooseX::Params::Validate \- an extension of Params::Validate using Moose's types .SH "VERSION" .IX Header "VERSION" version 0.21 .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 3 \& package Foo; \& use Moose; \& use MooseX::Params::Validate; \& \& sub foo { \& my ( $self, %params ) = validated_hash( \& \e@_, \& bar => { isa => \*(AqStr\*(Aq, default => \*(AqMoose\*(Aq }, \& ); \& return "Hooray for $params{bar}!"; \& } \& \& sub bar { \& my $self = shift; \& my ( $foo, $baz, $gorch ) = validated_list( \& \e@_, \& foo => { isa => \*(AqFoo\*(Aq }, \& baz => { isa => \*(AqArrayRef | HashRef\*(Aq, optional => 1 }, \& gorch => { isa => \*(AqArrayRef[Int]\*(Aq, optional => 1 } \& ); \& [ $foo, $baz, $gorch ]; \& } .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" This module fills a gap in Moose by adding method parameter validation to Moose. This is just one of many developing options, it should not be considered the \*(L"official\*(R" one by any means though. .PP You might also want to explore \f(CW\*(C`MooseX::Method::Signatures\*(C'\fR and \&\f(CW\*(C`MooseX::Declare\*(C'\fR. .SH "CAVEATS" .IX Header "CAVEATS" It is not possible to introspect the method parameter specs; they are created as needed when the method is called and cached for subsequent calls. .SH "EXPORTS" .IX Header "EXPORTS" .ie n .IP "\fBvalidated_hash( \e@_, \fB%parameter_spec\fB )\fR" 4 .el .IP "\fBvalidated_hash( \e@_, \f(CB%parameter_spec\fB )\fR" 4 .IX Item "validated_hash( @_, %parameter_spec )" This behaves similarly to the standard Params::Validate \f(CW\*(C`validate\*(C'\fR function and returns the captured values in a \s-1HASH.\s0 The one exception is where if it spots an instance in the \f(CW@_\fR, then it will handle it appropriately (unlike Params::Validate which forces you to shift you \f(CW$self\fR first). .Sp The values in \f(CW@_\fR can either be a set of name-value pairs or a single hash reference. .Sp The \f(CW%parameter_spec\fR accepts the following options: .RS 4 .IP "\fIisa\fR" 4 .IX Item "isa" The \f(CW\*(C`isa\*(C'\fR option can be either; class name, Moose type constraint name or an anon Moose type constraint. .IP "\fIdoes\fR" 4 .IX Item "does" The \f(CW\*(C`does\*(C'\fR option can be either; role name or an anon Moose type constraint. .IP "\fIdefault\fR" 4 .IX Item "default" This is the default value to be used if the value is not supplied. .IP "\fIoptional\fR" 4 .IX Item "optional" As with Params::Validate, all options are considered required unless otherwise specified. This option is passed directly to Params::Validate. .IP "\fIcoerce\fR" 4 .IX Item "coerce" If this is true and the parameter has a type constraint which has coercions, then the coercion will be called for this parameter. If the type does have coercions, then this parameter is ignored. .IP "\fIdepends\fR" 4 .IX Item "depends" Another parameter that this one depends on. See the Params::Validate documentation for more details. .RE .RS 4 .Sp This function is also available under its old name, \f(CW\*(C`validate\*(C'\fR. .RE .ie n .IP "\fBvalidated_list( \e@_, \fB%parameter_spec\fB )\fR" 4 .el .IP "\fBvalidated_list( \e@_, \f(CB%parameter_spec\fB )\fR" 4 .IX Item "validated_list( @_, %parameter_spec )" The \f(CW%parameter_spec\fR accepts the same options as above, but returns the parameters as positional values instead of a \s-1HASH.\s0 This is best explained by example: .Sp .Vb 8 \& sub foo { \& my ( $self, $foo, $bar ) = validated_list( \& \e@_, \& foo => { isa => \*(AqFoo\*(Aq }, \& bar => { isa => \*(AqBar\*(Aq }, \& ); \& $foo\->baz($bar); \& } .Ve .Sp We capture the order in which you defined the parameters and then return them as a list in the same order. If a param is marked optional and not included, then it will be set to \f(CW\*(C`undef\*(C'\fR. .Sp The values in \f(CW@_\fR can either be a set of name-value pairs or a single hash reference. .Sp Like \f(CW\*(C`validated_hash\*(C'\fR, if it spots an object instance as the first parameter of \f(CW@_\fR, it will handle it appropriately, returning it as the first argument. .Sp This function is also available under its old name, \f(CW\*(C`validatep\*(C'\fR. .ie n .IP "\fBpos_validated_list( \e@_, \fB$spec\fB, \f(BI$spec\fB, ... )\fR" 4 .el .IP "\fBpos_validated_list( \e@_, \f(CB$spec\fB, \f(CB$spec\fB, ... )\fR" 4 .IX Item "pos_validated_list( @_, $spec, $spec, ... )" This function validates a list of positional parameters. Each \f(CW$spec\fR should validate one of the parameters in the list: .Sp .Vb 7 \& sub foo { \& my $self = shift; \& my ( $foo, $bar ) = pos_validated_list( \& \e@_, \& { isa => \*(AqFoo\*(Aq }, \& { isa => \*(AqBar\*(Aq }, \& ); \& \& ... \& } .Ve .Sp Unlike the other functions, this function \fIcannot\fR find \f(CW$self\fR in the argument list. Make sure to shift it off yourself before doing validation. .Sp The values in \f(CW@_\fR must be a list of values. You cannot pass the values as an array reference, because this cannot be distinguished from passing one value which is itself an array reference. .Sp If a parameter is marked as optional and is not present, it will simply not be returned. .Sp If you want to pass in any of the cache control parameters described below, simply pass them after the list of parameter validation specs: .Sp .Vb 8 \& sub foo { \& my $self = shift; \& my ( $foo, $bar ) = pos_validated_list( \& \e@_, \& { isa => \*(AqFoo\*(Aq }, \& { isa => \*(AqBar\*(Aq }, \& MX_PARAMS_VALIDATE_NO_CACHE => 1, \& ); \& \& ... \& } .Ve .SH "EXCEPTION FOR FAILED VALIDATION" .IX Header "EXCEPTION FOR FAILED VALIDATION" If a type constraint check for a parameter fails, then the error is thrown as a MooseX::Params::Validate::Exception::ValidationFailedForTypeConstraint object. When stringified, this object will use the error message generated by the type constraint that failed. .PP Other errors are simply percolated up from Params::Validate as-is, and are not turned into exception objects. This may change in the future (or more likely, Params::Validate may start throwing objects of its own). .SH "ALLOWING EXTRA PARAMETERS" .IX Header "ALLOWING EXTRA PARAMETERS" By default, any parameters not mentioned in the parameter spec cause this module to throw an error. However, you can have this module simply ignore them by setting \f(CW\*(C`MX_PARAMS_VALIDATE_ALLOW_EXTRA\*(C'\fR to a true value when calling a validation subroutine. .PP When calling \f(CW\*(C`validated_hash\*(C'\fR or \f(CW\*(C`pos_validated_list\*(C'\fR the extra parameters are simply returned in the hash or list as appropriate. However, when you call \&\f(CW\*(C`validated_list\*(C'\fR the extra parameters will not be returned at all. You can get them by looking at the original value of \f(CW@_\fR. .SH "EXPORTS" .IX Header "EXPORTS" By default, this module exports the \f(CW\*(C`validated_hash\*(C'\fR, \&\f(CW\*(C`validated_list\*(C'\fR, and \f(CW\*(C`pos_validated_list\*(C'\fR. .PP If you would prefer to import the now deprecated functions \f(CW\*(C`validate\*(C'\fR and \f(CW\*(C`validatep\*(C'\fR instead, you can use the \f(CW\*(C`:deprecated\*(C'\fR tag to import them. .SH "IMPORTANT NOTE ON CACHING" .IX Header "IMPORTANT NOTE ON CACHING" When a validation subroutine is called the first time, the parameter spec is prepared and cached to avoid unnecessary regeneration. It uses the fully qualified name of the subroutine (package + subname) as the cache key. In 99.999% of the use cases for this module, that will be the right thing to do. .PP However, I have (ab)used this module occasionally to handle dynamic sets of parameters. In this special use case you can do a couple things to better control the caching behavior. .IP "\(bu" 4 Passing in the \f(CW\*(C`MX_PARAMS_VALIDATE_NO_CACHE\*(C'\fR flag in the parameter spec this will prevent the parameter spec from being cached. .Sp .Vb 6 \& sub foo { \& my ( $self, %params ) = validated_hash( \& \e@_, \& foo => { isa => \*(AqFoo\*(Aq }, \& MX_PARAMS_VALIDATE_NO_CACHE => 1, \& ); \& \& } .Ve .IP "\(bu" 4 Passing in \f(CW\*(C`MX_PARAMS_VALIDATE_CACHE_KEY\*(C'\fR with a value to be used as the cache key will bypass the normal cache key generation. .Sp .Vb 6 \& sub foo { \& my ( $self, %params ) = validated_hash( \& \e@_, \& foo => { isa => \*(AqFoo\*(Aq }, \& MX_PARAMS_VALIDATE_CACHE_KEY => \*(Aqfoo\-42\*(Aq, \& ); \& \& } .Ve .SH "MAINTAINER" .IX Header "MAINTAINER" Dave Rolsky .SH "BUGS" .IX Header "BUGS" Please submit bugs to the \s-1CPAN RT\s0 system at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=moosex\-params\-validate or via email at bug\-moosex\-params\-validate@rt.cpan.org. .SH "AUTHORS" .IX Header "AUTHORS" .IP "\(bu" 4 Stevan Little .IP "\(bu" 4 Dave Rolsky .SH "CONTRIBUTORS" .IX Header "CONTRIBUTORS" .IP "\(bu" 4 Dagfinn Ilmari Mannsa\*oker .IP "\(bu" 4 Hans Staugaard .IP "\(bu" 4 Karen Etheridge .SH "COPYRIGHT AND LICENSE" .IX Header "COPYRIGHT AND LICENSE" This software is copyright (c) 2013 \- 2015 by Stevan Little . .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.