{
    "mode": "perldoc",
    "parameter": "Type::Params",
    "section": "",
    "url": "https://www.chedong.com/phpMan.php/perldoc/Type%3A%3AParams/json",
    "generated": "2026-09-25T10:06:10Z",
    "synopsis": "use v5.20;\nuse strict;\nuse warnings;\nuse experimental 'signatures';\npackage Horse {\nuse Moo;\nuse Types::Standard qw( Object );\nuse Type::Params -sigs;\nuse namespace::autoclean;\n...;   # define attributes, etc\nsignaturefor addchild => (\nmethod     => 1,\npositional => [ Object ],\n);\nsub addchild ( $self, $child ) {\npush @{ $self->children }, $child;\nreturn $self;\n}\n}\npackage main;\nmy $boldruler = Horse->new;\n$boldruler->addchild( Horse->new );\n$boldruler->addchild( 123 );   # dies (123 is not an Object!)",
    "sections": {
        "NAME": {
            "content": "Type::Params - sub signature validation using Type::Tiny type constraints and coercions\n",
            "subsections": []
        },
        "SYNOPSIS": {
            "content": "use v5.20;\nuse strict;\nuse warnings;\nuse experimental 'signatures';\n\npackage Horse {\nuse Moo;\nuse Types::Standard qw( Object );\nuse Type::Params -sigs;\nuse namespace::autoclean;\n\n...;   # define attributes, etc\n\nsignaturefor addchild => (\nmethod     => 1,\npositional => [ Object ],\n);\n\nsub addchild ( $self, $child ) {\n\npush @{ $self->children }, $child;\n\nreturn $self;\n}\n}\n\npackage main;\n\nmy $boldruler = Horse->new;\n\n$boldruler->addchild( Horse->new );\n\n$boldruler->addchild( 123 );   # dies (123 is not an Object!)\n",
            "subsections": []
        },
        "STATUS": {
            "content": "This module is covered by the Type-Tiny stability policy.\n",
            "subsections": []
        },
        "DESCRIPTION": {
            "content": "This documents the details of the Type::Params package. Type::Tiny::Manual is a better starting\nplace if you're new.\n\nType::Params uses Type::Tiny constraints to validate the parameters to a sub. It takes the\nslightly unorthodox approach of separating validation into two stages:\n\n1.  Compiling the parameter specification into a coderef; then\n\n2.  Using the coderef to validate parameters.\n\nThe first stage is slow (it might take a couple of milliseconds), but you only need to do it the\nfirst time the sub is called. The second stage is fast; according to my benchmarks faster even\nthan the XS version of Params::Validate.\n",
            "subsections": []
        },
        "MODERN API": {
            "content": "The modern API can be exported using:\n\nuse Type::Params -sigs;\n\nOr:\n\nuse Type::Params -v2;\n\nOr by requesting functions by name:\n\nuse Type::Params qw( signature signaturefor );\n\nsignature( %spec )\nThe \"signature\" function takes a specification for your function's signature and returns a\ncoderef. You then call the coderef in list context, passing @ to it. The coderef will check,\ncoerce, and apply other procedures to the values, and return the tidied values, or die with an\nerror.\n\nThe usual way of using it is:\n\nsub yourfunction {\nstate $signature = signature( ... );\nmy ( $arg1, $arg2, $arg3 ) = $signature->( @ );\n\n...;\n}\n\nPerl allows a slightly archaic way of calling coderefs without using parentheses, which may be\nslightly faster at the cost of being more obscure:\n\nsub yourfunction {\nstate $signature = signature( ... );\nmy ( $arg1, $arg2, $arg3 ) = &$signature;\n\n...;\n}\n\nIf you need to support Perl 5.8, which didn't have the \"state\" keyword:\n\nmy $yourfunctionsig;\nsub yourfunction {\n$yourfunctionsig ||= signature( ... );\nmy ( $arg1, $arg2, $arg3 ) = $yourfunctionsig->( @ );\n\n...;\n}\n\nOne important thing to note is how the signature is only compiled into a coderef the first time\nyour function gets called, and thereafter will be reused.\n\nSignature Specification Options\nThe signature specification is a hash which must contain either a \"positional\", \"named\", or\n\"multiple\" key indicating whether your function takes positional parameters, named parameters,\nor supports multiple calling conventions, but may also include other options.\n\n\"positional\" ArrayRef\nThis is conceptually a list of type constraints, one for each positional parameter. For example,\na signature for a function which accepts two integers:\n\nsignature( positional => [ Int, Int ] )\n\nHowever, each type constraint is optionally followed by a hashref of options which affect that\nparameter. For example:\n\nsignature( positional => [\nInt, { default => 40 },\nInt, { default =>  2 },\n] )\n\nType constraints can instead be given as strings, which will be looked up using \"dwimtype\" from\nType::Utils.\n\nsignature( positional => [\n'Int', { default => 40 },\n'Int', { default =>  2 },\n] )\n\nSee the section below for more information on parameter options.\n\nOptional parameters must follow required parameters, and can be specified using either the\nOptional parameterizable type constraint, the \"optional\" parameter option, or by providing a\ndefault.\n\nsignature( positional => [\nOptional[Int],\nInt, { optional => !!1 },\nInt, { default  => 42 },\n] )\n\nA single slurpy parameter may be provided at the end, using the Slurpy parameterizable type\nconstraint, or the \"slurpy\" parameter option:\n\nsignature( positional => [\nInt,\nSlurpy[ ArrayRef[Int] ],\n] )\n\nsignature( positional => [\nInt,\nArrayRef[Int], { slurpy => !!1 },\n] )\n\nThe \"positional\" option can also be abbreviated to \"pos\".\n\nSo \"signature( pos => [...] )\" can be used instead of the longer \"signature( positional => [...]\n)\".\n\nIf a signature uses positional parameters, the values are returned by the coderef as a list:\n\nsub addnumbers {\nstate $sig = signature( positional => [ Num, Num ] );\nmy ( $num1, $num2 ) = $sig->( @ );\n\nreturn $num1 + $num2;\n}\n\nsay addnumbers( 2, 3 );   # says 5\n\n\"named\" ArrayRef\nThis is conceptually a list of pairs of names and type constraints, one name+type pair for each\npositional parameter. For example, a signature for a function which accepts two integers:\n\nsignature( named => [ foo => Int, bar => Int ] )\n\nHowever, each type constraint is optionally followed by a hashref of options which affect that\nparameter. For example:\n\nsignature( named => [\nfoo => Int, { default => 40 },\nbar => Int, { default =>  2 },\n] )\n\nType constraints can instead be given as strings, which will be looked up using \"dwimtype\" from\nType::Utils.\n\nsignature( named => [\nfoo => 'Int', { default => 40 },\nbar => 'Int', { default =>  2 },\n] )\n\nOptional and slurpy parameters are allowed, but unlike positional parameters, they do not need\nto be at the end.\n\nSee the section below for more information on parameter options.\n\nIf a signature uses named parameters, the values are returned by the coderef as an object:\n\nsub addnumbers {\nstate $sig = signature( named => [ num1 => Num, num2 => Num ] );\nmy ( $arg ) = $sig->( @ );\n\nreturn $arg->num1 + $arg->num2;\n}\n\nsay addnumbers(   num1 => 2, num2 => 3   );   # says 5\nsay addnumbers( { num1 => 2, num2 => 3 } );   # also says 5\n\n\"namedtolist\" ArrayRef|Bool\nThe \"namedtolist\" option is ignored for signatures using positional parameters, but for\nsignatures using named parameters, allows them to be returned in a list instead of as an object:\n\nsub addnumbers {\nstate $sig = signature(\nnamed         => [ num1 => Num, num2 => Num ],\nnamedtolist => !!1,\n);\nmy ( $num1, $num2 ) = $sig->( @ );\n\nreturn $num1 + $num2;\n}\n\nsay addnumbers(   num1 => 2, num2 => 3   );   # says 5\nsay addnumbers( { num1 => 2, num2 => 3 } );   # also says 5\n\nYou can think of \"addnumbers\" above as a function which takes named parameters from the\noutside, but receives positional parameters on the inside.\n\nYou can use an arrayref to specify the order the paramaters will be returned in. (By default\nthey are returned in the order they were defined in.)\n\nsub addnumbers {\nstate $sig = signature(\nnamed         => [ num1 => Num, num2 => Num ],\nnamedtolist => [ qw( num2 num1 ) ],\n);\nmy ( $num2, $num1 ) = $sig->( @ );\n\nreturn $num1 + $num2;\n}\n\n\"head\" Int|ArrayRef\n\"head\" provides an additional list of non-optional, positional parameters at the start of @.\nThis is often used for method calls. For example, if you wish to define a signature for:\n\n$object->mymethod( foo => 123, bar => 456 );\n\nYou could write it as this:\n\nsub mymethod {\nstate $signature = signature(\nhead    => [ Object ],\nnamed   => [ foo => Optional[Int], bar => Optional[Int] ],\n);\nmy ( $self, $arg ) = $signature->( @ );\n\n...;\n}\n\nIf \"head\" is set as a number instead of an arrayref, it is the number of additional arguments at\nthe start:\n\nsub mymethod {\nstate $signature = signature(\nhead    => 1,\nnamed   => [ foo => Optional[Int], bar => Optional[Int] ],\n);\nmy ( $self, $arg ) = $signature->( @ );\n\n...;\n}\n\nIn this case, no type checking is performed on those additional arguments; it is just checked\nthat they exist.\n\n\"tail\" Int|ArrayRef\nA \"tail\" is like a \"head\" except that it is for arguments at the *end* of @.\n\nsub mymethod {\nstate $signature = signature(\nhead    => [ Object ],\nnamed   => [ foo => Optional[Int], bar => Optional[Int] ],\ntail    => [ CodeRef ],\n);\nmy ( $self, $arg, $callback ) = $signature->( @ );\n\n...;\n}\n\n$object->mymethod( foo => 123, bar => 456, sub { ... } );\n\n\"method\" Bool|TypeTiny\nWhile \"head\" can be used for method signatures, a more declarative way is to set \"method => 1\".\n\nIf you wish to be specific that this is an object method, intended to be called on blessed\nobjects only, then you may use \"method => Object\", using the Object type from Types::Standard.\nIf you wish to specify that it's a class method, then use \"method => Str\", using the Str type\nfrom Types::Standard. (\"method => ClassName\" is perhaps clearer, but it's a slower check.)\n\nsub mymethod {\nstate $signature = signature(\nmethod  => 1,\nnamed   => [ foo => Optional[Int], bar => Optional[Int] ],\n);\nmy ( $self, $arg ) = $signature->( @ );\n\n...;\n}\n\nIf \"method\" is true (or a type constraint) then any parameter defaults which are coderefs will\nbe called as methods.\n\n\"description\" Str\nThis is the description of the coderef that will show up in stack traces. It defaults to\n\"parameter validation for X\" where X is the caller sub name. Usually the default will be fine.\n\n\"package\" Str\nThe package of the sub whose paramaters we're supposed to be checking. As well as showing up in\nstack traces, it's used by \"dwimtype\" if you provide any type constraints as strings.\n\nThe default is probably fine, but if you're wrapping \"signature\" so that you can check\nsignatures on behalf of another package, you may need to provide it.\n\n\"subname\" Str\nThe name of the sub whose paramaters we're supposed to be checking.\n\nThe default is probably fine, but if you're wrapping \"signature\" so that you can check\nsignatures on behalf of another package, you may need to provide it.\n\n\"callerlevel\" Int\nIf you're wrapping \"signature\" so that you can check signatures on behalf of another package,\nthen setting \"callerlevel\" to 1 (or more, depending on the level of wrapping!) may be an\nalternative to manually setting the \"package\" and \"subname\".\n\n\"ondie\" Maybe[CodeRef]\nUsually when your coderef hits an error, it will throw an exception, which is a blessed\nError::TypeTiny object.\n\nIf you provide an \"ondie\" coderef, then instead the Error::TypeTiny object will be passed to\nit. If the \"ondie\" coderef returns something, then whatever it returns will be returned as your\nsignature's parameters.\n\nsub addnumbers {\nstate $sig = signature(\npositional => [ Num, Num ],\nondie     => sub {\nmy $error = shift;\nprint \"Existential crisis: $error\\n\";\nexit( 1 );\n},\n);\nmy ( $num1, $num2 ) = $sig->( @ );\n\nreturn $num1 + $num2;\n}\n\nsay addnumbers();   # has an existential crisis\n\nThis is probably not very useful.\n\n\"gotonext\" Bool|CodeLike\nThis can be used for chaining coderefs. If you understand \"ondie\", it's more like an \"onlive\".\n\nsub addnumbers {\nstate $sig = signature(\npositional => [ Num, Num ],\ngotonext  => sub {\nmy ( $num1, $num2 ) = @;\n\nreturn $num1 + $num2;\n},\n);\n\nmy $sum = $sig->( @ );\nreturn $sum;\n}\n\nsay addnumbers( 2, 3 );   # says 5\n\nIf set to a true boolean instead of a coderef, has a slightly different behaviour:\n\nsub addnumbers {\nstate $sig = signature(\npositional => [ Num, Num ],\ngotonext  => !!1,\n);\n\nmy $sum = $sig->(\nsub { return $[0] + $[1] },\n@,\n);\nreturn $sum;\n}\n\nsay addnumbers( 2, 3 );   # says 5\n\nThis looks strange. Why would this be useful? Well, it works nicely with Moose's \"around\"\nkeyword.\n\nsub addnumbers {\nreturn $[1] + $[2];\n}\n\naround addnumbers => signature(\nmethod     => !!1,\npositional => [ Num, Num ],\ngotonext  => !!1,\npackage    => PACKAGE,\nsubname    => 'addnumbers',\n);\n\nsay PACKAGE->addnumbers( 2, 3 );   # says 5\n\nNote the way \"around\" works in Moose is that it expects a wrapper coderef as its final argument.\nThat wrapper coderef then expects to be given a reference to the original function as its first\nparameter.\n\nThis can allow, for example, a role to provide a signature wrapping a method defined in a class.\n\nThis is kind of complex, and you're unlikely to use it, but it's been proven useful for tools\nthat integrate Type::Params with Moose-like method modifiers.\n\n\"strictness\" Bool|Str\nIf you set \"strictness\" to a false value (0, undef, or the empty string), then certain signature\nchecks will simply never be done. The initial check that there's the correct number of\nparameters, plus type checks on parameters which don't coerce can be skipped.\n\nIf you set it to a true boolean (i.e. 1) or do not set it at all, then these checks will always\nbe done.\n\nAlternatively, it may be set to the quoted fully-qualified name of a Perl global variable or a\nconstant, and that will be compiled into the coderef as a condition to enable strict checks.\n\nstate $signature = signature(\nstrictness => '$::CHECKTYPES',\npositional => [ Int, ArrayRef ],\n);\n\n# Type checks are skipped\n{\nlocal $::CHECKTYPES = 0;\nmy ( $number, $list ) = $signature->( {}, {} );\n}\n\n# Type checks are performed\n{\nlocal $::CHECKTYPES = 1;\nmy ( $number, $list ) = $signature->( {}, {} );\n}\n\nA recommended use of this is with Devel::StrictMode.\n\nuse Devel::StrictMode qw( STRICT );\n\nstate $signature = signature(\nstrictness => STRICT,\npositional => [ Int, ArrayRef ],\n);\n\n\"multiple\" ArrayRef\nThis option allows your signature to support multiple calling conventions. Each entry in the\narray is an alternative signature, as a hashref:\n\nstate $signature = signature(\nmultiple => [\n{\npositional => [ ArrayRef, Int ],\n},\n{\nnamed      => [ array => ArrayRef, index => Int ],\nnamedtolist => 1,\n},\n],\n);\n\nThat signature will allow your function to be called as:\n\nyourfunction( $arr, $ix )\nyourfunction( array => $arr, index => $ix )\nyourfunction( { array => $arr, index => $ix } )\n\nSometimes the alternatives will return the parameters in a different order:\n\nstate $signature = signature(\nmultiple => [\n{ positional => [ ArrayRef, Int ] },\n{ positional => [ Int, ArrayRef ] },\n],\n);\nmy ( $xxx, $yyy ) = $signature->( @ );\n\nSo how does your sub know whether $xxx or $yyy is the arrayref? One option is to use the\n\"${^TYPEPARAMSMULTISIG}\" global variable which will be set to the index of the signature\nwhich was used:\n\nmy @results = $signature->( @ );\nmy ( $arr, $ix ) = ${^TYPEPARAMSMULTISIG} == 1\n? reverse( @results )\n: @results;\n\nA neater solution is to use a \"gotonext\" coderef to re-order alternative signature results into\nyour preferred order:\n\nstate $signature = signature(\nmultiple => [\n{ positional => [ ArrayRef, Int ] },\n{ positional => [ Int, ArrayRef ], gotonext => sub { reverse @ } },\n],\n);\nmy ( $arr, $ix ) = $signature->( @ );\n\nWhile conceptally \"multiple\" is an arrayref of hashrefs, it is also possible to use arrayrefs in\nthe arrayref.\n\nmultiple => [\n[ ArrayRef, Int ],\n[ Int, ArrayRef ],\n]\n\nWhen an arrayref is used like that, it is a shortcut for a positional signature.\n\nCoderefs may additionally be used:\n\nstate $signature = signature(\nmultiple => [\n[ ArrayRef, Int ],\n{ positional => [ Int, ArrayRef ], gotonext => sub { reverse @ } },\nsub { ... },\nsub { ... },\n],\n);\n\nThe coderefs should be subs which return a list of parameters if they succeed and throw an\nexception if they fail.\n\nThe following signatures are equivalent:\n\nstate $sig1 = signature(\nmultiple => [\n{ method => 1, positional => [ ArrayRef, Int ] },\n{ method => 1, positional => [ Int, ArrayRef ] },\n],\n);\n\nstate $sig2 = signature(\nmethod   => 1,\nmultiple => [\n{ positional => [ ArrayRef, Int ] },\n{ positional => [ Int, ArrayRef ] },\n],\n);\n\nThe \"multiple\" option can also be abbreviated to \"multi\".\n\nSo \"signature( multi => [...] )\" can be used instead of the longer \"signature( multiple => [...]\n)\". Three whole keystrokes saved!\n\n(Note: in older releases of Type::Params, \"${^TYPEPARAMSMULTISIG}\" was called\n\"${^TYPEPARAMSMULTISIG}\". The latter name is deprecated, and support for it will be removed in\na future release of Type::Params.)\n\n\"message\" Str\nOnly used by \"multiple\" signatures. The error message to throw when no signatures match.\n\n\"wantsource\" Bool\nInstead of returning a coderef, return Perl source code string. Handy for debugging.\n\n\"wantdetails\" Bool\nInstead of returning a coderef, return a hashref of stuff including the coderef. This is mostly\nfor people extending Type::Params and I won't go into too many details about what else this\nhashref contains.\n\n\"bless\" Bool|ClassName, \"class\" ClassName|ArrayRef, and \"constructor\" Str\nNamed parameters are usually returned as a blessed object:\n\nsub addnumbers {\nstate $sig = signature( named => [ num1 => Num, num2 => Num ] );\nmy ( $arg ) = $sig->( @ );\n\nreturn $arg->num1 + $arg->num2;\n}\n\nThe class they are blessed into is one built on-the-fly by Type::Params. However, these three\nsignature options allow you more control over that process.\n\nFirstly, if you set \"bless => false\" and do not set \"class\" or \"constructor\", then $arg will\njust be an unblessed hashref.\n\nsub addnumbers {\nstate $sig = signature(\nnamed        => [ num1 => Num, num2 => Num ],\nbless        => !!0,\n);\nmy ( $arg ) = $sig->( @ );\n\nreturn $arg->{num1} + $arg->{num2};\n}\n\nThis is a good speed boost, but having proper methods for each named parameter is a helpful way\nto catch misspelled names.\n\nIf you wish to manually create a class instead of relying on Type::Params generating one\non-the-fly, you can do this:\n\npackage Params::For::AddNumbers {\nsub num1 { return $[0]{num1} }\nsub num2 { return $[0]{num2} }\nsub sum {\nmy $self = shift;\nreturn $self->num1 + $self->num2;\n}\n}\n\nsub addnumbers {\nstate $sig = signature(\nnamed        => [ num1 => Num, num2 => Num ],\nbless        => 'Params::For::AddNumbers',\n);\nmy ( $arg ) = $sig->( @ );\n\nreturn $arg->sum;\n}\n\nNote that \"Params::For::AddNumbers\" here doesn't include a \"new\" method because Type::Params\nwill directly do \"bless( $arg, $opts{bless} )\".\n\nIf you want Type::Params to use a proper constructor, you should use the \"class\" option instead:\n\npackage Params::For::AddNumbers {\nuse Moo;\nhas [ 'num1', 'num2' ] => ( is => 'ro' );\nsub sum {\nmy $self = shift;\nreturn $self->num1 + $self->num2;\n}\n}\n\nsub addnumbers {\nstate $sig = signature(\nnamed        => [ num1 => Num, num2 => Num ],\nclass        => 'Params::For::AddNumbers',\n);\nmy ( $arg ) = $sig->( @ );\n\nreturn $arg->sum;\n}\n\nIf you wish to use a constructor named something other than \"new\", then use:\n\nstate $sig = signature(\nnamed        => [ num1 => Num, num2 => Num ],\nclass        => 'Params::For::AddNumbers',\nconstructor  => 'newfromhashref',\n);\n\nOr as a shortcut:\n\nstate $sig = signature(\nnamed        => [ num1 => Num, num2 => Num ],\nclass        => [ 'Params::For::AddNumbers', 'newfromhashref' ],\n);\n\nIt is doubtful you want to use any of these options, except \"bless => false\".\n\nParameter Options\nIn the parameter lists for the \"positional\" and \"named\" signature options, each parameter may be\nfollowed by a hashref of options specific to that parameter:\n\nsignature(\npositional => [\nInt, \\%optionsforfirstparameter,\nInt, \\%optionsforotherparameter,\n],\n%moreoptionsforsignature,\n);\n\nsignature(\nnamed => [\nfoo => Int, \\%optionsforfoo,\nbar => Int, \\%optionsforbar,\n],\n%moreoptionsforsignature,\n);\n\nThe following options are supported for parameters.\n\n\"optional\" Bool\nAn option *called* optional!\n\nThis makes a parameter optional:\n\nsub addnums {\nstate $sig = signature(\npositional => [\nInt,\nInt,\nBool, { optional => !!1 },\n],\n);\n\nmy ( $num1, $num2, $debug ) = $sig->( @ );\n\nmy $sum = $num1 + $num2;\nwarn \"$sum = $num1 + $num2\" if $debug;\n\nreturn $sum;\n}\n\naddnums( 2, 3, 1 );   # prints warning\naddnums( 2, 3, 0 );   # no warning\naddnums( 2, 3    );   # no warning\n\nTypes::Standard also provides a Optional parameterizable type which may be a neater way to do\nthis:\n\nstate $sig = signature(\npositional => [ Int, Int, Optional[Bool] ],\n);\n\nIn signatures with positional parameters, any optional parameters must be defined *after*\nnon-optional parameters. The \"tail\" option provides a workaround for required parameters at the\nend of @.\n\nIn signatures with named parameters, the order of optional and non-optional parameters is\nunimportant.\n\n\"slurpy\" Bool\nA signature may contain a single slurpy parameter, which mops up any other arguments the caller\nprovides your function.\n\nIn signatures with positional parameters, slurpy params must always have some kind of ArrayRef\nor HashRef type constraint, must always appear at the *end* of the list of positional\nparameters, and they work like this:\n\nsub addnums {\nstate $sig = signature(\npositional => [\nNum,\nArrayRef[Num], { slurpy => !!1 },\n],\n);\nmy ( $firstnum, $othernums ) = $sig->( @ );\n\nmy $sum = $firstnum;\n$sum += $ for @$othernums;\n\nreturn $sum;\n}\n\nsay addnums( 1 );            # says 1\nsay addnums( 1, 2 );         # says 3\nsay addnums( 1, 2, 3 );      # says 6\nsay addnums( 1, 2, 3, 4 );   # says 10\n\nIn signatures with named parameters, slurpy params must always have some kind of HashRef type\nconstraint, and they work like this:\n\nuse builtin qw( true false );\n\nsub processdata {\nstate $sig = signature(\nmethod => true,\nnamed  => [\ninput   => FileHandle,\noutput  => FileHandle,\nflags   => HashRef[Bool], { slurpy => true },\n],\n);\nmy ( $self, $arg ) = @;\nwarn \"Beginning data processing\" if $arg->flags->{debug};\n\n...;\n}\n\n$widget->processdata(\ninput  => \\*STDIN,\noutput => \\*STDOUT,\ndebug  => true,\n);\n\nThe Slurpy type constraint from Types::Standard may be used as a shortcut to specify slurpy\nparameters:\n\nsignature(\npositional => [ Num, Slurpy[ ArrayRef[Num] ] ],\n)\n\nThe type Slurpy[Any] is handled specially and treated as a slurpy ArrayRef in signatures with\npositional parameters, and a slurpy HashRef in signatures with named parameters, but has some\nadditional optimizations for speed.\n\n\"default\" CodeRef|ScalarRef|Ref|Str|Undef\nA default may be provided for a parameter.\n\nstate $check = signature(\npositional => [\nInt,\nInt, { default => \"666\" },\nInt, { default => \"999\" },\n],\n);\n\nSupported defaults are any strings (including numerical ones), \"undef\", and empty hashrefs and\narrayrefs. Non-empty hashrefs and arrayrefs are *not allowed as defaults*.\n\nAlternatively, you may provide a coderef to generate a default value:\n\nstate $check = signature(\npositional => [\nInt,\nInt, { default => sub { 6 * 111 } },\nInt, { default => sub { 9 * 111 } },\n]\n);\n\nThat coderef may generate any value, including non-empty arrayrefs and non-empty hashrefs. For\nundef, simple strings, numbers, and empty structures, avoiding using a coderef will make your\nparameter processing faster.\n\nInstead of a coderef, you can use a reference to a string of Perl source code:\n\nstate $check = signature(\npositional => [\nInt,\nInt, { default => \\ '6 * 111' },\nInt, { default => \\ '9 * 111' },\n],\n);\n\nDefaults *will* be validated against the type constraint, and potentially coerced.\n\nAny parameter with a default will automatically be optional.\n\nNote that having *any* defaults in a signature (even if they never end up getting used) can slow\nit down, as Type::Params will need to build a new array instead of just returning @.\n\n\"coerce\" Bool\nSpeaking of which, the \"coerce\" option allows you to indicate that a value should be coerced\ninto the correct type:\n\nstate $sig = signature(\npositional => [\nInt,\nInt,\nBool, { coerce => true },\n],\n);\n\nSetting \"coerce\" to false will disable coercion.\n\nIf \"coerce\" is not specified, so is neither true nor false, then coercion will be enabled if the\ntype constraint has a coercion, and disabled otherwise.\n\nNote that having *any* coercions in a signature (even if they never end up getting used) can\nslow it down, as Type::Params will need to build a new array instead of just returning @.\n\n\"clone\" Bool\nIf this is set to true, it will deep clone incoming values via \"dclone\" from Storable (a core\nmodule since Perl 5.7.3).\n\nIn the below example, $arr is a reference to a *clone of* @numbers, so pushing additional\nnumbers to it leaves @numbers unaffected.\n\nsub foo {\nstate $check = signature(\npositional => [\nArrayRef, { clone => 1 }\n],\n);\nmy ( $arr ) = &$check;\n\npush @$arr, 4, 5, 6;\n}\n\nmy @numbers = ( 1, 2, 3 );\nfoo( \\@numbers );\n\nprint \"@numbers\\n\";  ## 1 2 3\n\nNote that cloning will significantly slow down your signature.\n\n\"name\" Str\nThis overrides the name of a named parameter. I don't know why you would want to do that.\n\nThe following signature has two parameters: \"foo\" and \"bar\". The name \"fool\" is completely\nignored.\n\nsignature(\nnamed => [\nfool   => Int, { name => 'foo' },\nbar    => Int,\n],\n)\n\nYou can, however, also name positional parameters, which don't usually have names.\n\nsignature(\npositional => [\nInt, { name => 'foo' },\nInt, { name => 'bar' },\n],\n)\n\nThe names of positional parameters are not really *used* for anything at the moment, but may be\nincorporated into error messages or similar in the future.\n\n\"getter\" Str\nFor signatures with named parameters, specifies the method name used to retrieve this\nparameter's value from the $arg object.\n\nsub processdata {\nstate $sig = signature(\nmethod => true,\nnamed  => [\ninput   => FileHandle,    { getter => 'in' },\noutput  => FileHandle,    { getter => 'out' },\nflags   => HashRef[Bool], { slurpy => true },\n],\n);\nmy ( $self, $arg ) = @;\nwarn \"Beginning data processing\" if $arg->flags->{debug};\n\nmy ( $in, $out ) = ( $arg->in, $arg->out );\n...;\n}\n\n$widget->processdata(\ninput  => \\*STDIN,\noutput => \\*STDOUT,\ndebug  => true,\n);\n\nIgnored by signatures with positional parameters.\n\n\"predicate\" Str\nThe $arg object provided by signatures with named parameters will also include \"has\" methods for\nany optional arguments. For example:\n\nstate $sig = signature(\nmethod => true,\nnamed  => [\ninput   => Optional[ FileHandle ],\noutput  => Optional[ FileHandle ],\nflags   => Slurpy[ HashRef[Bool] ],\n],\n);\nmy ( $self, $arg ) = $sig->( @ );\n\nif ( $self->hasinput and $self->hasoutput ) {\n...;\n}\n\nSetting a \"predicate\" option allows you to choose a different name for this method.\n\nIt is also possible to set a \"predicate\" for non-optional parameters, which don't normally get a\n\"has\" method.\n\nIgnored by signatures with positional parameters.\n\n\"alias\" Str|ArrayRef[Str]\nA list of alternative names for the parameter, or a single alternative name.\n\nsub addnumbers {\nstate $sig = signature(\nnamed => [\nfirstnumber   => Int, { alias => [ 'x' ] },\nsecondnumber  => Int, { alias =>   'y'   },\n],\n);\nmy ( $arg ) = $sig->( @ );\n\nreturn $arg->firstnumber + $arg->secondnumber;\n}\n\nsay addnumbers( firstnumber => 40, secondnumber => 2 );  # 42\nsay addnumbers( x            => 40, y             => 2 );  # 42\nsay addnumbers( firstnumber => 40, y             => 2 );  # 42\nsay addnumbers( firstnumber => 40, x => 1, y => 2 );      # dies!\n\nIgnored by signatures with positional parameters.\n\n\"strictness\" Bool|Str\nOverrides the signature option \"strictness\" on a per-parameter basis.\n\n\"signaturefor $functionname => ( %spec )\"\nLike \"signature\", but instead of returning a coderef, wraps an existing function, so you don't\nneed to deal with the mechanics of generating the signature at run-time, calling it, and\nextracting the returned values.\n\nThe following three examples are roughly equivalent:\n\nsub addnums {\nstate $signature = signature(\npositional => [ Num, Num ],\n);\nmy ( $x, $y ) = $signature->( @ );\n\nreturn $x + $y;\n}\n\nOr:\n\nsignaturefor addnums => (\npositional => [ Num, Num ],\n);\n\nsub addnums {\nmy ( $x, $y ) = @;\n\nreturn $x + $y;\n}\n\nOr since Perl 5.20:\n\nsignaturefor addnums => (\npositional => [ Num, Num ],\n);\n\nsub addnums ( $x, $y ) {\nreturn $x + $y;\n}\n\nThe \"signaturefor\" keyword turns \"signature\" inside-out.\n\nThe same signature specification options are supported, with the exception of \"wantsource\",\n\"wantdetails\", and \"gotonext\" which will not work. (If using the \"multiple\" option, then\n\"gotonext\" is still supported in the *nested* signatures.)\n\nIf you are providing a signature for a sub in another package, then \"signaturefor\n\"Some::Package::somesub\" => ( ... )\" will work, as will \"signaturefor somesub => ( package =>\n\"Some::Package\", ... )\". If \"method\" is true, then \"signaturefor\" will respect inheritance when\ndetermining which sub to wrap. \"signaturefor\" will not be able to find lexical subs, so use\n\"signature\" within the sub instead.\n\nThe \"gotonext\" option is what \"signaturefor\" uses to \"connect\" the signature to the body of\nthe sub, so do not use it unless you understand the consequences and want to override the normal\nbehaviour.\n\nIf the sub being wrapped cannot be found, then \"signaturefor\" will usually throw an error. If\nyou want it to \"work\" in this situation, use the \"fallback\" option. \"fallback =>\n\\&alternativecodereftowrap\" will instead wrap a different coderef if the original cannot be\nfound. \"fallback => 1\" is a shortcut for \"fallback => sub {}\". An example where this might be\nuseful is if you're adding signatures to methods which are inherited from a parent class, but\nyou are not 100% confident will exist (perhaps dependent on the version of the parent class).\n\nsignaturefor addnums => (\npositional => [ Num, Num ],\nfallback   => sub { $[0] + $[1] },\n);\n\n\"signaturefor( \\@functions, %opts )\" is a useful shortcut if you have multiple functions with\nthe same signature.\n\nsignaturefor [ 'addnums', 'subtractnums' ] => (\npositional => [ Num, Num ],\n);\n",
            "subsections": []
        },
        "LEGACY API": {
            "content": "The following functions were the API prior to Type::Params v2. They are still supported, but\ntheir use is now discouraged.\n\nIf you don't provide an import list at all, you will import \"compile\" and \"compilenamed\":\n\nuse Type::Params;\n\nThis does the same:\n\nuse Type::Params -v1;\n\nThe following exports \"compile\", \"compilenamed\", and \"compilenamedoo\":\n\nuse Type::Params -compile;\n\nThe following exports \"wrapsubs\" and \"wrapmethods\":\n\nuse Type::Params -wrap;\n\ncompile( @posparams )\nEquivalent to \"signature( positional => \\@posparams )\".\n\n\"compile( \\%spec, @posparams )\" is equivalent to \"signature( %spec, positional => \\@posparams\n)\".\n\ncompilenamed( @namedparams )\nEquivalent to \"signature( bless => 0, named => \\@namedparams )\".\n\n\"compilenamed( \\%spec, @namedparams )\" is equivalent to \"signature( bless => 0, %spec, named\n=> \\@namedparams )\".\n\ncompilenamedoo( @namedparams )\nEquivalent to \"signature( bless => 1, named => \\@namedparams )\".\n\n\"compilenamedoo( \\%spec, @namedparams )\" is equivalent to \"signature( bless => 1, %spec,\nnamed => \\@namedparams )\".\n\n\"validate( \\@args, @posparams )\"\nEquivalent to \"signature( positional => \\@posparams )->( @args )\".\n\nThe \"validate\" function has *never* been recommended, and is not exported unless requested by\nname.\n\n\"validatenamed( \\@args, @namedparams )\"\nEquivalent to \"signature( bless => 0, named => \\@namedparams )->( @args )\".\n\nThe \"validatenamed\" function has *never* been recommended, and is not exported unless requested\nby name.\n\n\"wrapsubs( func1 => \\@params1, func2 => \\@params2, ... )\"\nEquivalent to:\n\nsignaturefor func1 => ( positional => \\@params1 );\nsignaturefor func2 => ( positional => \\@params2 );\n\nOne slight difference is that instead of arrayrefs, you can provide the output of one of the\n\"compile\" functions:\n\nwrapsubs( func1 => compilenamed( @params1 ) );\n\n\"wrapsubs\" is not exported unless requested by name.\n\n\"wrapmethods( func1 => \\@params1, func2 => \\@params2, ... )\"\nEquivalent to:\n\nsignaturefor func1 => ( method => 1, positional => \\@params1 );\nsignaturefor func2 => ( method => 1, positional => \\@params2 );\n\nOne slight difference is that instead of arrayrefs, you can provide the output of one of the\n\"compile\" functions:\n\nwrapmethods( func1 => compilenamed( @params1 ) );\n\n\"wrapmethods\" is not exported unless requested by name.\n\nmultisig( @alternatives )\nEquivalent to:\n\nsignature( multiple => \\@alternatives )\n\n\"multisig( \\%spec, @alternatives )\" is equivalent to \"signature( %spec, multiple =>\n\\@alternatives )\".\n",
            "subsections": []
        },
        "TYPE CONSTRAINTS": {
            "content": "Although Type::Params is not a real type library, it exports two type constraints. Their use is\nno longer recommended.\n",
            "subsections": [
                {
                    "name": "Invocant",
                    "content": "Type::Params exports a type Invocant on request. This gives you a type constraint which accepts\nclassnames *and* blessed objects.\n\nuse Type::Params qw( compile Invocant );\n\nsub mymethod {\nstate $check = signature(\nmethod     => Invocant,\npositional => [ ArrayRef, Int ],\n);\nmy ($selforclass, $arr, $ix) = $check->(@);\n\nreturn $arr->[ $ix ];\n}\n\n\"Invocant\" is not exported unless requested by name.\n\nRecommendation: use Defined from Types::Standard instead.\n"
                },
                {
                    "name": "ArgsObject",
                    "content": "Type::Params exports a parameterizable type constraint ArgsObject. It accepts the kinds of\nobjects returned by signature checks for named parameters.\n\npackage Foo {\nuse Moo;\nuse Type::Params 'ArgsObject';\n\nhas args => (\nis  => 'ro',\nisa => ArgsObject['Bar::bar'],\n);\n}\n\npackage Bar {\nuse Types::Standard -types;\nuse Type::Params 'signature';\n\nsub bar {\nstate $check = signature(\nnamed => [\nxxx => Int,\nyyy => ArrayRef,\n],\n);\nmy ( $got ) = $check->( @ );\n\nreturn 'Foo'->new( args => $got );\n}\n}\n\nBar::bar( xxx => 42, yyy => [] );\n\nThe parameter \"Bar::bar\" refers to the caller when the check is compiled, rather than when the\nparameters are checked.\n\n\"ArgsObject\" is not exported unless requested by name.\n\nRecommendation: use Object from Types::Standard instead.\n"
                }
            ]
        },
        "ENVIRONMENT": {
            "content": "\"PERLTYPEPARAMSXS\"\nAffects the building of accessors for $arg objects. If set to true, will use\nClass::XSAccessor. If set to false, will use pure Perl. If this environment variable does\nnot exist, will use Class::XSAccessor.\n\nIf Class::XSAccessor is not installed or is too old, pure Perl will always be used as a\nfallback.\n",
            "subsections": []
        },
        "BUGS": {
            "content": "Please report any bugs to <https://github.com/tobyink/p5-type-tiny/issues>.\n",
            "subsections": []
        },
        "SEE ALSO": {
            "content": "The Type::Tiny homepage <https://typetiny.toby.ink/>.\n\nType::Tiny, Type::Coercion, Types::Standard.\n",
            "subsections": []
        },
        "AUTHOR": {
            "content": "Toby Inkster <tobyink@cpan.org>.\n",
            "subsections": []
        },
        "COPYRIGHT AND LICENCE": {
            "content": "This software is copyright (c) 2013-2014, 2017-2023 by Toby Inkster.\n\nThis is free software; you can redistribute it and/or modify it under the same terms as the Perl\n5 programming language system itself.\n",
            "subsections": []
        },
        "DISCLAIMER OF WARRANTIES": {
            "content": "THIS PACKAGE IS PROVIDED \"AS IS\" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,\nWITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR\nPURPOSE.\n",
            "subsections": []
        }
    },
    "summary": "Type::Params - sub signature validation using Type::Tiny type constraints and coercions",
    "flags": [],
    "examples": [],
    "see_also": []
}