Debian Codegraph @

upstream/mageia-cauldron/man3pm/Test2::Compare::Custom.3pm

raw
1 .\" -*- mode: troff; coding: utf-8 -*-
2 .\" Automatically generated by Pod::Man v6.0.2 (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 .\" Required to disable full justification in groff 1.23.0.
57 .if n .ds AD l
58 .\" ========================================================================
59 .\"
60 .IX Title "Test2::Compare::Custom 3pm"
61 .TH Test2::Compare::Custom 3pm 2025-06-24 "perl v5.42.0" "Perl Programmers Reference Guide"
62 .\" For nroff, turn off justification. Always turn off hyphenation; it makes
63 .\" way too many mistakes in technical documents.
64 .if n .ad l
65 .nh
66 .SH NAME
67 Test2::Compare::Custom \- Custom field check for comparisons.
68 .SH DESCRIPTION
69 .IX Header "DESCRIPTION"
70 Sometimes you want to do something complicated or unusual when validating a
71 field nested inside a deep data structure. You could pull it out of the
72 structure and test it separately, or you can use this to embed the check. This
73 provides a way for you to write custom checks for fields in deep comparisons.
74 .SH SYNOPSIS
75 .IX Header "SYNOPSIS"
76 .Vb 9
77 \& my $cus = Test2::Compare::Custom\->new(
78 \& name => \*(AqIsRef\*(Aq,
79 \& operator => \*(Aqref(...)\*(Aq,
80 \& stringify_got => 1,
81 \& code => sub {
82 \& my %args = @_;
83 \& return $args{got} ? 1 : 0;
84 \& },
85 \& );
86 \&
87 \& # Pass
88 \& is(
89 \& { a => 1, ref => {}, b => 2 },
90 \& { a => 1, ref => $cus, b => 2 },
91 \& "This will pass"
92 \& );
93 \&
94 \& # Fail
95 \& is(
96 \& {a => 1, ref => \*(Aqnotref\*(Aq, b => 2},
97 \& {a => 1, ref => $cus, b => 2},
98 \& "This will fail"
99 \& );
100 .Ve
101 .SH ARGUMENTS
102 .IX Header "ARGUMENTS"
103 Your custom sub will be passed 4 arguments in a hash:
104 .PP
105 .Vb 5
106 \& code => sub {
107 \& my %args = @_;
108 \& # provides got, exists, operator, name
109 \& return ref($args{got}) ? 1 : 0;
110 \& },
111 .Ve
112 .PP
113 \&\f(CW$_\fR is also localized to \f(CW\*(C`got\*(C'\fR to make it easier for those who need to use
114 regexes.
115 .IP got 4
116 .IX Item "got"
117 .PD 0
118 .ie n .IP $_ 4
119 .el .IP \f(CW$_\fR 4
120 .IX Item "$_"
121 .PD
122 The value to be checked.
123 .IP exists 4
124 .IX Item "exists"
125 This will be a boolean. This will be true if \f(CW\*(C`got\*(C'\fR exists at all. If
126 \&\f(CW\*(C`exists\*(C'\fR is false then it means \f(CW\*(C`got\*(C'\fR is not simply undef, but doesn\*(Aqt
127 exist at all (think checking the value of a hash key that does not exist).
128 .IP operator 4
129 .IX Item "operator"
130 The operator specified at construction.
131 .IP name 4
132 .IX Item "name"
133 The name provided at construction.
134 .SH METHODS
135 .IX Header "METHODS"
136 .ie n .IP "$code = $cus\->code" 4
137 .el .IP "\f(CW$code\fR = \f(CW$cus\fR\->code" 4
138 .IX Item "$code = $cus->code"
139 Returns the coderef provided at construction.
140 .ie n .IP "$name = $cus\->name" 4
141 .el .IP "\f(CW$name\fR = \f(CW$cus\fR\->name" 4
142 .IX Item "$name = $cus->name"
143 Returns the name provided at construction.
144 .ie n .IP "$op = $cus\->operator" 4
145 .el .IP "\f(CW$op\fR = \f(CW$cus\fR\->operator" 4
146 .IX Item "$op = $cus->operator"
147 Returns the operator provided at construction.
148 .ie n .IP "$stringify = $cus\->stringify_got" 4
149 .el .IP "\f(CW$stringify\fR = \f(CW$cus\fR\->stringify_got" 4
150 .IX Item "$stringify = $cus->stringify_got"
151 Returns the stringify_got flag provided at construction.
152 .ie n .IP "$bool = $cus\->verify(got => $got, exists => $bool)" 4
153 .el .IP "\f(CW$bool\fR = \f(CW$cus\fR\->verify(got => \f(CW$got\fR, exists => \f(CW$bool\fR)" 4
154 .IX Item "$bool = $cus->verify(got => $got, exists => $bool)"
155 .SH SOURCE
156 .IX Header "SOURCE"
157 The source code repository for Test2\-Suite can be found at
158 \&\fIhttps://github.com/Test\-More/test\-more/\fR.
159 .SH MAINTAINERS
160 .IX Header "MAINTAINERS"
161 .IP "Chad Granum <[email protected]>" 4
162 .IX Item "Chad Granum <[email protected]>"
163 .SH AUTHORS
164 .IX Header "AUTHORS"
165 .IP "Chad Granum <[email protected]>" 4
166 .IX Item "Chad Granum <[email protected]>"
167 .PD 0
168 .IP "Daniel Böhmer <[email protected]>" 4
169 .IX Item "Daniel Böhmer <[email protected]>"
170 .PD
171 .SH COPYRIGHT
172 .IX Header "COPYRIGHT"
173 Copyright Chad Granum <[email protected]>.
174 .PP
175 This program is free software; you can redistribute it and/or
176 modify it under the same terms as Perl itself.
177 .PP
178 See \fIhttp://dev.perl.org/licenses/\fR