Debian Codegraph @

upstream/debian-unstable/man3/Test2::Manual::Tooling::Plugin::ToolStarts.3perl

raw
1 .\" -*- mode: troff; coding: utf-8 -*-
2 .\" Automatically generated by Pod::Man 5.0102 (Pod::Simple 3.45)
3 .\"
4 .\" Standard preamble:
5 .\" ========================================================================
6 .de Sp \" Vertical space (when we can't use .PP)
7 .if t .sp .5v
8 .if n .sp
9 ..
10 .de Vb \" Begin verbatim text
11 .ft CW
12 .nf
13 .ne \\$1
14 ..
15 .de Ve \" End verbatim text
16 .ft R
17 .fi
18 ..
19 .\" \*(C` and \*(C' are quotes in nroff, nothing in troff, for use with C<>.
20 .ie n \{\
21 . ds C` ""
22 . ds C' ""
23 'br\}
24 .el\{\
25 . ds C`
26 . ds C'
27 'br\}
28 .\"
29 .\" Escape single quotes in literal strings from groff's Unicode transform.
30 .ie \n(.g .ds Aq \(aq
31 .el .ds Aq '
32 .\"
33 .\" If the F register is >0, we'll generate index entries on stderr for
34 .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index
35 .\" entries marked with X<> in POD. Of course, you'll have to process the
36 .\" output yourself in some meaningful fashion.
37 .\"
38 .\" Avoid warning from groff about undefined register 'F'.
39 .de IX
40 ..
41 .nr rF 0
42 .if \n(.g .if rF .nr rF 1
43 .if (\n(rF:(\n(.g==0)) \{\
44 . if \nF \{\
45 . de IX
46 . tm Index:\\$1\t\\n%\t"\\$2"
47 ..
48 . if !\nF==2 \{\
49 . nr % 0
50 . nr F 2
51 . \}
52 . \}
53 .\}
54 .rr rF
55 .\" ========================================================================
56 .\"
57 .IX Title "Test2::Manual::Tooling::Plugin::ToolStarts 3perl"
58 .TH Test2::Manual::Tooling::Plugin::ToolStarts 3perl 2025-11-16 "perl v5.40.1" "Perl Programmers Reference Guide"
59 .\" For nroff, turn off justification. Always turn off hyphenation; it makes
60 .\" way too many mistakes in technical documents.
61 .if n .ad l
62 .nh
63 .SH NAME
64 Test2::Manual::Tooling::Plugin::ToolStarts \- How to add behaviors that occur
65 when a tool starts work.
66 .SH DESCRIPTION
67 .IX Header "DESCRIPTION"
68 This tutorial will help you write plugins that have behavior when a tool
69 starts. All tools should start by acquiring a context object. This tutorial
70 shows you the hooks you can use to take advantage of the context acquisition.
71 .SH "COMPLETE CODE UP FRONT"
72 .IX Header "COMPLETE CODE UP FRONT"
73 .Vb 1
74 \& package Test2::Plugin::MyPlugin;
75 \&
76 \& use Test2::API qw{
77 \& test2_add_callback_context_init
78 \& test2_add_callback_context_acquire
79 \& };
80 \&
81 \& sub import {
82 \& my $class = shift;
83 \&
84 \& # Let us know every time a tool requests a context, and give us a
85 \& # chance to modify the parameters before we find it.
86 \& test2_add_callback_context_acquire(sub {
87 \& my $params_ref = shift;
88 \&
89 \& print "A tool has requested the context\en";
90 \& });
91 \&
92 \& # Callback every time a new context is created, not called if an
93 \& # existing context is found.
94 \& test2_add_callback_context_init(sub {
95 \& my $ctx_ref = shift;
96 \&
97 \& print "A new context was created\en";
98 \& });
99 \& }
100 \&
101 \& 1;
102 .Ve
103 .SH "LINE BY LINE"
104 .IX Header "LINE BY LINE"
105 .IP "use Test2::API qw{test2_add_callback_context_init test2_add_callback_context_acquire};" 4
106 .IX Item "use Test2::API qw{test2_add_callback_context_init test2_add_callback_context_acquire};"
107 This imports the \f(CWtest2_add_callback_context_init()\fR and
108 \&\f(CWtest2_add_callback_context_acquire()\fR callbacks.
109 .IP "test2_add_callback_context_acquire(sub { ... })" 4
110 .IX Item "test2_add_callback_context_acquire(sub { ... })"
111 This is where we add our callback for context acquisition. Every time
112 \&\f(CWTest2::API::context()\fR is called the callback will be run.
113 .ie n .IP "my $params_ref = shift" 4
114 .el .IP "my \f(CW$params_ref\fR = shift" 4
115 .IX Item "my $params_ref = shift"
116 In the \fBtest2_add_callback_context_acquire()\fR callbacks we get exactly 1
117 argument, a reference to the parameters that \f(CWcontext()\fR will use to find the
118 context.
119 .IP "print ""A tool has requested the context\en""" 4
120 .IX Item "print ""A tool has requested the contextn"""
121 Print a notification whenever a tool asks for a context.
122 .IP "test2_add_callback_context_init(sub { ... })" 4
123 .IX Item "test2_add_callback_context_init(sub { ... })"
124 Add our context init callback. These callbacks are triggered whenever a
125 completely new context is created. This is not called if an existing context is
126 found. In short this only fires off for the top level tool, not nested tools.
127 .ie n .IP "my $ctx_ref = shift" 4
128 .el .IP "my \f(CW$ctx_ref\fR = shift" 4
129 .IX Item "my $ctx_ref = shift"
130 The coderefs for \fBtest2_add_callback_context_init()\fR will receive exactly 1
131 argument, the newly created context.
132 .IP "print ""A new context was created\en""" 4
133 .IX Item "print ""A new context was createdn"""
134 Print a notification whenever a new context is created.
135 .SH "SEE ALSO"
136 .IX Header "SEE ALSO"
137 Test2::Manual \- Primary index of the manual.
138 .SH SOURCE
139 .IX Header "SOURCE"
140 The source code repository for Test2\-Manual can be found at
141 \&\fIhttps://github.com/Test\-More/Test2\-Suite/\fR.
142 .SH MAINTAINERS
143 .IX Header "MAINTAINERS"
144 .IP "Chad Granum <[email protected]>" 4
145 .IX Item "Chad Granum <[email protected]>"
146 .SH AUTHORS
147 .IX Header "AUTHORS"
148 .PD 0
149 .IP "Chad Granum <[email protected]>" 4
150 .IX Item "Chad Granum <[email protected]>"
151 .PD
152 .SH COPYRIGHT
153 .IX Header "COPYRIGHT"
154 Copyright 2018 Chad Granum <[email protected]>.
155 .PP
156 This program is free software; you can redistribute it and/or
157 modify it under the same terms as Perl itself.
158 .PP
159 See \fIhttp://dev.perl.org/licenses/\fR