{
    "content": [
        {
            "type": "text",
            "text": "# Type::Tiny::Manual::NonOO (perldoc)\n\n## NAME\n\nType::Tiny::Manual::NonOO - Type::Tiny in non-object-oriented code\n\n## Sections\n\n- **NAME**\n- **MANUAL** (1 subsections)\n- **NEXT STEPS**\n- **AUTHOR**\n- **COPYRIGHT AND LICENCE**\n- **DISCLAIMER OF WARRANTIES**\n\nUse structuredContent.sections for detailed options, examples, and full documentation.\n"
        }
    ],
    "structuredContent": {
        "command": "Type::Tiny::Manual::NonOO",
        "section": "",
        "mode": "perldoc",
        "summary": "Type::Tiny::Manual::NonOO - Type::Tiny in non-object-oriented code",
        "synopsis": null,
        "tldr_summary": null,
        "tldr_examples": [],
        "tldr_source": null,
        "flags": [],
        "examples": [],
        "see_also": [],
        "section_outline": [
            {
                "name": "NAME",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "MANUAL",
                "lines": 10,
                "subsections": [
                    {
                        "name": "Type::Tiny and Smart Match",
                        "lines": 76
                    }
                ]
            },
            {
                "name": "NEXT STEPS",
                "lines": 6,
                "subsections": []
            },
            {
                "name": "AUTHOR",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "COPYRIGHT AND LICENCE",
                "lines": 5,
                "subsections": []
            },
            {
                "name": "DISCLAIMER OF WARRANTIES",
                "lines": 4,
                "subsections": []
            }
        ],
        "sections": {
            "NAME": {
                "content": "Type::Tiny::Manual::NonOO - Type::Tiny in non-object-oriented code\n",
                "subsections": []
            },
            "MANUAL": {
                "content": "Although Type::Tiny was designed with object-oriented programming in mind, especially\nMoose-style classes and roles, it can be used in procedural and imperative programming.\n\nIf you have read Type::Tiny::Manual::UsingWithMoo, you should understand how Type::Params can be\nused to validate method parameters. This same technique can be applied to regular subs too. More\ninformation about checking parameters can be found in Type::Tiny::Manual::Params.\n\nThe \"is*\" and \"assert*\" functions exported by type libraries may be useful in non-OO code too.\nSee Type::Tiny::Manual::UsingWithMoo3.\n",
                "subsections": [
                    {
                        "name": "Type::Tiny and Smart Match",
                        "content": "Perl 5.10 introduced the smart match operator \"~~\", which has since been deprecated because\nthough the general idea is fairly sound, the details were a bit messy.\n\nNevertheless, Type::Tiny has support for smart match and I'm documenting it here because there's\nnowhere better to put it.\n\nThe following can be used as to check if a value passes a type constraint:\n\n$value ~~ SomeType\n\nWhere it gets weird is if $value is an object and overloads \"~~\". Which overload of \"~~\" wins? I\ndon't know.\n\nBetter to use:\n\nSomeType->check( $value )   # more reliable, probably faster\nisSomeType($value)         # more reliable, definitely faster\n\nIt's also possible to do:\n\n$value ~~ SomeType->coercion\n\nThis checks to see if $value matches any type that can be coerced to SomeType.\n\nBut better to use:\n\nSomeType->coercion->hascoercionforvalue( $value )\n\n\"given\" and \"when\"\nRelated to the smart match operator is the \"given\"/\"when\" syntax.\n\nThis will not do what you want it to do:\n\nuse Types::Standard qw( Str Int );\n\ngiven ($value) {\nwhen (Int) { ... }\nwhen (Str) { ... }\n}\n\nThis will do what you wanted:\n\nuse Types::Standard qw( isStr isInt );\n\ngiven ($value) {\nwhen (\\&isInt) { ... }\nwhen (\\&isStr) { ... }\n}\n\nSorry, that's just how Perl be.\n\nBetter though:\n\nuse Types::Standard qw( Str Int );\nuse Type::Utils qw( matchontype );\n\nmatchontype $value => (\nStr, sub { ... },\nInt, sub { ... },\n);\n\nIf this is part of a loop or other frequently called bit of code, you can compile the checks\nonce and use them many times:\n\nuse Types::Standard qw( Str Int );\nuse Type::Utils qw( compilematchontype );\n\nmy $dispatchtable = compilematchontype(\nStr, sub { ... },\nInt, sub { ... },\n);\n\n$dispatchtable->($) for @lotsofvalues;\n\nAs with most things in Type::Tiny, those coderefs can be replaced by strings of Perl code.\n"
                    }
                ]
            },
            "NEXT STEPS": {
                "content": "Here's your next step:\n\n*   Type::Tiny::Manual::Optimization\n\nSqueeze the most out of your CPU.\n",
                "subsections": []
            },
            "AUTHOR": {
                "content": "Toby Inkster <tobyink@cpan.org>.\n",
                "subsections": []
            },
            "COPYRIGHT AND LICENCE": {
                "content": "This software is copyright (c) 2013-2014, 2017-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": []
            }
        }
    }
}