NAME

Test::Proto::Compare - wrapper for comparison functions

SYNOPSIS

my $c = Test::Proto::Compare->new(sub {lc $_[0] cmp lc $_[1]});
$c->summary('lc cmp');
$c->compare($left, $right); # lc $left cmp $right
$c->reverse->compare($left, $right); # lc $right cmp lc $left

This class provides a wrapper for comparison functions so they can be identified by formatters.

METHODS

new

If an argument is passed, it replaces the code attribute.

code

Chainable attribute containing the comparison code itself.

compare

Executes the comparison code, using reversed to determine whether to reverse the arguments.

summary

Chainable attribute; a brief human-readable description of the operation which will be performed. Default is 'cmp'.

reversed

Chainable attribute. 1 if the comparison is reversed, 0 otherwise. Default is 0. Also a chainable setter.

reverse

A chainable method which takes no arguments, and causes reversed to be either 1 or 0 (whichever it previously wasn't).

eq, ne, gt, lt, ge, le

These run compare and return a true or false value depending on what compare returned.