1Test2::Manual::Tooling:U:sPelrugCionn:t:rTiobToueltsSettd2a:rP:teMsra(ln3u)Daolc:u:mTeonotlaitnigo:n:Plugin::ToolStarts(3)
2
3
4
6 Test2::Manual::Tooling::Plugin::ToolStarts - How to add behaviors that
7 occur when a tool starts work.
8
10 This tutorial will help you write plugins that have behavior when a
11 tool starts. All tools should start by acquiring a context object. This
12 tutorial shows you the hooks you can use to take advantage of the
13 context acquisition.
14
16 package Test2::Plugin::MyPlugin;
17
18 use Test2::API qw{
19 test2_add_callback_context_init
20 test2_add_callback_context_acquire
21 };
22
23 sub import {
24 my $class = shift;
25
26 # Let us know every time a tool requests a context, and give us a
27 # chance to modify the parameters before we find it.
28 test2_add_callback_context_acquire(sub {
29 my $params_ref = shift;
30
31 print "A tool has requested the context\n";
32 });
33
34 # Callback every time a new context is created, not called if an
35 # existing context is found.
36 test2_add_callback_context_init(sub {
37 my $ctx_ref = shift;
38
39 print "A new context was created\n";
40 });
41 }
42
43 1;
44
46 use Test2::API qw{test2_add_callback_context_init
47 test2_add_callback_context_acquire};
48 This imports the "test2_add_callback_context_init()" and
49 "test2_add_callback_context_acquire()" callbacks.
50
51 test2_add_callback_context_acquire(sub { ... })
52 This is where we add our callback for context acquisition. Every
53 time "Test2::API::context()" is called the callback will be run.
54
55 my $params_ref = shift
56 In the test2_add_callback_context_acquire() callbacks we get
57 exactly 1 argument, a reference to the parameters that "context()"
58 will use to find the context.
59
60 print "A tool has requested the context\n"
61 Print a notification whenever a tool asks for a context.
62
63 test2_add_callback_context_init(sub { ... })
64 Add our context init callback. These callbacks are triggered
65 whenever a completely new context is created. This is not called if
66 an existing context is found. In short this only fires off for the
67 top level tool, not nested tools.
68
69 my $ctx_ref = shift
70 The coderefs for test2_add_callback_context_init() will receive
71 exactly 1 argument, the newly created context.
72
73 print "A new context was created\n"
74 Print a notification whenever a new context is created.
75
77 Test2::Manual - Primary index of the manual.
78
80 The source code repository for Test2-Manual can be found at
81 https://github.com/Test-More/Test2-Suite/.
82
84 Chad Granum <exodist@cpan.org>
85
87 Chad Granum <exodist@cpan.org>
88
90 Copyright 2018 Chad Granum <exodist@cpan.org>.
91
92 This program is free software; you can redistribute it and/or modify it
93 under the same terms as Perl itself.
94
95 See http://dev.perl.org/licenses/
96
97
98
99perl v5.30.1 T2e0s2t02-:0:1M-a3n1ual::Tooling::Plugin::ToolStarts(3)