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
46           will automatically clean up after itself and restore the parent
47           hub.
48
49               {
50                   my $grab = grab();
51                   # Things are grabbed
52               }
53               # Things are back to normal
54
55           By default the hub used has "no_ending" set to true. This will
56           prevent the hub from enforcing that you issued a plan and ran at
57           least 1 test. You can turn enforcement back one like this:
58
59               $grab->hub->set_no_ending(0);
60
61           With "no_ending" turned off, "finish" will run the post-test checks
62           to enforce the plan and that tests were run. In many cases this
63           will result in additional events in your events array.
64

SEE ALSO

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

SOURCE

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

MAINTAINERS

74       Chad Granum <exodist@cpan.org>
75

AUTHORS

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