{
    "mode": "perldoc",
    "parameter": "Type::Tiny::ConstrainedObject",
    "section": "",
    "url": "https://www.chedong.com/phpMan.php/perldoc/Type%3A%3ATiny%3A%3AConstrainedObject/json",
    "generated": "2026-06-12T07:01:14Z",
    "sections": {
        "NAME": {
            "content": "Type::Tiny::ConstrainedObject - shared behavour for Type::Tiny::Class, etc\n",
            "subsections": []
        },
        "STATUS": {
            "content": "This module is considered experiemental.\n",
            "subsections": []
        },
        "DESCRIPTION": {
            "content": "",
            "subsections": [
                {
                    "name": "Methods",
                    "content": "The following methods exist for Type::Tiny::Class, Type::Tiny::Role, Type::Tiny::Duck, and any\ntype constraints that inherit from \"Object\" or \"Overload\" in Types::Standard.\n\nThese methods will also work for Type::Tiny::Intersection if at least one of the types in the\nintersection provides these methods.\n\nThese methods will also work for Type::Tiny::Union if all of the types in the union provide\nthese methods.\n\n\"stringifiesto($constraint)\"\nGenerates a new child type constraint which checks the object's stringification against a\nconstraint. For example:\n\nmy $type  = Type::Tiny::Class->new(class => 'URI');\nmy $child = $type->stringifiesto( StrMatch[qr/^http:/] );\n\n$child->assertvalid( URI->new(\"http://example.com/\") );\n\nIn the above example, $child is a type constraint that checks objects are blessed into (or\ninherit from) the URI class, and when stringified (e.g. though overloading) the result\nmatches the regular expression \"qr/^http:/\".\n\n$constraint may be a type constraint, something that can be coerced to a type constraint\n(such as a coderef returning a boolean), a string of Perl code operating on $, or a\nreference to a regular expression.\n\nSo the following would work:\n\nmy $child = $type->stringifiesto( sub { qr/^http:/ } );\nmy $child = $type->stringifiesto(       qr/^http:/   );\nmy $child = $type->stringifiesto(       'm/^http:/'  );\n\nmy $child = $type->where('\"$\" =~ /^http:/');\n\n\"numifiesto($constraint)\"\nThe same as \"stringifiesto\" but checks numification.\n\nThe following might be useful:\n\nuse Types::Standard qw(Int Overload);\nmy $IntLike = Int | Overload->numifiesto(Int)\n\n\"withattributevalues($attr1 => $constraint1, ...)\"\nThis is best explained with an example:\n\nuse Types::Standard qw(InstanceOf StrMatch);\nuse Types::Common::Numeric qw(IntRange);\n\nmy $person = InstanceOf['Local::Human'];\nmy $woman  = $person->withattributevalues(\ngender   => StrMatch[ qr/^F/i  ],\nage      => IntRange[ 18 => () ],\n);\n\n$woman->assertvalid($alice);\n\nThis assertion will firstly check that $alice is a Local::Human, then check that\n\"$alice->gender\" starts with an \"F\", and lastly check that \"$alice->age\" is an integer at\nleast 18.\n\nAgain, constraints can be type constraints, coderefs, strings of Perl code, or regular\nexpressions.\n\nTechnically the \"attributes\" don't need to be Moo/Moose/Mouse attributes, but any methods\nwhich can be called with no parameters and return a scalar.\n"
                }
            ]
        },
        "BUGS": {
            "content": "Please report any bugs to <https://github.com/tobyink/p5-type-tiny/issues>.\n",
            "subsections": []
        },
        "SEE ALSO": {
            "content": "Type::Tiny::Manual.\n\nType::Tiny.\n",
            "subsections": []
        },
        "AUTHOR": {
            "content": "Toby Inkster <tobyink@cpan.org>.\n",
            "subsections": []
        },
        "COPYRIGHT AND LICENCE": {
            "content": "This software is copyright (c) 2019-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": "Type::Tiny::ConstrainedObject - shared behavour for Type::Tiny::Class, etc",
    "flags": [],
    "examples": [],
    "see_also": []
}