TEST2::MANUAL::TOOLING::PLUGIN::TOOLCOMPLETES(3pm)

πŸ’… NAME πŸ’…

Okay bestie, so this page is Test2::Manual::Tooling::Plugin::ToolCompletes β€” it's the tutorial that teaches you how to add behaviors that happen when a tool completes its work. From the Test2 manual family, no cap. πŸŽ€


✨ DESCRIPTION ✨

This tutorial helps you understand how to add behaviors that occur when a tool is done with its work. That's the whole vibe. πŸ¦‹

Every single tool has to acquire a context and then release it β€” that's just how the girlies operate. So for this tutorial, we're making use of the release hooks, the ones that get called every time a tool releases the context object. Obsessed, honestly. πŸ’–


πŸ”₯ COMPLETE CODE UP FRONT πŸ”₯

Here's the whole thing, ready to slay:

package Test2::Plugin::MyPlugin;

use Test2::API qw{test2_add_callback_context_release};

sub import {
    my $class = shift;

    test2_add_callback_context_release(sub {
        my $ctx_ref = shift;

        print "Context was released\n";
    });
}

1;

🌸 LINE BY LINE 🌸

  • use Test2::API qw{test2_add_callback_context_release}; β€” this is what imports the test2_add_callback_context_release() callback. Gotta have it, periodt. ✨
  • test2_add_callback_context_release(sub { ... }) and my $ctx_ref = shift β€” okay so the coderefs for test2_add_callback_context_release() will receive exactly 1 argument: the context that's being released. One. $ctx_ref is holding it, iykyk. 🫢
  • print "Context was released\n" β€” prints a little notification whenever the context is released. It's giving ✨observability✨, we love a heads-up. πŸ’…

πŸ‘‘ SEE ALSO πŸ‘‘

  • Test2::Manual β€” the primary index of the manual. Start there if you're lost, bestie, it's the main character.

🌈 SOURCE 🌈

The source code repository for Test2-Manual can be found at https://github.com/Test-More/test-more/. Go be nosy, it's encouraged. πŸ”₯


🧚 MAINTAINERS 🧚

Chad Granum <exodist@cpan.org>


πŸ’œ AUTHORS πŸ’œ

Chad Granum <exodist@cpan.org>


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/


Fr fr, that's the whole page β€” go forth and hook your own behaviors onto the release. πŸ’–

Okay that's a wrap, mwah! πŸŽ€ This was perl v5.42.3, dated 2026-11-03, and the page you just read is Test2::...ompletes(3pm) β€” see you in the next one, bestie! πŸ’…βœ¨πŸ¦‹

πŸ“¦ where this page comes from