1Test2::Tools::Grab(3) User Contributed Perl DocumentationTest2::Tools::Grab(3)
2
3
4

NAME

6       Test2::Tools::Grab - Temporarily intercept all events without adding a
7       scope level.
8

DESCRIPTION

10       This package provides a function that returns an object that grabs all
11       events.  Once the object is destroyed events will once again be sent to
12       the main hub.
13

SYNOPSIS

15           use Test2::Tools::Grab;
16
17           my $grab = grab();
18
19           # Generate some events, they are intercepted.
20           ok(1, "pass");
21           ok(0, "fail");
22
23           my $events_a = $grab->flush;
24
25           # Generate some more events, they are intercepted.
26           ok(1, "pass");
27           ok(0, "fail");
28
29           my $events_b = $grab->finish;
30

EXPORTS

32       $grab = grab()
33           This lets you intercept all events for a section of code without
34           adding anything to your call stack. This is useful for things that
35           are sensitive to changes in the stack depth.
36
37               my $grab = grab();
38                   ok(1, 'foo');
39                   ok(0, 'bar');
40
41               my $events = $grab->finish;
42
43               is(@$events, 2, "grabbed 2 events.");
44
45           If the $grab object is destroyed without calling finish(), it will
46           automatically clean up after itself and restore the parent hub.
47
48               {
49                   my $grab = grab();
50                   # Things are grabbed
51               }
52               # Things are back to normal
53
54           By default the hub used has "no_ending" set to true. This will
55           prevent the hub from enforcing that you issued a plan and ran at
56           least 1 test. You can turn enforcement back one like this:
57
58               $grab->hub->set_no_ending(0);
59
60           With "no_ending" turned off, "finish" will run the post-test checks
61           to enforce the plan and that tests were run. In many cases this
62           will result in additional events in your events array.
63

SEE ALSO

65       Test2::Util::Grabber - The object constructed and returned by this
66       tool.
67

SOURCE

69       The source code repository for Test2 can be found at
70       https://github.com/Test-More/Test2-Suite/.
71

MAINTAINERS

73       Chad Granum <exodist@cpan.org>
74

AUTHORS

76       Chad Granum <exodist@cpan.org>
77
79       Copyright 2018 Chad Granum <exodist@cpan.org>.
80
81       This program is free software; you can redistribute it and/or modify it
82       under the same terms as Perl itself.
83
84       See http://dev.perl.org/licenses/
85
86
87
88perl v5.36.0                      2023-03-23             Test2::Tools::Grab(3)
Impressum