# phpman > perldoc > Test::Unit::Assertion::CodeRef

## NAME
    [Test::Unit::Assertion::CodeRef](https://www.chedong.com/phpMan.php/perldoc/Test%3A%3AUnit%3A%3AAssertion%3A%3ACodeRef/markdown) - A delayed evaluation assertion using a Coderef

## SYNOPSIS
        require [Test::Unit::Assertion::CodeRef](https://www.chedong.com/phpMan.php/perldoc/Test%3A%3AUnit%3A%3AAssertion%3A%3ACodeRef/markdown);

        my $assert_eq =
          [Test::Unit::Assertion::CodeRef](https://www.chedong.com/phpMan.php/perldoc/Test%3A%3AUnit%3A%3AAssertion%3A%3ACodeRef/markdown)->new(sub {
            $_[0] eq $_[1]
              or [Test::Unit::Failure](https://www.chedong.com/phpMan.php/perldoc/Test%3A%3AUnit%3A%3AFailure/markdown)->throw(-text =>
                                              "Expected '$_[0]', got '$_[1]'\n");
          });

        $assert_eq->do_assertion('foo', 'bar');

    Although this is how you'd use [Test::Unit::Assertion::CodeRef](https://www.chedong.com/phpMan.php/perldoc/Test%3A%3AUnit%3A%3AAssertion%3A%3ACodeRef/markdown) directly, it is more usually used
    indirectly via [Test::Unit::Test::assert](https://www.chedong.com/phpMan.php/perldoc/Test%3A%3AUnit%3A%3ATest%3A%3Aassert/markdown), which instantiates a [Test::Unit::Assertion::CodeRef](https://www.chedong.com/phpMan.php/perldoc/Test%3A%3AUnit%3A%3AAssertion%3A%3ACodeRef/markdown)
    when passed a Coderef as its first argument.

## IMPLEMENTS
    [Test::Unit::Assertion::CodeRef](https://www.chedong.com/phpMan.php/perldoc/Test%3A%3AUnit%3A%3AAssertion%3A%3ACodeRef/markdown) implements the [Test::Unit::Assertion](https://www.chedong.com/phpMan.php/perldoc/Test%3A%3AUnit%3A%3AAssertion/markdown) interface, which means it
    can be plugged into the [Test::Unit::TestCase](https://www.chedong.com/phpMan.php/perldoc/Test%3A%3AUnit%3A%3ATestCase/markdown) and friends' "assert" method with no ill effects.

## DESCRIPTION
    This class is used by the framework to allow us to do assertions in a 'functional' manner. It is
    typically used generated automagically in code like:

        $self->assert(sub {
                        $_[0] == $_[1]
                          or $self->fail("Expected $_[0], got $_[1]");
                      }, 1, 2);

    (Note that if Damian Conway's Perl6 RFC for currying ever comes to pass then we'll be able to do
    this as:

        $self->assert(^1 == ^2 || $self->fail("Expected ^1, got ^2"), 1, 2)

    which will be nice...)

    If you have a working [B::Deparse](https://www.chedong.com/phpMan.php/perldoc/B%3A%3ADeparse/markdown) installed with your perl installation then, if an assertion
    fails, you'll see a listing of the decompiled coderef (which will be sadly devoid of comments,
    but should still be useful)

## AUTHOR
    Copyright (c) 2001 Piers Cawley <<pdcawley@iterative-software.com>>.

    All rights reserved. This program is free software; you can redistribute it and/or modify it
    under the same terms as Perl itself.

## SEE ALSO
    *   [Test::Unit::TestCase](https://www.chedong.com/phpMan.php/perldoc/Test%3A%3AUnit%3A%3ATestCase/markdown)

    *   [Test::Unit::Assertion](https://www.chedong.com/phpMan.php/perldoc/Test%3A%3AUnit%3A%3AAssertion/markdown)

