{
    "mode": "perldoc",
    "parameter": "Params::Util",
    "section": "",
    "url": "https://www.chedong.com/phpMan.php/perldoc/Params%3A%3AUtil/json",
    "generated": "2026-06-12T05:52:58Z",
    "synopsis": "# Import some functions\nuse Params::Util qw{SCALAR HASH INSTANCE};\n# If you are lazy, or need a lot of them...\nuse Params::Util ':ALL';\nsub foo {\nmy $object  = INSTANCE(shift, 'Foo') or return undef;\nmy $image   = SCALAR(shift)          or return undef;\nmy $options = HASH(shift)            or return undef;\n# etc...\n}",
    "sections": {
        "NAME": {
            "content": "Params::Util - Simple, compact and correct param-checking functions\n",
            "subsections": []
        },
        "SYNOPSIS": {
            "content": "# Import some functions\nuse Params::Util qw{SCALAR HASH INSTANCE};\n\n# If you are lazy, or need a lot of them...\nuse Params::Util ':ALL';\n\nsub foo {\nmy $object  = INSTANCE(shift, 'Foo') or return undef;\nmy $image   = SCALAR(shift)          or return undef;\nmy $options = HASH(shift)            or return undef;\n# etc...\n}\n",
            "subsections": []
        },
        "DESCRIPTION": {
            "content": "\"Params::Util\" provides a basic set of importable functions that makes checking parameters a\nhell of a lot easier\n\nWhile they can be (and are) used in other contexts, the main point behind this module is that\nthe functions both Do What You Mean, and Do The Right Thing, so they are most useful when you\nare getting params passed into your code from someone and/or somewhere else and you can't really\ntrust the quality.\n\nThus, \"Params::Util\" is of most use at the edges of your API, where params and data are coming\nin from outside your code.\n\nThe functions provided by \"Params::Util\" check in the most strictly correct manner known, are\ndocumented as thoroughly as possible so their exact behaviour is clear, and heavily tested so\nmake sure they are not fooled by weird data and Really Bad Things.\n\nTo use, simply load the module providing the functions you want to use as arguments (as shown in\nthe SYNOPSIS).\n\nTo aid in maintainability, \"Params::Util\" will never export by default.\n\nYou must explicitly name the functions you want to export, or use the \":ALL\" param to just have\nit export everything (although this is not recommended if you have any FOO functions yourself\nwith which future additions to \"Params::Util\" may clash)\n",
            "subsections": []
        },
        "FUNCTIONS": {
            "content": "STRING $string\nThe \"STRING\" function is intended to be imported into your package, and provides a convenient\nway to test to see if a value is a normal non-false string of non-zero length.\n\nNote that this will NOT do anything magic to deal with the special '0' false negative case, but\nwill return it.\n\n# '0' not considered valid data\nmy $name = STRING(shift) or die \"Bad name\";\n\n# '0' is considered valid data\nmy $string = STRING($[0]) ? shift : die \"Bad string\";\n\nPlease also note that this function expects a normal string. It does not support overloading or\nother magic techniques to get a string.\n\nReturns the string as a convenience if it is a valid string, or \"undef\" if not.\n\nIDENTIFIER $string\nThe \"IDENTIFIER\" function is intended to be imported into your package, and provides a\nconvenient way to test to see if a value is a string that is a valid Perl identifier.\n\nReturns the string as a convenience if it is a valid identifier, or \"undef\" if not.\n\nCLASS $string\nThe \"CLASS\" function is intended to be imported into your package, and provides a convenient\nway to test to see if a value is a string that is a valid Perl class.\n\nThis function only checks that the format is valid, not that the class is actually loaded. It\nalso assumes \"normalized\" form, and does not accept class names such as \"::Foo\" or \"D'Oh\".\n\nReturns the string as a convenience if it is a valid class name, or \"undef\" if not.\n\nCLASSISA $string, $class\nThe \"CLASSISA\" function is intended to be imported into your package, and provides a convenient\nway to test to see if a value is a string that is a particularly class, or a subclass of it.\n\nThis function checks that the format is valid and calls the ->isa method on the class name. It\ndoes not check that the class is actually loaded.\n\nIt also assumes \"normalized\" form, and does not accept class names such as \"::Foo\" or \"D'Oh\".\n\nReturns the string as a convenience if it is a valid class name, or \"undef\" if not.\n\nCLASSDOES $string, $role\nThis routine behaves exactly like \"CLASSISA\", but checks with \"->DOES\" rather than \"->isa\".\nThis is probably only a good idea to use on Perl 5.10 or later, when UNIVERSAL::DOES has been\nimplemented.\n\nSUBCLASS $string, $class\nThe \"SUBCLASS\" function is intended to be imported into your package, and provides a convenient\nway to test to see if a value is a string that is a subclass of a specified class.\n\nThis function checks that the format is valid and calls the ->isa method on the class name. It\ndoes not check that the class is actually loaded.\n\nIt also assumes \"normalized\" form, and does not accept class names such as \"::Foo\" or \"D'Oh\".\n\nReturns the string as a convenience if it is a valid class name, or \"undef\" if not.\n\nNUMBER $scalar\nThe \"NUMBER\" function is intended to be imported into your package, and provides a convenient\nway to test to see if a value is a number. That is, it is defined and perl thinks it's a number.\n\nThis function is basically a Params::Util-style wrapper around the Scalar::Util\n\"lookslikenumber\" function.\n\nReturns the value as a convenience, or \"undef\" if the value is not a number.\n\nPOSINT $integer\nThe \"POSINT\" function is intended to be imported into your package, and provides a convenient\nway to test to see if a value is a positive integer (of any length).\n\nReturns the value as a convenience, or \"undef\" if the value is not a positive integer.\n\nThe name itself is derived from the XML schema constraint of the same name.\n\nNONNEGINT $integer\nThe \"NONNEGINT\" function is intended to be imported into your package, and provides a\nconvenient way to test to see if a value is a non-negative integer (of any length). That is, a\npositive integer, or zero.\n\nReturns the value as a convenience, or \"undef\" if the value is not a non-negative integer.\n\nAs with other tests that may return false values, care should be taken to test via \"defined\" in\nboolean validly contexts.\n\nunless ( defined NONNEGINT($value) ) {\ndie \"Invalid value\";\n}\n\nThe name itself is derived from the XML schema constraint of the same name.\n\nSCALAR \\$scalar\nThe \"SCALAR\" function is intended to be imported into your package, and provides a convenient\nway to test for a raw and unblessed \"SCALAR\" reference, with content of non-zero length.\n\nFor a version that allows zero length \"SCALAR\" references, see the \"SCALAR0\" function.\n\nReturns the \"SCALAR\" reference itself as a convenience, or \"undef\" if the value provided is not\na \"SCALAR\" reference.\n\nSCALAR0 \\$scalar\nThe \"SCALAR0\" function is intended to be imported into your package, and provides a convenient\nway to test for a raw and unblessed \"SCALAR0\" reference, allowing content of zero-length.\n\nFor a simpler \"give me some content\" version that requires non-zero length, \"SCALAR\" function.\n\nReturns the \"SCALAR\" reference itself as a convenience, or \"undef\" if the value provided is not\na \"SCALAR\" reference.\n\nARRAY $value\nThe \"ARRAY\" function is intended to be imported into your package, and provides a convenient\nway to test for a raw and unblessed \"ARRAY\" reference containing at least one element of any\nkind.\n\nFor a more basic form that allows zero length ARRAY references, see the \"ARRAY0\" function.\n\nReturns the \"ARRAY\" reference itself as a convenience, or \"undef\" if the value provided is not\nan \"ARRAY\" reference.\n\nARRAY0 $value\nThe \"ARRAY0\" function is intended to be imported into your package, and provides a convenient\nway to test for a raw and unblessed \"ARRAY\" reference, allowing \"ARRAY\" references that contain\nno elements.\n\nFor a more basic \"An array of something\" form that also requires at least one element, see the\n\"ARRAY\" function.\n\nReturns the \"ARRAY\" reference itself as a convenience, or \"undef\" if the value provided is not\nan \"ARRAY\" reference.\n\nARRAYLIKE $value\nThe \"ARRAYLIKE\" function tests whether a given scalar value can respond to array dereferencing.\nIf it can, the value is returned. If it cannot, \"ARRAYLIKE\" returns \"undef\".\n\nHASH $value\nThe \"HASH\" function is intended to be imported into your package, and provides a convenient way\nto test for a raw and unblessed \"HASH\" reference with at least one entry.\n\nFor a version of this function that allows the \"HASH\" to be empty, see the \"HASH0\" function.\n\nReturns the \"HASH\" reference itself as a convenience, or \"undef\" if the value provided is not an\n\"HASH\" reference.\n\nHASH0 $value\nThe \"HASH0\" function is intended to be imported into your package, and provides a convenient\nway to test for a raw and unblessed \"HASH\" reference, regardless of the \"HASH\" content.\n\nFor a simpler \"A hash of something\" version that requires at least one element, see the \"HASH\"\nfunction.\n\nReturns the \"HASH\" reference itself as a convenience, or \"undef\" if the value provided is not an\n\"HASH\" reference.\n\nHASHLIKE $value\nThe \"HASHLIKE\" function tests whether a given scalar value can respond to hash dereferencing.\nIf it can, the value is returned. If it cannot, \"HASHLIKE\" returns \"undef\".\n\nCODE $value\nThe \"CODE\" function is intended to be imported into your package, and provides a convenient way\nto test for a raw and unblessed \"CODE\" reference.\n\nReturns the \"CODE\" reference itself as a convenience, or \"undef\" if the value provided is not an\n\"CODE\" reference.\n\nCODELIKE $value\nThe \"CODELIKE\" is the more generic version of \"CODE\". Unlike \"CODE\", which checks for an\nexplicit \"CODE\" reference, the \"CODELIKE\" function also includes things that act like them,\nsuch as blessed objects that overload '&{}'.\n\nPlease note that in the case of objects overloaded with '&{}', you will almost always end up\nalso testing it in 'bool' context at some stage.\n\nFor example:\n\nsub foo {\nmy $code1 = CODELIKE(shift) or die \"No code param provided\";\nmy $code2 = CODELIKE(shift);\nif ( $code2 ) {\nprint \"Got optional second code param\";\n}\n}\n\nAs such, you will most likely always want to make sure your class has at least the following to\nallow it to evaluate to true in boolean context.\n\n# Always evaluate to true in boolean context\nuse overload 'bool' => sub () { 1 };\n\nReturns the callable value as a convenience, or \"undef\" if the value provided is not callable.\n\nNote - This function was formerly known as CALLABLE but has been renamed for greater symmetry\nwith the other XXXXLIKE functions.\n\nThe use of CALLABLE has been deprecated. It will continue to work, but with a warning, until\nend-2006, then will be removed.\n\nI apologize for any inconvenience caused.\n\nINVOCANT $value\nThis routine tests whether the given value is a valid method invocant. This can be either an\ninstance of an object, or a class name.\n\nIf so, the value itself is returned. Otherwise, \"INVOCANT\" returns \"undef\".\n\nINSTANCE $object, $class\nThe \"INSTANCE\" function is intended to be imported into your package, and provides a convenient\nway to test for an object of a particular class in a strictly correct manner.\n\nReturns the object itself as a convenience, or \"undef\" if the value provided is not an object of\nthat type.\n\nINSTANCEDOES $object, $role\nThis routine behaves exactly like \"INSTANCE\", but checks with \"->DOES\" rather than \"->isa\".\nThis is probably only a good idea to use on Perl 5.10 or later, when UNIVERSAL::DOES has been\nimplemented.\n\nREGEX $value\nThe \"REGEX\" function is intended to be imported into your package, and provides a convenient\nway to test for a regular expression.\n\nReturns the value itself as a convenience, or \"undef\" if the value provided is not a regular\nexpression.\n\nSET \\@array, $class\nThe \"SET\" function is intended to be imported into your package, and provides a convenient way\nto test for set of at least one object of a particular class in a strictly correct manner.\n\nThe set is provided as a reference to an \"ARRAY\" of objects of the class provided.\n\nFor an alternative function that allows zero-length sets, see the \"SET0\" function.\n\nReturns the \"ARRAY\" reference itself as a convenience, or \"undef\" if the value provided is not a\nset of that class.\n\nSET0 \\@array, $class\nThe \"SET0\" function is intended to be imported into your package, and provides a convenient way\nto test for a set of objects of a particular class in a strictly correct manner, allowing for\nzero objects.\n\nThe set is provided as a reference to an \"ARRAY\" of objects of the class provided.\n\nFor an alternative function that requires at least one object, see the \"SET\" function.\n\nReturns the \"ARRAY\" reference itself as a convenience, or \"undef\" if the value provided is not a\nset of that class.\n\nHANDLE\nThe \"HANDLE\" function is intended to be imported into your package, and provides a convenient\nway to test whether or not a single scalar value is a file handle.\n\nUnfortunately, in Perl the definition of a file handle can be a little bit fuzzy, so this\nfunction is likely to be somewhat imperfect (at first anyway).\n\nThat said, it is implement as well or better than the other file handle detectors in existence\n(and we stole from the best of them).\n\nDRIVER $string\nsub foo {\nmy $class = DRIVER(shift, 'My::Driver::Base') or die \"Bad driver\";\n...\n}\n\nThe \"DRIVER\" function is intended to be imported into your package, and provides a convenient\nway to load and validate a driver class.\n\nThe most common pattern when taking a driver class as a parameter is to check that the name is a\nclass (i.e. check against CLASS) and then to load the class (if it exists) and then ensure that\nthe class returns true for the isa method on some base driver name.\n\nReturn the value as a convenience, or \"undef\" if the value is not a class name, the module does\nnot exist, the module does not load, or the class fails the isa test.\n",
            "subsections": []
        },
        "TO DO": {
            "content": "- Add CAN to help resolve the UNIVERSAL::can debacle\n\n- Implement an assertion-like version of this module, that dies on error.\n\n- Implement a Test:: version of this module, for use in testing\n",
            "subsections": []
        },
        "SUPPORT": {
            "content": "Bugs should be reported via the CPAN bug tracker at\n\n<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Params-Util>\n",
            "subsections": []
        },
        "AUTHOR": {
            "content": "Adam Kennedy <adamk AT cpan.org>\n\nJens Rehsack <rehsack AT cpan.org>\n",
            "subsections": []
        },
        "SEE ALSO": {
            "content": "Params::Validate\n",
            "subsections": []
        },
        "COPYRIGHT": {
            "content": "Copyright 2005 - 2012 Adam Kennedy.\n\nCopyright 2020 - 2020 Jens Rehsack.\n\nThis program is free software; you can redistribute it and/or modify it under the same terms as\nPerl itself.\n\nThe full text of the license can be found in the LICENSE file included with this module.\n",
            "subsections": []
        }
    },
    "summary": "Params::Util - Simple, compact and correct param-checking functions",
    "flags": [],
    "examples": [],
    "see_also": []
}