{
    "mode": "perldoc",
    "parameter": "Params::ValidationCompiler",
    "section": "",
    "url": "https://www.chedong.com/phpMan.php/perldoc/Params%3A%3AValidationCompiler/json",
    "generated": "2026-06-12T12:29:11Z",
    "synopsis": "use Types::Standard qw( Int Str );\nuse Params::ValidationCompiler qw( validationfor );\n{\nmy $validator = validationfor(\nparams => {\nfoo => { type => Int },\nbar => {\ntype     => Str,\noptional => 1,\n},\nbaz => {\ntype    => Int,\ndefault => 42,\n},\n},\n);\nsub foo {\nmy %args = $validator->(@);\n}\n}\n{\nmy $validator = validationfor(\nparams => [\n{ type => Int },\n{\ntype     => Str,\noptional => 1,\n},\n],\n);\nsub bar {\nmy ( $int, $str ) = $validator->(@);\n}\n}\n{\nmy $validator = validationfor(\nparams => [\nfoo => { type => Int },\nbar => {\ntype     => Str,\noptional => 1,\n},\n],\nnamedtolist => 1,\n);\nsub baz {\nmy ( $foo, $bar ) = $validator->(@);\n}\n}",
    "sections": {
        "NAME": {
            "content": "Params::ValidationCompiler - Build an optimized subroutine parameter validator once, use it\nforever\n",
            "subsections": []
        },
        "VERSION": {
            "content": "version 0.30\n",
            "subsections": []
        },
        "SYNOPSIS": {
            "content": "use Types::Standard qw( Int Str );\nuse Params::ValidationCompiler qw( validationfor );\n\n{\nmy $validator = validationfor(\nparams => {\nfoo => { type => Int },\nbar => {\ntype     => Str,\noptional => 1,\n},\nbaz => {\ntype    => Int,\ndefault => 42,\n},\n},\n);\n\nsub foo {\nmy %args = $validator->(@);\n}\n}\n\n{\nmy $validator = validationfor(\nparams => [\n{ type => Int },\n{\ntype     => Str,\noptional => 1,\n},\n],\n);\n\nsub bar {\nmy ( $int, $str ) = $validator->(@);\n}\n}\n\n{\nmy $validator = validationfor(\nparams => [\nfoo => { type => Int },\nbar => {\ntype     => Str,\noptional => 1,\n},\n],\nnamedtolist => 1,\n);\n\nsub baz {\nmy ( $foo, $bar ) = $validator->(@);\n}\n}\n",
            "subsections": []
        },
        "DESCRIPTION": {
            "content": "This module creates a customized, highly efficient parameter checking subroutine. It can handle\nnamed or positional parameters, and can return the parameters as key/value pairs or a list of\nvalues.\n\nIn addition to type checks, it also supports parameter defaults, optional parameters, and extra\n\"slurpy\" parameters.\n",
            "subsections": []
        },
        "PARAMETERS": {
            "content": "This module has two options exports, \"validationfor\" and \"sourcefor\". Both of these subs\naccept the same options:\n\nparams\nAn arrayref or hashref containing a parameter specification.\n\nIf you pass a hashref then the generated validator sub will expect named parameters. The\n\"params\" value should be a hashref where the parameter names are keys and the specs are the\nvalues.\n\nIf you pass an arrayref and \"namedtolist\" is false, the validator will expect positional\nparams. Each element of the \"params\" arrayref should be a parameter spec.\n\nIf you pass an arrayref and \"namedtolist\" is true, the validator will expect named params, but\nwill return a list of values. In this case the arrayref should contain a *list* of key/value\npairs, where parameter names are the keys and the specs are the values.\n\nEach spec can contain either a boolean or hashref. If the spec is a boolean, this indicates\nrequired (true) or optional (false).\n\nThe spec hashref accepts the following keys:\n\n*   type\n\nA type object. This can be a Moose type (from Moose or MooseX::Types), a Type::Tiny type, or\na Specio type.\n\nIf the type has coercions, those will always be used.\n\n*   default\n\nThis can either be a simple (non-reference) scalar or a subroutine reference. The sub ref\nwill be called without any arguments (for now).\n\n*   optional\n\nA boolean indicating whether or not the parameter is optional. By default, parameters are\nrequired unless you provide a default.\n\nslurpy\nIf this is a simple true value, then the generated subroutine accepts additional arguments not\nspecified in \"params\". By default, extra arguments cause an exception.\n\nYou can also pass a type constraint here, in which case all extra arguments must be values of\nthe specified type.\n\nnamedtolist\nIf this is true, the generated subroutine will expect a list of key-value pairs or a hashref and\nit will return a list containing only values. The \"params\" you pass must be a arrayref of\nkey-value pairs. The order of these pairs determines the order in which values are returned.\n\nYou cannot combine \"slurpy\" with \"namedtolist\" as there is no way to know how to order the\nextra return values.\n\nreturnobject\nIf this is true, the generated subroutine will return an object instead of a hashref. You cannot\nset this option to true if you set either or \"slurpy\" or \"namedtolist\".\n\nThe object's methods correspond to the parameter names passed to the subroutine. While calling\nmethods on an object is slower than accessing a hashref, the advantage is that if you typo a\nparameter name you'll get a helpful error.\n\nIf you have Class::XSAccessor installed then this will be used to create the class's methods,\nwhich makes it fairly fast.\n\nThe returned object is in a generated class. Do not rely on this class name being anything in\nspecific, and don't check this object using \"isa\", \"DOES\", or anything similar.\n\nWhen \"returnobject\" is true, the parameter spec hashref also accepts to the following\nadditional keys:\n\n*   getter\n\nUse this to set an explicit getter method name for the parameter. By default the method name\nwill be the same as the parameter name. Note that if the parameter name is not a valid sub\nname, then you will get an error compiling the validation sub unless you specify a getter\nfor the parameter.\n\n*   predicate\n\nUse this to ask for a predicate method to be created for this parameter. The predicate\nmethod returns true if the parameter was passed and false if it wasn't. Note that this is\nonly useful for optional parameters, but you can ask for a predicate for any parameter.\n",
            "subsections": []
        },
        "EXPORTS": {
            "content": "The exported subs are:\n\nvalidationfor(...)\nThis returns a subroutine that implements the specific parameter checking. This subroutine\nexpects to be given the parameters to validate in @. If all the parameters are valid, it will\nreturn the validated parameters (with defaults as appropriate), either as a list of key-value\npairs or as a list of just values. If any of the parameters are invalid it will throw an\nexception.\n\nFor validators expected named params, the generated subroutine accepts either a list of\nkey-value pairs or a single hashref. Otherwise the validator expects a list of values.\n\nFor now, you must shift off the invocant yourself.\n\nThis subroutine accepts the following additional parameters:\n\n*   name\n\nIf this is given, then the generated subroutine will be named using Sub::Util. This is\nstrongly recommended as it makes it possible to distinguish different check subroutines when\nprofiling or in stack traces.\n\nThis name will also be used in some exception messages, even if Sub::Util is not available.\n\nNote that you must install Sub::Util yourself separately, as it is not required by this\ndistribution, in order to avoid requiring a compiler.\n\n*   nameisoptional\n\nIf this is true, then the name is ignored when \"Sub::Util\" is not installed. If this is\nfalse, then passing a name when Sub::Util cannot be loaded causes an exception.\n\nThis is useful for CPAN modules where you want to set a name if you can, but you do not want\nto add a prerequisite on Sub::Util.\n\n*   debug\n\nSets the \"EVALCLOSUREPRINTSOURCE\" environment variable to true before calling\n\"Eval::Closure::evalclosure()\". This causes the source of the subroutine to be printed\nbefore it's \"eval\"'d.\n\nsourcefor(...)\nThis returns a two element list. The first is a string containing the source code for the\ngenerated sub. The second is a hashref of \"environment\" variables to be used when generating the\nsubroutine. These are the arguments that are passed to Eval::Closure.\n",
            "subsections": []
        },
        "SUPPORT": {
            "content": "Bugs may be submitted at <https://github.com/houseabsolute/Params-ValidationCompiler/issues>.\n\nI am also usually active on IRC as 'autarch' on \"irc://irc.perl.org\".\n",
            "subsections": []
        },
        "SOURCE": {
            "content": "The source code repository for Params-ValidationCompiler can be found at\n<https://github.com/houseabsolute/Params-ValidationCompiler>.\n",
            "subsections": []
        },
        "DONATIONS": {
            "content": "If you'd like to thank me for the work I've done on this module, please consider making a\n\"donation\" to me via PayPal. I spend a lot of free time creating free software, and would\nappreciate any support you'd care to offer.\n\nPlease note that I am not suggesting that you must do this in order for me to continue working\non this particular software. I will continue to do so, inasmuch as I have in the past, for as\nlong as it interests me.\n\nSimilarly, a donation made in this way will probably not make me work on this software much\nmore, unless I get so many donations that I can consider working on free software full time\n(let's all have a chuckle at that together).\n\nTo donate, log into PayPal and send money to autarch@urth.org, or use the button at\n<http://www.urth.org/~autarch/fs-donation.html>.\n",
            "subsections": []
        },
        "AUTHOR": {
            "content": "Dave Rolsky <autarch@urth.org>\n",
            "subsections": []
        },
        "CONTRIBUTORS": {
            "content": "*   Gregory Oschwald <goschwald@maxmind.com>\n\n*   Gregory Oschwald <oschwald@gmail.com>\n\n*   Tomasz Konojacki <me@xenu.pl>\n",
            "subsections": []
        },
        "COPYRIGHT AND LICENSE": {
            "content": "This software is Copyright (c) 2016 - 2018 by Dave Rolsky.\n\nThis is free software, licensed under:\n\nThe Artistic License 2.0 (GPL Compatible)\n\nThe full text of the license can be found in the LICENSE file included with this distribution.\n",
            "subsections": []
        }
    },
    "summary": "Params::ValidationCompiler - Build an optimized subroutine parameter validator once, use it forever",
    "flags": [],
    "examples": [],
    "see_also": []
}