.\" -*- mode: troff; coding: utf-8 -*- .\" Automatically generated by Pod::Man 5.0102 (Pod::Simple 3.45) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" \*(C` and \*(C' are quotes in nroff, nothing in troff, for use with C<>. .ie n \{\ . ds C` "" . ds C' "" 'br\} .el\{\ . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" ======================================================================== .\" .IX Title "Test2::Tools::Grab 3perl" .TH Test2::Tools::Grab 3perl 2024-09-01 "perl v5.40.0" "Perl Programmers Reference Guide" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH NAME Test2::Tools::Grab \- Temporarily intercept all events without adding a scope level. .SH DESCRIPTION .IX Header "DESCRIPTION" This package provides a function that returns an object that grabs all events. Once the object is destroyed events will once again be sent to the main hub. .SH SYNOPSIS .IX Header "SYNOPSIS" .Vb 1 \& use Test2::Tools::Grab; \& \& my $grab = grab(); \& \& # Generate some events, they are intercepted. \& ok(1, "pass"); \& ok(0, "fail"); \& \& my $events_a = $grab\->flush; \& \& # Generate some more events, they are intercepted. \& ok(1, "pass"); \& ok(0, "fail"); \& \& my $events_b = $grab\->finish; .Ve .SH EXPORTS .IX Header "EXPORTS" .ie n .IP "$grab = \fBgrab()\fR" 4 .el .IP "\f(CW$grab\fR = \fBgrab()\fR" 4 .IX Item "$grab = grab()" This lets you intercept all events for a section of code without adding anything to your call stack. This is useful for things that are sensitive to changes in the stack depth. .Sp .Vb 3 \& my $grab = grab(); \& ok(1, \*(Aqfoo\*(Aq); \& ok(0, \*(Aqbar\*(Aq); \& \& my $events = $grab\->finish; \& \& is(@$events, 2, "grabbed 2 events."); .Ve .Sp If the \f(CW$grab\fR object is destroyed without calling \f(CWfinish()\fR, it will automatically clean up after itself and restore the parent hub. .Sp .Vb 5 \& { \& my $grab = grab(); \& # Things are grabbed \& } \& # Things are back to normal .Ve .Sp By default the hub used has \f(CW\*(C`no_ending\*(C'\fR set to true. This will prevent the hub from enforcing that you issued a plan and ran at least 1 test. You can turn enforcement back one like this: .Sp .Vb 1 \& $grab\->hub\->set_no_ending(0); .Ve .Sp With \f(CW\*(C`no_ending\*(C'\fR turned off, \f(CW\*(C`finish\*(C'\fR will run the post-test checks to enforce the plan and that tests were run. In many cases this will result in additional events in your events array. .SH "SEE ALSO" .IX Header "SEE ALSO" Test2::Util::Grabber \- The object constructed and returned by this tool. .SH SOURCE .IX Header "SOURCE" The source code repository for Test2 can be found at \&\fIhttps://github.com/Test\-More/Test2\-Suite/\fR. .SH MAINTAINERS .IX Header "MAINTAINERS" .IP "Chad Granum " 4 .IX Item "Chad Granum " .SH AUTHORS .IX Header "AUTHORS" .PD 0 .IP "Chad Granum " 4 .IX Item "Chad Granum " .PD .SH COPYRIGHT .IX Header "COPYRIGHT" Copyright 2018 Chad Granum . .PP This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. .PP See \fIhttp://dev.perl.org/licenses/\fR