Test2::Tools::Grab(3)
β¨ NAME β¨
Okay bestie, this is the Test2::Tools::Grab(3) page from User Contributed Perl Documentation.
Test2::Tools::Grab β temporarily intercept all events without adding a scope level. Periodt. π
π¦ 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. Itβs giving βevent trap, but make it temporary.β β¨
πΈ SYNOPSIS πΈ
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;
π EXPORTS π
$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. Iykyk. π«Ά
my $grab = grab();
ok(1, 'foo');
ok(0, 'bar');
my $events = $grab->finish;
is(@$events, 2, "grabbed 2 events.");
If the $grab object is destroyed without calling finish(), it will automatically clean up after itself and restore the parent hub. No cap, it really does tidy up after itself. π§
{
my $grab = grab();
# Things are grabbed
}
# Things are back to normal
By default the hub used has no_ending 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 on like this:
$grab->hub->set_no_ending(0);
With no_ending turned off, finish 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. So likeβ¦ expect extra guests at the party. π
π SEE ALSO π
Test2::Util::Grabberβ the object constructed and returned by this tool.
π₯ SOURCE π₯
The source code repository for Test2 can be found at https://github.com/Test-More/test-more/.
π MAINTAINERS π
Chad Granum Chad Granum <exodist@cpan.org>
π AUTHORS π
Chad Granum Chad Granum <exodist@cpan.org>
π COPYRIGHT π
Copyright Chad Granum Chad Granum <exodist@cpan.org>.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
See http://dev.perl.org/licenses/
And thatβs the whole vibe: this page is from perl v5.42.0, dated 2025-07-28, and itβs the Test2::Tools::Grab(3) manual page. Bye bestie, go grab those events responsibly ππ
π¦ where this page comes from
- opensuse-leap 16.0: perl-Test-Simple 1.302214-bp160.1.2 Β· Artistic-1.0 OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms