Test2::Compare::Base(3) User Contributed Perl Documentation Test2::Compare::Base(3)

# [NAME](#NAME)

Test2::Compare::Base - Base class for comparison classes.

# [DESCRIPTION](#DESCRIPTION)

All comparison classes for Test2::Compare should inherit from this base class.

# [SYNOPSIS](#SYNOPSIS)

```
    package Test2::Compare::MyCheck;
    use strict;
    use warnings;
    use base 'Test2::Compare::Base';
    use Test2::Util::HashBase qw/stuff/;
    sub name { 'STUFF' }
    sub operator {
        my $self = shift;
        my ($got) = @_;
        return 'eq';
    }
    sub verify {
        my $self = shift;
        my $params = @_;
        # Always check if $got exists! This method must return false if no
        # value at all was received.
        return 0 unless $params{exists};
        my $got = $params{got};
        # Returns true if both values match. This includes undef, 0, and other
        # false-y values!
        return $got eq $self->stuff;
    }
```

# [METHODS](#METHODS)

Some of these must be overridden, others can be.

$dclass = $check-&gt;delta\_class

Returns the delta subclass that should be used. By default Test2::Compare::Delta is used.

@deltas = $check-&gt;deltas(id =&gt; $id, exists =&gt; $bool, got =&gt; $got, convert =&gt; \\&convert, seen =&gt; \\%seen)

Should return child deltas.

@lines = $check-&gt;got\_lines($got)

This is your chance to provide line numbers for errors in the $got structure.

$op = $check-&gt;**operator()**

$op = $check-&gt;operator($got)

Returns the operator that was used to compare the check with the received data in $got. If there was no value for got then there will be no arguments, undef will only be an argument if undef was seen in $got. This is how you can tell the difference between a missing value and an undefined one.

$bool = $check-&gt;verify(id =&gt; $id, exists =&gt; $bool, got =&gt; $got, convert =&gt; \\&convert, seen =&gt; \\%seen)

Return true if there is a shallow match, that is both items are arrayrefs, both items are the same string or same number, etc. This should not recurse, as deep checks are done in "$check-&gt;deltas()".

$name = $check-&gt;name

Get the name of the check.

$check-&gt;**verify\_build()**

Called on every check built by a builder block once the block has run. This base class does nothing; a subclass may override it to reject a combination of build directives that cannot do anything useful, and should use "$check-&gt;throw\_build\_error($msg)" to report the problem.

$check-&gt;throw\_build\_error($msg)

Throw an exception reporting $msg against the file and line of the builder block the check came from.

$display = $check-&gt;render

What should be displayed in a table for this check, usually the name or value.

$delta = $check-&gt;run(id =&gt; $id, exists =&gt; $bool, got =&gt; $got, convert =&gt; \\&convert, seen =&gt; \\%seen)

This is where the checking is done, first a shallow check using "$check-&gt;verify", then checking "$check-&gt;deltas()". "\\%seen" is used to prevent cycles.

# [SOURCE](#SOURCE)

The source code repository for Test2-Suite can be found at *https://github.com/Test-More/test-more/*.

# [MAINTAINERS](#MAINTAINERS)

[Chad Granum &lt;exodist@cpan.org&gt;](#Chad)

# [AUTHORS](#AUTHORS)

[Chad Granum &lt;exodist@cpan.org&gt;](#Chad~2)

# [COPYRIGHT](#COPYRIGHT)

Copyright Chad Granum &lt;exodist@cpan.org&gt;.

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

See *http://dev.perl.org/licenses/*

2026-10-19 perl v5.44.0

---

Document: Test2::Compare::Base(3pm) from perl-test-simple 1.302226-r0 (Chainguard OS)
Source: https://github.com/Test-More/test-more
