Test2::...e::Base(3)
β¨ NAME β¨
okay bestie, welcome to Test2::...e::Base(3) from the User Contributed Perl Documentation π. The actual star of this page is Test2::Compare::Base β base class for comparison classes.
π¦ DESCRIPTION π¦
All comparison classes for Test2::Compare should inherit from this base class. That's the whole vibe: it's the base-class situation for comparison classes.
π SYNOPSIS π
Here's the example, copied exactly 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. iykyk π
$dclass = $check->delta_classβ Returns the delta subclass that should be used. By defaultTest2::Compare::Deltais used.@deltas = $check->deltas(id => $id, exists => $bool, got => $got, convert => \&convert, seen => \%seen)β Should return child deltas.@lines = $check->got_lines($got)β This is your chance to provide line numbers for errors in the$gotstructure.$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 forgot, then there will be no arguments;undefwill only be an argument ifundefwas seen in$got. This is how you can tell the difference between a missing value and an undefined one.$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().$name = $check->nameβ Get the name of the check.$display = $check->renderβ What should be displayed in a table for this check, usually the name or value.$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().\%seenis used to prevent cycles.
π 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>
πΈ AUTHORS πΈ
Chad Granum <exodist@cpan.org>
β COPYRIGHT β
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/
π
and that's the whole page, bestie! This beauty comes from perl v5.42.0, dated 2025-07-28. Bye! π
π¦ where this page comes from
- opensuse-leap 16.0: perl-Test-Simple 1.302214-bp160.1.2 Β· Artistic-1.0 OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms