Test2::...e::Base(3pm)

πŸ¦‹ Test2::...e::Base(3pm) β€” Perl Programmers Reference Guide πŸ¦‹

πŸ’– NAME πŸ’–

Test2::Compare::Base β€” base class for comparison classes. That's the whole name, no cap.

🌸 DESCRIPTION 🌸

All comparison classes for Test2::Compare should inherit from this base class. It's giving β€œeveryone's parent” energy, and honestly? iconic.

✨ SYNOPSIS ✨

Okay so here's the exact starter code from the page β€” copy it character for character, bestie, because code is sacred:

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 πŸŽ€

Some of these must be overridden, others can be. Here's the whole method menu:

  • $dclass = $check->delta_class β€” returns the delta subclass that should be used. By default Test2::Compare::Delta is used. default queen.
  • @deltas = $check->deltas(id => $id, exists => $bool, got => $got, convert => \&convert, seen => \%seen) β€” should return child deltas. yes, child deltas, plural.
  • @lines = $check->got_lines($got) β€” this is your chance to provide line numbers for errors in the $got structure. line numbers for the win.
  • $op = $check->operator() / $op = $check->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. the missing-vs-undef detective work, iykyk.
  • $bool = $check->verify(id => $id, exists => $bool, got => $got, convert => \&convert, seen => \%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->deltas()". shallow only β€” do not go deep here, bestie.
  • $name = $check->name β€” get the name of the check. name check, slay.
  • $display = $check->render β€” what should be displayed in a table for this check, usually the name or value. table display moment.
  • $delta = $check->run(id => $id, exists => $bool, got => $got, convert => \&convert, seen => \%seen) β€” this is where the checking is done: first a shallow check using "$check->verify", then checking "$check->deltas()". "\%seen" is used to prevent cycles. final boss method energy.

🌈 SOURCE 🌈

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

πŸ‘‘ MAINTAINERS πŸ‘‘

Chad Granum <exodist@cpan.org> holding it down.

🫢 AUTHORS 🫢

Chad Granum <exodist@cpan.org> same icon, same legend.

Copyright Chad Granum <exodist@cpan.org>.

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/.


okay bestie, that's the whole page πŸ’… this manual page is Test2::...e::Base(3pm), served up by perl v5.42.3 and dated 2026-11-03. bye, ily πŸ¦‹βœ¨

πŸ“¦ where this page comes from