Test2::...lStarts(3pm)
π Test2::Manual::Tooling::Plugin::ToolStarts β NAME
Okay bestie, so this is a page from the Perl Programmers Reference Guide (yes, the whole Test2::...lStarts(3pm) situation β the title's just being dramatic and truncating itself π). Its actual name is Test2::Manual::Tooling::Plugin::ToolStarts, and it's literally a tutorial on how to add behaviors that fire off when a tool starts working. π
β¨ DESCRIPTION β¨
So here's the tea π΅: this tutorial is gonna walk you through writing plugins that do stuff the moment a tool starts. And the way that works is β every tool should kick things off by acquiring a context object. So this whole tutorial is about the hooks you can grab onto to take advantage of that context acquisition moment. It's giving "catch the vibe right at the beginning" energy. π¦
πΈ COMPLETE CODE UP FRONT πΈ
Here's the whole thing, no suspense, we're not gatekeeping:
package Test2::Plugin::MyPlugin;
use Test2::API qw{
test2_add_callback_context_init
test2_add_callback_context_acquire
};
sub import {
my $class = shift;
# Let us know every time a tool requests a context, and give us a
# chance to modify the parameters before we find it.
test2_add_callback_context_acquire(sub {
my $params_ref = shift;
print "A tool has requested the context\n";
});
# Callback every time a new context is created, not called if an
# existing context is found.
test2_add_callback_context_init(sub {
my $ctx_ref = shift;
print "A new context was created\n";
});
}
1;
π§ LINE BY LINE π§
use Test2::API qw{test2_add_callback_context_init test2_add_callback_context_acquire};β this is the import line, and it's bringing in both callbacks:test2_add_callback_context_init()andtest2_add_callback_context_acquire(). Iconic duo, no notes. πtest2_add_callback_context_acquire(sub { ... })β this is where we add our callback for context acquisition. So every single timeTest2::API::context()gets called, this callback runs. Every time. It's committed. πmy $params_ref = shiftβ inside thetest2_add_callback_context_acquire()callbacks we get exactly 1 argument: a reference to the parameters thatcontext()is gonna use to find the context. That's the whole gift. πprint "A tool has requested the context\n"β literally just prints a lil notification whenever a tool asks for a context. Lowkey a vibe check on your tools. β¨test2_add_callback_context_init(sub { ... })β here we add our context init callback. These callbacks get triggered whenever a completely new context is created. And listen β this one is not called if an existing context is found. So in short: it only fires off for the top level tool, not for nested tools. Important distinction, don't forget it. π«Άmy $ctx_ref = shiftβ the coderefs fortest2_add_callback_context_init()receive exactly 1 argument: the newly created context. That's it, that's the whole argument list. πprint "A new context was created\n"β prints a notification whenever a new context is created. Celebration print statement, honestly. π
π¦ SEE ALSO π¦
Test2::Manualβ the primary index of the manual. Start there if you're lost, bestie, it's the map. πΊοΈ
π SOURCE π
The source code repository for Test2-Manual can be found at https://github.com/Test-More/test-more/. Go star it, it's free. β
π MAINTAINERS π
- Chad Granum
<exodist@cpan.org>
π AUTHORS π
- Chad Granum
<exodist@cpan.org>
π COPYRIGHT π
Copyright 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/
π Okay so real talk, that copyright bit means it's free software under the same terms as Perl itself β keep that intact, it's not decorative.
And that's the whole page, bestie, you ate. π
β¨ This little masterpiece is from perl v5.42.3, dated 2026-11-03 β yeah, the perl version and the date are the whole footer flex. Slay, go write your plugin. π«Άπ
π¦ where this page comes from
- alpine 3.24: perl-doc 5.42.3-r0 Β· Artistic-1.0-Perl 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