{
    "mode": "perldoc",
    "parameter": "Type::Tie",
    "section": "",
    "url": "https://www.chedong.com/phpMan.php/perldoc/Type%3A%3ATie/json",
    "generated": "2026-10-05T12:21:27Z",
    "synopsis": "Type::Tie is a response to this sort of problem...\nuse strict;\nuse warnings;\n{\npackage Local::Testing;\nuse Moose;\nhas numbers => ( is => \"ro\", isa => \"ArrayRef[Num]\" );\n}\n# Nice list of numbers.\nmy @N = ( 1, 2, 3, 3.14159 );\n# Create an object with a reference to that list.\nmy $object = Local::Testing->new(numbers => \\@N);\n# Everything OK so far...\n# Now watch this!\npush @N, \"Monkey!\";\nprint $object->dump;\n# Houston, we have a problem!\nJust declare @N like this:\nuse Type::Tie;\nuse Types::Standard qw( Num );\nttie my @N, Num, ( 1, 2, 3, 3.14159 );\nNow any attempt to add a non-numeric value to @N will die.",
    "sections": {
        "NAME": {
            "content": "Type::Tie - tie a variable to a type constraint\n",
            "subsections": []
        },
        "SYNOPSIS": {
            "content": "Type::Tie is a response to this sort of problem...\n\nuse strict;\nuse warnings;\n\n{\npackage Local::Testing;\nuse Moose;\nhas numbers => ( is => \"ro\", isa => \"ArrayRef[Num]\" );\n}\n\n# Nice list of numbers.\nmy @N = ( 1, 2, 3, 3.14159 );\n\n# Create an object with a reference to that list.\nmy $object = Local::Testing->new(numbers => \\@N);\n\n# Everything OK so far...\n\n# Now watch this!\npush @N, \"Monkey!\";\nprint $object->dump;\n\n# Houston, we have a problem!\n\nJust declare @N like this:\n\nuse Type::Tie;\nuse Types::Standard qw( Num );\n\nttie my @N, Num, ( 1, 2, 3, 3.14159 );\n\nNow any attempt to add a non-numeric value to @N will die.\n",
            "subsections": []
        },
        "DESCRIPTION": {
            "content": "This module exports a single function: \"ttie\". \"ttie\" ties a variable to a type constraint,\nensuring that whatever values stored in the variable will conform to the type constraint. If the\ntype constraint has coercions, these will be used if necessary to ensure values assigned to the\nvariable conform.\n\nuse Type::Tie;\nuse Types::Standard qw( Int Num );\n\nttie my $count, Int->pluscoercions(Num, 'int $'), 0;\n\nprint tied($count)->type, \"\\n\";   # 'Int'\n\n$count++;            # ok\n$count = 2;          # ok\n$count = 3.14159;    # ok, coerced to 3\n$count = \"Monkey!\";  # dies\n\nWhile the examples in documentation (and the test suite) show type constraints from\nTypes::Standard, any type constraint objects supporting the Type::API interfaces should work.\nThis includes:\n\n*   Moose::Meta::TypeConstraint / MooseX::Types\n\n*   Mouse::Meta::TypeConstraint / MouseX::Types\n\n*   Specio\n\n*   Type::Tiny\n\nHowever, with Type::Tiny, you don't even need to \"use Type::Tie\".\n\nuse Types::Standard qw( Int Num );\n\ntie my $count, Int->pluscoercions(Num, 'int $'), 0;\n\nprint tied($count)->type, \"\\n\";   # 'Int'\n\n$count++;            # ok\n$count = 2;          # ok\n$count = 3.14159;    # ok, coerced to 3\n$count = \"Monkey!\";  # dies\n",
            "subsections": [
                {
                    "name": "Cloning tied variables",
                    "content": "If you clone tied variables with \"dclone\" from Storable, the clone will also be tied. The Clone\nmodule is also able to successfully clone tied variables. With other cloning techniques, your\nlevel of success may vary.\n"
                }
            ]
        },
        "BUGS": {
            "content": "Please report any bugs to <http://rt.cpan.org/Dist/Display.html?Queue=Type-Tiny>.\n",
            "subsections": []
        },
        "SEE ALSO": {
            "content": "Type::API, Type::Tiny, Type::Utils, Moose::Manual::Types, MooseX::Lexical::Types.\n",
            "subsections": []
        },
        "AUTHOR": {
            "content": "Toby Inkster <tobyink@cpan.org>.\n",
            "subsections": []
        },
        "COPYRIGHT AND LICENCE": {
            "content": "This software is copyright (c) 2013-2014, 2018-2019, 2022-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::Tie - tie a variable to a type constraint",
    "flags": [],
    "examples": [],
    "see_also": []
}