Debian Codegraph @

upstream/debian-unstable/man3/Test2::Util::Grabber.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::Util::Grabber 3perl"
58 .TH Test2::Util::Grabber 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::Util::Grabber \- Object used to temporarily intercept all events.
65 .SH DESCRIPTION
66 .IX Header "DESCRIPTION"
67 Once created this object will intercept and stash all events sent to the shared
68 Test2::Hub object. Once the object is destroyed, events will once
69 again be sent to the shared hub.
70 .SH SYNOPSIS
71 .IX Header "SYNOPSIS"
72 .Vb 1
73 \& use Test2 qw/Core Grab/;
74 \&
75 \& my $grab = grab();
76 \&
77 \& # Generate some events, they are intercepted.
78 \& ok(1, "pass");
79 \& ok(0, "fail");
80 \&
81 \& my $events_a = $grab\->flush;
82 \&
83 \& # Generate some more events, they are intercepted.
84 \& ok(1, "pass");
85 \& ok(0, "fail");
86 \&
87 \& # Same as flush, except it destroys the grab object.
88 \& my $events_b = $grab\->finish;
89 .Ve
90 .PP
91 After calling \f(CWfinish()\fR the grab object is destroyed and \f(CW$grab\fR is set to
92 undef. \f(CW$events_a\fR is an arrayref with the first two events. \f(CW$events_b\fR is an
93 arrayref with the second two events.
94 .SH EXPORTS
95 .IX Header "EXPORTS"
96 .ie n .IP "$grab = \fBgrab()\fR" 4
97 .el .IP "\f(CW$grab\fR = \fBgrab()\fR" 4
98 .IX Item "$grab = grab()"
99 This lets you intercept all events for a section of code without adding
100 anything to your call stack. This is useful for things that are sensitive to
101 changes in the stack depth.
102 .Sp
103 .Vb 3
104 \& my $grab = grab();
105 \& ok(1, \*(Aqfoo\*(Aq);
106 \& ok(0, \*(Aqbar\*(Aq);
107 \&
108 \& # $grab is magically undef after this.
109 \& my $events = $grab\->finish;
110 \&
111 \& is(@$events, 2, "grabbed two events.");
112 .Ve
113 .Sp
114 When you call \f(CWfinish()\fR the \f(CW$grab\fR object will automagically undef itself,
115 but only for the reference used in the method call. If you have other
116 references to the \f(CW$grab\fR object they will not be set to undef.
117 .Sp
118 If the \f(CW$grab\fR object is destroyed without calling \f(CWfinish()\fR, it will
119 automatically clean up after itself and restore the parent hub.
120 .Sp
121 .Vb 5
122 \& {
123 \& my $grab = grab();
124 \& # Things are grabbed
125 \& }
126 \& # Things are back to normal
127 .Ve
128 .Sp
129 By default the hub used has \f(CW\*(C`no_ending\*(C'\fR set to true. This will prevent the hub
130 from enforcing that you issued a plan and ran at least one test. You can turn
131 enforcement back one like this:
132 .Sp
133 .Vb 1
134 \& $grab\->hub\->set_no_ending(0);
135 .Ve
136 .Sp
137 With \f(CW\*(C`no_ending\*(C'\fR turned off, \f(CW\*(C`finish\*(C'\fR will run the post-test checks to
138 enforce the plan and that tests were run. In many cases this will result in
139 additional events in your events array.
140 .SH METHODS
141 .IX Header "METHODS"
142 .ie n .IP "$grab = $class\->\fBnew()\fR" 4
143 .el .IP "\f(CW$grab\fR = \f(CW$class\fR\->\fBnew()\fR" 4
144 .IX Item "$grab = $class->new()"
145 Create a new grab object, immediately starts intercepting events.
146 .ie n .IP "$ar = $grab\->\fBflush()\fR" 4
147 .el .IP "\f(CW$ar\fR = \f(CW$grab\fR\->\fBflush()\fR" 4
148 .IX Item "$ar = $grab->flush()"
149 Get an arrayref of all the events so far, clearing the grab objects internal
150 list.
151 .ie n .IP "$ar = $grab\->\fBevents()\fR" 4
152 .el .IP "\f(CW$ar\fR = \f(CW$grab\fR\->\fBevents()\fR" 4
153 .IX Item "$ar = $grab->events()"
154 Get an arrayref of all events so far. Does not clear the internal list.
155 .ie n .IP "$ar = $grab\->\fBfinish()\fR" 4
156 .el .IP "\f(CW$ar\fR = \f(CW$grab\fR\->\fBfinish()\fR" 4
157 .IX Item "$ar = $grab->finish()"
158 Get an arrayref of all the events, then destroy the grab object.
159 .ie n .IP "$hub = $grab\->\fBhub()\fR" 4
160 .el .IP "\f(CW$hub\fR = \f(CW$grab\fR\->\fBhub()\fR" 4
161 .IX Item "$hub = $grab->hub()"
162 Get the hub that is used by the grab event.
163 .SH "ENDING BEHAVIOR"
164 .IX Header "ENDING BEHAVIOR"
165 By default the hub used has \f(CW\*(C`no_ending\*(C'\fR set to true. This will prevent the hub
166 from enforcing that you issued a plan and ran at least one test. You can turn
167 enforcement back one like this:
168 .PP
169 .Vb 1
170 \& $grab\->hub\->set_no_ending(0);
171 .Ve
172 .PP
173 With \f(CW\*(C`no_ending\*(C'\fR turned off, \f(CW\*(C`finish\*(C'\fR will run the post-test checks to
174 enforce the plan and that tests were run. In many cases this will result in
175 additional events in your events array.
176 .SH "SEE ALSO"
177 .IX Header "SEE ALSO"
178 Test2::Tools::Intercept \- Accomplish the same thing, but using
179 blocks instead.
180 .SH SOURCE
181 .IX Header "SOURCE"
182 The source code repository for Test2 can be found at
183 \&\fIhttps://github.com/Test\-More/Test2\-Suite/\fR.
184 .SH MAINTAINERS
185 .IX Header "MAINTAINERS"
186 .IP "Chad Granum <[email protected]>" 4
187 .IX Item "Chad Granum <[email protected]>"
188 .SH AUTHORS
189 .IX Header "AUTHORS"
190 .PD 0
191 .IP "Chad Granum <[email protected]>" 4
192 .IX Item "Chad Granum <[email protected]>"
193 .PD
194 .SH COPYRIGHT
195 .IX Header "COPYRIGHT"
196 Copyright 2018 Chad Granum <[email protected]>.
197 .PP
198 This program is free software; you can redistribute it and/or
199 modify it under the same terms as Perl itself.
200 .PP
201 See \fIhttp://dev.perl.org/licenses/\fR