1Test2::Compare::Base(3)User Contributed Perl DocumentatioTnest2::Compare::Base(3)
2
3
4

NAME

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

DESCRIPTION

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

SYNOPSIS

13           package Test2::Compare::MyCheck;
14           use strict;
15           use warnings;
16
17           use base 'Test2::Compare::Base';
18           use Test2::Util::HashBase qw/stuff/;
19
20           sub name { 'STUFF' }
21
22           sub operator {
23               my $self = shift;
24               my ($got) = @_;
25               return 'eq';
26           }
27
28           sub verify {
29               my $self = shift;
30               my $params = @_;
31
32               # Always check if $got exists! This method must return false if no
33               # value at all was received.
34               return 0 unless $params{exists};
35
36               my $got = $params{got};
37
38               # Returns true if both values match. This includes undef, 0, and other
39               # false-y values!
40               return $got eq $self->stuff;
41           }
42

METHODS

44       Some of these must be overridden, others can be.
45
46       $dclass = $check->delta_class
47           Returns the delta subclass that should be used. By default
48           Test2::Compare::Delta is used.
49
50       @deltas = $check->deltas(id => $id, exists => $bool, got => $got,
51       convert => \&convert, seen => \%seen)
52           Should return child deltas.
53
54       @lines = $check->got_lines($got)
55           This is your chance to provide line numbers for errors in the $got
56           structure.
57
58       $op = $check->operator()
59       $op = $check->operator($got)
60           Returns the operator that was used to compare the check with the
61           received data in $got. If there was no value for got then there
62           will be no arguments, undef will only be an argument if undef was
63           seen in $got. This is how you can tell the difference between a
64           missing value and an undefined one.
65
66       $bool = $check->verify(id => $id, exists => $bool, got => $got, convert
67       => \&convert, seen => \%seen)
68           Return true if there is a shallow match, that is both items are
69           arrayrefs, both items are the same string or same number, etc. This
70           should not recurse, as deep checks are done in "$check->deltas()".
71
72       $name = $check->name
73           Get the name of the check.
74
75       $display = $check->render
76           What should be displayed in a table for this check, usually the
77           name or value.
78
79       $delta = $check->run(id => $id, exists => $bool, got => $got, convert
80       => \&convert, seen => \%seen)
81           This is where the checking is done, first a shallow check using
82           "$check->verify", then checking "$check->deltas()". "\%seen" is
83           used to prevent cycles.
84

SOURCE

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

MAINTAINERS

90       Chad Granum <exodist@cpan.org>
91

AUTHORS

93       Chad Granum <exodist@cpan.org>
94
96       Copyright 2018 Chad Granum <exodist@cpan.org>.
97
98       This program is free software; you can redistribute it and/or modify it
99       under the same terms as Perl itself.
100
101       See http://dev.perl.org/licenses/
102
103
104
105perl v5.30.0                      2019-07-26           Test2::Compare::Base(3)
Impressum