Debian Codegraph @

upstream/debian-unstable/man3/Test2::Tools::Grab.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::Tools::Grab 3perl"
58 .TH Test2::Tools::Grab 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::Tools::Grab \- Temporarily intercept all events without adding a scope
65 level.
66 .SH DESCRIPTION
67 .IX Header "DESCRIPTION"
68 This package provides a function that returns an object that grabs all events.
69 Once the object is destroyed events will once again be sent to the main hub.
70 .SH SYNOPSIS
71 .IX Header "SYNOPSIS"
72 .Vb 1
73 \& use Test2::Tools::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 \& my $events_b = $grab\->finish;
88 .Ve
89 .SH EXPORTS
90 .IX Header "EXPORTS"
91 .ie n .IP "$grab = \fBgrab()\fR" 4
92 .el .IP "\f(CW$grab\fR = \fBgrab()\fR" 4
93 .IX Item "$grab = grab()"
94 This lets you intercept all events for a section of code without adding
95 anything to your call stack. This is useful for things that are sensitive to
96 changes in the stack depth.
97 .Sp
98 .Vb 3
99 \& my $grab = grab();
100 \& ok(1, \*(Aqfoo\*(Aq);
101 \& ok(0, \*(Aqbar\*(Aq);
102 \&
103 \& my $events = $grab\->finish;
104 \&
105 \& is(@$events, 2, "grabbed 2 events.");
106 .Ve
107 .Sp
108 If the \f(CW$grab\fR object is destroyed without calling \f(CWfinish()\fR, it will
109 automatically clean up after itself and restore the parent hub.
110 .Sp
111 .Vb 5
112 \& {
113 \& my $grab = grab();
114 \& # Things are grabbed
115 \& }
116 \& # Things are back to normal
117 .Ve
118 .Sp
119 By default the hub used has \f(CW\*(C`no_ending\*(C'\fR set to true. This will prevent the hub
120 from enforcing that you issued a plan and ran at least 1 test. You can turn
121 enforcement back one like this:
122 .Sp
123 .Vb 1
124 \& $grab\->hub\->set_no_ending(0);
125 .Ve
126 .Sp
127 With \f(CW\*(C`no_ending\*(C'\fR turned off, \f(CW\*(C`finish\*(C'\fR will run the post-test checks to
128 enforce the plan and that tests were run. In many cases this will result in
129 additional events in your events array.
130 .SH "SEE ALSO"
131 .IX Header "SEE ALSO"
132 Test2::Util::Grabber \- The object constructed and returned by this tool.
133 .SH SOURCE
134 .IX Header "SOURCE"
135 The source code repository for Test2 can be found at
136 \&\fIhttps://github.com/Test\-More/Test2\-Suite/\fR.
137 .SH MAINTAINERS
138 .IX Header "MAINTAINERS"
139 .IP "Chad Granum <[email protected]>" 4
140 .IX Item "Chad Granum <[email protected]>"
141 .SH AUTHORS
142 .IX Header "AUTHORS"
143 .PD 0
144 .IP "Chad Granum <[email protected]>" 4
145 .IX Item "Chad Granum <[email protected]>"
146 .PD
147 .SH COPYRIGHT
148 .IX Header "COPYRIGHT"
149 Copyright 2018 Chad Granum <[email protected]>.
150 .PP
151 This program is free software; you can redistribute it and/or
152 modify it under the same terms as Perl itself.
153 .PP
154 See \fIhttp://dev.perl.org/licenses/\fR