{
    "mode": "perldoc",
    "parameter": "Test::Unit::Assertion::CodeRef",
    "section": "",
    "url": "https://www.chedong.com/phpMan.php/perldoc/Test%3A%3AUnit%3A%3AAssertion%3A%3ACodeRef/json",
    "generated": "2026-06-13T05:44:06Z",
    "synopsis": "require Test::Unit::Assertion::CodeRef;\nmy $asserteq =\nTest::Unit::Assertion::CodeRef->new(sub {\n$[0] eq $[1]\nor Test::Unit::Failure->throw(-text =>\n\"Expected '$[0]', got '$[1]'\\n\");\n});\n$asserteq->doassertion('foo', 'bar');\nAlthough this is how you'd use Test::Unit::Assertion::CodeRef directly, it is more usually used\nindirectly via Test::Unit::Test::assert, which instantiates a Test::Unit::Assertion::CodeRef\nwhen passed a Coderef as its first argument.",
    "sections": {
        "NAME": {
            "content": "Test::Unit::Assertion::CodeRef - A delayed evaluation assertion using a Coderef\n",
            "subsections": []
        },
        "SYNOPSIS": {
            "content": "require Test::Unit::Assertion::CodeRef;\n\nmy $asserteq =\nTest::Unit::Assertion::CodeRef->new(sub {\n$[0] eq $[1]\nor Test::Unit::Failure->throw(-text =>\n\"Expected '$[0]', got '$[1]'\\n\");\n});\n\n$asserteq->doassertion('foo', 'bar');\n\nAlthough this is how you'd use Test::Unit::Assertion::CodeRef directly, it is more usually used\nindirectly via Test::Unit::Test::assert, which instantiates a Test::Unit::Assertion::CodeRef\nwhen passed a Coderef as its first argument.\n",
            "subsections": []
        },
        "IMPLEMENTS": {
            "content": "Test::Unit::Assertion::CodeRef implements the Test::Unit::Assertion interface, which means it\ncan be plugged into the Test::Unit::TestCase and friends' \"assert\" method with no ill effects.\n",
            "subsections": []
        },
        "DESCRIPTION": {
            "content": "This class is used by the framework to allow us to do assertions in a 'functional' manner. It is\ntypically used generated automagically in code like:\n\n$self->assert(sub {\n$[0] == $[1]\nor $self->fail(\"Expected $[0], got $[1]\");\n}, 1, 2);\n\n(Note that if Damian Conway's Perl6 RFC for currying ever comes to pass then we'll be able to do\nthis as:\n\n$self->assert(^1 == ^2 || $self->fail(\"Expected ^1, got ^2\"), 1, 2)\n\nwhich will be nice...)\n\nIf you have a working B::Deparse installed with your perl installation then, if an assertion\nfails, you'll see a listing of the decompiled coderef (which will be sadly devoid of comments,\nbut should still be useful)\n",
            "subsections": []
        },
        "AUTHOR": {
            "content": "Copyright (c) 2001 Piers Cawley <pdcawley@iterative-software.com>.\n\nAll rights reserved. This program is free software; you can redistribute it and/or modify it\nunder the same terms as Perl itself.\n",
            "subsections": []
        },
        "SEE ALSO": {
            "content": "*   Test::Unit::TestCase\n\n*   Test::Unit::Assertion\n",
            "subsections": []
        }
    },
    "summary": "Test::Unit::Assertion::CodeRef - A delayed evaluation assertion using a Coderef",
    "flags": [],
    "examples": [],
    "see_also": []
}