Debian Codegraph @

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