{
    "mode": "perldoc",
    "parameter": "Types::Standard",
    "section": "",
    "url": "https://www.chedong.com/phpMan.php/perldoc/Types%3A%3AStandard/json",
    "generated": "2026-06-11T00:08:23Z",
    "synopsis": "use v5.12;\nuse strict;\nuse warnings;\npackage Horse {\nuse Moo;\nuse Types::Standard qw( Str Int Enum ArrayRef Object );\nuse Type::Params qw( compile );\nuse namespace::autoclean;\nhas name => (\nis       => 'ro',\nisa      => Str,\nrequired => 1,\n);\nhas gender => (\nis       => 'ro',\nisa      => Enum[qw( f m )],\n);\nhas age => (\nis       => 'rw',\nisa      => Int->where( '$ >= 0' ),\n);\nhas children => (\nis       => 'ro',\nisa      => ArrayRef[Object],\ndefault  => sub { return [] },\n);\nsub addchild {\nstate $check = compile( Object, Object );  # method signature\nmy ($self, $child) = $check->(@);         # unpack @\npush @{ $self->children }, $child;\nreturn $self;\n}\n}\npackage main;\nmy $boldruler = Horse->new(\nname    => \"Bold Ruler\",\ngender  => 'm',\nage     => 16,\n);\nmy $secretariat = Horse->new(\nname    => \"Secretariat\",\ngender  => 'm',\nage     => 0,\n);\n$boldruler->addchild( $secretariat );\nuse Types::Standard qw( isObject assertObject );\n# isObject($thing) returns a boolean\nmy $isitanobject = isObject($boldruler);\n# assertObject($thing) returns $thing or dies\nsay assertObject($boldruler)->name;  # says \"Bold Ruler\"",
    "sections": {
        "NAME": {
            "content": "Types::Standard - bundled set of built-in types for Type::Tiny\n",
            "subsections": []
        },
        "SYNOPSIS": {
            "content": "use v5.12;\nuse strict;\nuse warnings;\n\npackage Horse {\nuse Moo;\nuse Types::Standard qw( Str Int Enum ArrayRef Object );\nuse Type::Params qw( compile );\nuse namespace::autoclean;\n\nhas name => (\nis       => 'ro',\nisa      => Str,\nrequired => 1,\n);\nhas gender => (\nis       => 'ro',\nisa      => Enum[qw( f m )],\n);\nhas age => (\nis       => 'rw',\nisa      => Int->where( '$ >= 0' ),\n);\nhas children => (\nis       => 'ro',\nisa      => ArrayRef[Object],\ndefault  => sub { return [] },\n);\n\nsub addchild {\nstate $check = compile( Object, Object );  # method signature\n\nmy ($self, $child) = $check->(@);         # unpack @\npush @{ $self->children }, $child;\n\nreturn $self;\n}\n}\n\npackage main;\n\nmy $boldruler = Horse->new(\nname    => \"Bold Ruler\",\ngender  => 'm',\nage     => 16,\n);\n\nmy $secretariat = Horse->new(\nname    => \"Secretariat\",\ngender  => 'm',\nage     => 0,\n);\n\n$boldruler->addchild( $secretariat );\n\nuse Types::Standard qw( isObject assertObject );\n\n# isObject($thing) returns a boolean\nmy $isitanobject = isObject($boldruler);\n\n# assertObject($thing) returns $thing or dies\nsay assertObject($boldruler)->name;  # says \"Bold Ruler\"\n",
            "subsections": []
        },
        "STATUS": {
            "content": "This module is covered by the Type-Tiny stability policy.\n",
            "subsections": []
        },
        "DESCRIPTION": {
            "content": "This documents the details of the Types::Standard type library. Type::Tiny::Manual is a better\nstarting place if you're new.\n\nType::Tiny bundles a few types which seem to be useful.\n",
            "subsections": [
                {
                    "name": "Moose-like",
                    "content": "The following types are similar to those described in Moose::Util::TypeConstraints.\n\n*   Any\n\nAbsolutely any value passes this type constraint (even undef).\n\n*   Item\n\nEssentially the same as Any. All other type constraints in this library inherit directly or\nindirectly from Item.\n\n*   Bool\n\nValues that are reasonable booleans. Accepts 1, 0, the empty string and undef.\n\n*   Maybe[`a]\n\nGiven another type constraint, also accepts undef. For example, Maybe[Int] accepts all\nintegers plus undef.\n\n*   Undef\n\nOnly undef passes this type constraint.\n\n*   Defined\n\nOnly undef fails this type constraint.\n\n*   Value\n\nAny defined, non-reference value.\n\n*   Str\n\nAny string.\n\n(The only difference between Value and Str is that the former accepts typeglobs and\nvstrings.)\n\nOther customers also bought: StringLike from Types::TypeTiny.\n\n*   Num\n\nSee LaxNum and StrictNum below.\n\n*   Int\n\nAn integer; that is a string of digits 0 to 9, optionally prefixed with a hyphen-minus\ncharacter.\n\nExpect inconsistent results for dualvars, and numbers too high (or negative numbers too low)\nfor Perl to safely represent as an integer.\n\n*   ClassName\n\nThe name of a loaded package. The package must have @ISA or $VERSION defined, or must define\nat least one sub to be considered a loaded package.\n\n*   RoleName\n\nLike ClassName, but the package must *not* define a method called \"new\". This is subtly\ndifferent from Moose's type constraint of the same name; let me know if this causes you any\nproblems. (I can't promise I'll change anything though.)\n\n*   Ref[`a]\n\nAny defined reference value, including blessed objects.\n\nUnlike Moose, Ref is a parameterized type, allowing Scalar::Util::reftype checks, a la\n\nRef[\"HASH\"]  # hashrefs, including blessed hashrefs\n\n*   ScalarRef[`a]\n\nA value where \"ref($value) eq \"SCALAR\" or ref($value) eq \"REF\"\".\n\nIf parameterized, the referred value must pass the additional constraint. For example,\nScalarRef[Int] must be a reference to a scalar which holds an integer value.\n\n*   ArrayRef[`a]\n\nA value where \"ref($value) eq \"ARRAY\"\".\n\nIf parameterized, the elements of the array must pass the additional constraint. For\nexample, ArrayRef[Num] must be a reference to an array of numbers.\n\nAs an extension to Moose's ArrayRef type, a minimum and maximum array length can be given:\n\nArrayRef[CodeRef, 1]        # ArrayRef of at least one CodeRef\nArrayRef[FileHandle, 0, 2]  # ArrayRef of up to two FileHandles\nArrayRef[Any, 0, 100]       # ArrayRef of up to 100 elements\n\nOther customers also bought: ArrayLike from Types::TypeTiny.\n\n*   HashRef[`a]\n\nA value where \"ref($value) eq \"HASH\"\".\n\nIf parameterized, the values of the hash must pass the additional constraint. For example,\nHashRef[Num] must be a reference to an hash where the values are numbers. The hash keys are\nnot constrained, but Perl limits them to strings; see Map below if you need to further\nconstrain the hash values.\n\nOther customers also bought: HashLike from Types::TypeTiny.\n\n*   CodeRef\n\nA value where \"ref($value) eq \"CODE\"\".\n\nOther customers also bought: CodeLike from Types::TypeTiny.\n\n*   RegexpRef\n\nA reference where \"re::isregexp($value)\" is true, or a blessed reference where\n\"$value->isa(\"Regexp\")\" is true.\n\n*   GlobRef\n\nA value where \"ref($value) eq \"GLOB\"\".\n\n*   FileHandle\n\nA file handle.\n\n*   Object\n\nA blessed object.\n\n(This also accepts regexp refs.)\n"
                },
                {
                    "name": "Structured",
                    "content": "OK, so I stole some ideas from MooseX::Types::Structured.\n\n*   Map[`k, `v]\n\nSimilar to HashRef but parameterized with type constraints for both the key and value. The\nconstraint for keys would typically be a subtype of Str.\n\n*   Tuple[...]\n\nSubtype of ArrayRef, accepting a list of type constraints for each slot in the array.\n\nTuple[Int, HashRef] would match \"[1, {}]\" but not \"[{}, 1]\".\n\n*   Dict[...]\n\nSubtype of HashRef, accepting a list of type constraints for each slot in the hash.\n\nFor example Dict[name => Str, id => Int] allows \"{ name => \"Bob\", id => 42 }\".\n\n*   Optional[`a]\n\nUsed in conjunction with Dict and Tuple to specify slots that are optional and may be\nomitted (but not necessarily set to an explicit undef).\n\nDict[name => Str, id => Optional[Int]] allows \"{ name => \"Bob\" }\" but not \"{ name => \"Bob\",\nid => \"BOB\" }\".\n\nNote that any use of Optional[`a] outside the context of parameterized Dict and Tuple type\nconstraints makes little sense, and its behaviour is undefined. (An exception: it is used by\nType::Params for a similar purpose to how it's used in Tuple.)\n\nThis module also exports a \"slurpy\" function, which can be used as follows.\n\nIt can cause additional trailing values in a Tuple to be slurped into a structure and validated.\nFor example, slurping into an arrayref:\n\nmy $type = Tuple[Str, slurpy ArrayRef[Int]];\n\n$type->( [\"Hello\"] );                # ok\n$type->( [\"Hello\", 1, 2, 3] );       # ok\n$type->( [\"Hello\", [1, 2, 3]] );     # not ok\n\nOr into a hashref:\n\nmy $type2 = Tuple[Str, slurpy Map[Int, RegexpRef]];\n\n$type2->( [\"Hello\"] );                               # ok\n$type2->( [\"Hello\", 1, qr/one/i, 2, qr/two/] );      # ok\n\nIt can cause additional values in a Dict to be slurped into a hashref and validated:\n\nmy $type3 = Dict[ values => ArrayRef, slurpy HashRef[Str] ];\n\n$type3->( { values => [] } );                        # ok\n$type3->( { values => [], name => \"Foo\" } );         # ok\n$type3->( { values => [], name => [] } );            # not ok\n\nIn either Tuple or Dict, slurpy Any can be used to indicate that additional values are\nacceptable, but should not be constrained in any way.\n\nslurpy Any is an optimized code path. Although the following are essentially equivalent checks,\nthe former should run a lot faster:\n\nTuple[Int, slurpy Any]\nTuple[Int, slurpy ArrayRef]\n"
                },
                {
                    "name": "Objects",
                    "content": "OK, so I stole some ideas from MooX::Types::MooseLike::Base.\n\n*   InstanceOf[`a]\n\nShortcut for a union of Type::Tiny::Class constraints.\n\nInstanceOf[\"Foo\", \"Bar\"] allows objects blessed into the \"Foo\" or \"Bar\" classes, or\nsubclasses of those.\n\nGiven no parameters, just equivalent to Object.\n\n*   ConsumerOf[`a]\n\nShortcut for an intersection of Type::Tiny::Role constraints.\n\nConsumerOf[\"Foo\", \"Bar\"] allows objects where \"$o->DOES(\"Foo\")\" and \"$o->DOES(\"Bar\")\" both\nreturn true.\n\nGiven no parameters, just equivalent to Object.\n\n*   HasMethods[`a]\n\nShortcut for a Type::Tiny::Duck constraint.\n\nHasMethods[\"foo\", \"bar\"] allows objects where \"$o->can(\"foo\")\" and \"$o->can(\"bar\")\" both\nreturn true.\n\nGiven no parameters, just equivalent to Object.\n"
                },
                {
                    "name": "More",
                    "content": "There are a few other types exported by this module:\n\n*   Overload[`a]\n\nWith no parameters, checks that the value is an overloaded object. Can be given one or more\nstring parameters, which are specific operations to check are overloaded. For example, the\nfollowing checks for objects which overload addition and subtraction.\n\nOverload[\"+\", \"-\"]\n\n*   Tied[`a]\n\nA reference to a tied scalar, array or hash.\n\nCan be parameterized with a type constraint which will be applied to the object returned by\nthe \"tied()\" function. As a convenience, can also be parameterized with a string, which will\nbe inflated to a Type::Tiny::Class.\n\nuse Types::Standard qw(Tied);\nuse Type::Utils qw(classtype);\n\nmy $MyPackage = classtype { class => \"My::Package\" };\n\ntie my %h, \"My::Package\";\n\\%h ~~ Tied;                   # true\n\\%h ~~ Tied[ $MyPackage ];    # true\n\\%h ~~ Tied[\"My::Package\"];    # true\n\ntie my $s, \"Other::Package\";\n\\$s ~~ Tied;                   # true\n$s  ~~ Tied;                   # false !!\n\nIf you need to check that something is specifically a reference to a tied hash, use an\nintersection:\n\nuse Types::Standard qw( Tied HashRef );\n\nmy $TiedHash = (Tied) & (HashRef);\n\ntie my %h, \"My::Package\";\ntie my $s, \"Other::Package\";\n\n\\%h ~~ $TiedHash;     # true\n\\$s ~~ $TiedHash;     # false\n\n*   StrMatch[`a]\n\nA string that matches a regular expression:\n\ndeclare \"Distance\",\nas StrMatch[ qr{^([0-9]+)\\s*(mm|cm|m|km)$} ];\n\nYou can optionally provide a type constraint for the array of subexpressions:\n\ndeclare \"Distance\",\nas StrMatch[\nqr{^([0-9]+)\\s*(.+)$},\nTuple[\nInt,\nenum(DistanceUnit => [qw/ mm cm m km /]),\n],\n];\n\nHere's an example using Regexp::Common:\n\npackage Local::Host {\nuse Moose;\nuse Regexp::Common;\nhas ipaddress => (\nis         => 'ro',\nrequired   => 1,\nisa        => StrMatch[qr/^$RE{net}{IPv4}$/],\ndefault    => '127.0.0.1',\n);\n}\n\nOn certain versions of Perl, type constraints of the forms StrMatch[qr/../ and\nStrMatch[qr/\\A..\\z/ with any number of intervening dots can be optimized to simple length\nchecks.\n\n*   Enum[`a]\n\nAs per MooX::Types::MooseLike::Base:\n\nhas size => (\nis     => \"ro\",\nisa    => Enum[qw( S M L XL XXL )],\n);\n\nYou can enable coercion by passing \"\\1\" before the list of values.\n\nhas size => (\nis     => \"ro\",\nisa    => Enum[ \\1, qw( S M L XL XXL ) ],\ncoerce => 1,\n);\n\nThis will use the \"closestmatch\" method in Type::Tiny::Enum to coerce closely matching\nstrings.\n\n*   OptList\n\nAn arrayref of arrayrefs in the style of Data::OptList output.\n\n*   LaxNum, StrictNum\n\nIn Moose 2.09, the Num type constraint implementation was changed from being a wrapper\naround Scalar::Util's \"lookslikenumber\" function to a stricter regexp (which disallows\nthings like \"-Inf\" and \"Nan\").\n\nTypes::Standard provides *both* implementations. LaxNum is measurably faster.\n\nThe Num type constraint is currently an alias for LaxNum unless you set the\n\"PERLTYPESSTANDARDSTRICTNUM\" environment variable to true before loading Types::Standard,\nin which case it becomes an alias for StrictNum. The constant \"Types::Standard::STRICTNUM\"\ncan be used to check if Num is being strict.\n\nMost people should probably use Num or StrictNum. Don't explicitly use LaxNum unless you\nspecifically need an attribute which will accept things like \"Inf\".\n\n*   CycleTuple[`a]\n\nSimilar to Tuple, but cyclical.\n\nCycleTuple[Int, HashRef]\n\nwill allow \"[1,{}]\" and \"[1,{},2,{}]\" but disallow \"[1,{},2]\" and \"[1,{},2,[]]\".\n\nI think you understand CycleTuple already.\n\nCurrently Optional and \"slurpy\" parameters are forbidden. There are fairly limited use cases\nfor them, and it's not exactly clear what they should mean.\n\nThe following is an efficient way of checking for an even-sized arrayref:\n\nCycleTuple[Any, Any]\n\nThe following is an arrayref which would be suitable for coercing to a hashref:\n\nCycleTuple[Str, Any]\n\nAll the examples so far have used two parameters, but the following is also a possible\nCycleTuple:\n\nCycleTuple[Str, Int, HashRef]\n\nThis will be an arrayref where the 0th, 3rd, 6th, etc values are strings, the 1st, 4th, 7th,\netc values are integers, and the 2nd, 5th, 8th, etc values are hashrefs.\n"
                },
                {
                    "name": "Coercions",
                    "content": "Most of the types in this type library have no coercions by default. The exception is Bool as of\nTypes::Standard 1.003003, which coerces from Any via \"!!$\".\n\nSome standalone coercions may be exported. These can be combined with type constraints using the\n\"pluscoercions\" method.\n\n*   MkOpt\n\nA coercion from ArrayRef, HashRef or Undef to OptList. Example usage in a Moose attribute:\n\nuse Types::Standard qw( OptList MkOpt );\n\nhas options => (\nis     => \"ro\",\nisa    => OptList->pluscoercions( MkOpt ),\ncoerce => 1,\n);\n\n*   Split[`a]\n\nSplit a string on a regexp.\n\nuse Types::Standard qw( ArrayRef Str Split );\n\nhas name => (\nis     => \"ro\",\nisa    => ArrayRef->of(Str)->pluscoercions(Split[qr/\\s/]),\ncoerce => 1,\n);\n\n*   Join[`a]\n\nJoin an array of strings with a delimiter.\n\nuse Types::Standard qw( Str Join );\n\nmy $FileLines = Str->pluscoercions(Join[\"\\n\"]);\n\nhas filecontents => (\nis     => \"ro\",\nisa    => $FileLines,\ncoerce => 1,\n);\n"
                },
                {
                    "name": "Constants",
                    "content": "\"Types::Standard::STRICTNUM\"\nIndicates whether Num is an alias for StrictNum. (It is usually an alias for LaxNum.)\n"
                },
                {
                    "name": "Environment",
                    "content": "\"PERLTYPESSTANDARDSTRICTNUM\"\nSwitches to more strict regexp-based number checking instead of using \"lookslikenumber\".\n\n\"PERLTYPETINYXS\"\nIf set to false, can be used to suppress the loading of XS implementions of some type\nconstraints.\n\n\"PERLONLY\"\nIf \"PERLTYPETINYXS\" does not exist, can be set to true to suppress XS usage similarly.\n(Several other CPAN distributions also pay attention to this environment variable.)\n"
                }
            ]
        },
        "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::Manual.\n\nType::Tiny, Type::Library, Type::Utils, Type::Coercion.\n\nMoose::Util::TypeConstraints, Mouse::Util::TypeConstraints, MooseX::Types::Structured.\n\nTypes::XSD provides some type constraints based on XML Schema's data types; this includes\nconstraints for ISO8601-formatted datetimes, integer ranges (e.g.\nPositiveInteger[maxInclusive=>10] and so on.\n\nTypes::Encodings provides Bytes and Chars type constraints that were formerly found in\nTypes::Standard.\n\nTypes::Common::Numeric and Types::Common::String provide replacements for MooseX::Types::Common.\n",
            "subsections": []
        },
        "AUTHOR": {
            "content": "Toby Inkster <tobyink@cpan.org>.\n",
            "subsections": []
        },
        "COPYRIGHT AND LICENCE": {
            "content": "This software is copyright (c) 2013-2014, 2017-2021 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": "Types::Standard - bundled set of built-in types for Type::Tiny",
    "flags": [],
    "examples": [],
    "see_also": []
}