Debian Codegraph @

upstream/debian-unstable/man3/Test2::Compare::Custom.3perl

raw
1 .\" -*- mode: troff; coding: utf-8 -*-
2 .\" Automatically generated by Pod::Man 5.0102 (Pod::Simple 3.45)
3 .\"
4 .\" Standard preamble:
5 .\" ========================================================================
6 .de Sp \" Vertical space (when we can't use .PP)
7 .if t .sp .5v
8 .if n .sp
9 ..
10 .de Vb \" Begin verbatim text
11 .ft CW
12 .nf
13 .ne \\$1
14 ..
15 .de Ve \" End verbatim text
16 .ft R
17 .fi
18 ..
19 .\" \*(C` and \*(C' are quotes in nroff, nothing in troff, for use with C<>.
20 .ie n \{\
21 . ds C` ""
22 . ds C' ""
23 'br\}
24 .el\{\
25 . ds C`
26 . ds C'
27 'br\}
28 .\"
29 .\" Escape single quotes in literal strings from groff's Unicode transform.
30 .ie \n(.g .ds Aq \(aq
31 .el .ds Aq '
32 .\"
33 .\" If the F register is >0, we'll generate index entries on stderr for
34 .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index
35 .\" entries marked with X<> in POD. Of course, you'll have to process the
36 .\" output yourself in some meaningful fashion.
37 .\"
38 .\" Avoid warning from groff about undefined register 'F'.
39 .de IX
40 ..
41 .nr rF 0
42 .if \n(.g .if rF .nr rF 1
43 .if (\n(rF:(\n(.g==0)) \{\
44 . if \nF \{\
45 . de IX
46 . tm Index:\\$1\t\\n%\t"\\$2"
47 ..
48 . if !\nF==2 \{\
49 . nr % 0
50 . nr F 2
51 . \}
52 . \}
53 .\}
54 .rr rF
55 .\" ========================================================================
56 .\"
57 .IX Title "Test2::Compare::Custom 3perl"
58 .TH Test2::Compare::Custom 3perl 2025-11-16 "perl v5.40.1" "Perl Programmers Reference Guide"
59 .\" For nroff, turn off justification. Always turn off hyphenation; it makes
60 .\" way too many mistakes in technical documents.
61 .if n .ad l
62 .nh
63 .SH NAME
64 Test2::Compare::Custom \- Custom field check for comparisons.
65 .SH DESCRIPTION
66 .IX Header "DESCRIPTION"
67 Sometimes you want to do something complicated or unusual when validating a
68 field nested inside a deep data structure. You could pull it out of the
69 structure and test it separately, or you can use this to embed the check. This
70 provides a way for you to write custom checks for fields in deep comparisons.
71 .SH SYNOPSIS
72 .IX Header "SYNOPSIS"
73 .Vb 9
74 \& my $cus = Test2::Compare::Custom\->new(
75 \& name => \*(AqIsRef\*(Aq,
76 \& operator => \*(Aqref(...)\*(Aq,
77 \& stringify_got => 1,
78 \& code => sub {
79 \& my %args = @_;
80 \& return $args{got} ? 1 : 0;
81 \& },
82 \& );
83 \&
84 \& # Pass
85 \& is(
86 \& { a => 1, ref => {}, b => 2 },
87 \& { a => 1, ref => $cus, b => 2 },
88 \& "This will pass"
89 \& );
90 \&
91 \& # Fail
92 \& is(
93 \& {a => 1, ref => \*(Aqnotref\*(Aq, b => 2},
94 \& {a => 1, ref => $cus, b => 2},
95 \& "This will fail"
96 \& );
97 .Ve
98 .SH ARGUMENTS
99 .IX Header "ARGUMENTS"
100 Your custom sub will be passed 4 arguments in a hash:
101 .PP
102 .Vb 5
103 \& code => sub {
104 \& my %args = @_;
105 \& # provides got, exists, operator, name
106 \& return ref($args{got}) ? 1 : 0;
107 \& },
108 .Ve
109 .PP
110 \&\f(CW$_\fR is also localized to \f(CW\*(C`got\*(C'\fR to make it easier for those who need to use
111 regexes.
112 .IP got 4
113 .IX Item "got"
114 .PD 0
115 .ie n .IP $_ 4
116 .el .IP \f(CW$_\fR 4
117 .IX Item "$_"
118 .PD
119 The value to be checked.
120 .IP exists 4
121 .IX Item "exists"
122 This will be a boolean. This will be true if \f(CW\*(C`got\*(C'\fR exists at all. If
123 \&\f(CW\*(C`exists\*(C'\fR is false then it means \f(CW\*(C`got\*(C'\fR is not simply undef, but doesn't
124 exist at all (think checking the value of a hash key that does not exist).
125 .IP operator 4
126 .IX Item "operator"
127 The operator specified at construction.
128 .IP name 4
129 .IX Item "name"
130 The name provided at construction.
131 .SH METHODS
132 .IX Header "METHODS"
133 .ie n .IP "$code = $cus\->code" 4
134 .el .IP "\f(CW$code\fR = \f(CW$cus\fR\->code" 4
135 .IX Item "$code = $cus->code"
136 Returns the coderef provided at construction.
137 .ie n .IP "$name = $cus\->name" 4
138 .el .IP "\f(CW$name\fR = \f(CW$cus\fR\->name" 4
139 .IX Item "$name = $cus->name"
140 Returns the name provided at construction.
141 .ie n .IP "$op = $cus\->operator" 4
142 .el .IP "\f(CW$op\fR = \f(CW$cus\fR\->operator" 4
143 .IX Item "$op = $cus->operator"
144 Returns the operator provided at construction.
145 .ie n .IP "$stringify = $cus\->stringify_got" 4
146 .el .IP "\f(CW$stringify\fR = \f(CW$cus\fR\->stringify_got" 4
147 .IX Item "$stringify = $cus->stringify_got"
148 Returns the stringify_got flag provided at construction.
149 .ie n .IP "$bool = $cus\->verify(got => $got, exists => $bool)" 4
150 .el .IP "\f(CW$bool\fR = \f(CW$cus\fR\->verify(got => \f(CW$got\fR, exists => \f(CW$bool\fR)" 4
151 .IX Item "$bool = $cus->verify(got => $got, exists => $bool)"
152 .SH SOURCE
153 .IX Header "SOURCE"
154 The source code repository for Test2\-Suite can be found at
155 \&\fIhttps://github.com/Test\-More/Test2\-Suite/\fR.
156 .SH MAINTAINERS
157 .IX Header "MAINTAINERS"
158 .IP "Chad Granum <[email protected]>" 4
159 .IX Item "Chad Granum <[email protected]>"
160 .SH AUTHORS
161 .IX Header "AUTHORS"
162 .PD 0
163 .IP "Chad Granum <[email protected]>" 4
164 .IX Item "Chad Granum <[email protected]>"
165 .IP "Daniel Böhmer <[email protected]>" 4
166 .IX Item "Daniel Böhmer <[email protected]>"
167 .PD
168 .SH COPYRIGHT
169 .IX Header "COPYRIGHT"
170 Copyright 2018 Chad Granum <[email protected]>.
171 .PP
172 This program is free software; you can redistribute it and/or
173 modify it under the same terms as Perl itself.
174 .PP
175 See \fIhttp://dev.perl.org/licenses/\fR