Debian Codegraph @

upstream/mageia-cauldron/man3pm/Test2::Manual::Tooling::Plugin::ToolStarts.3pm

raw
1 .\" -*- mode: troff; coding: utf-8 -*-
2 .\" Automatically generated by Pod::Man v6.0.2 (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 .\" Required to disable full justification in groff 1.23.0.
57 .if n .ds AD l
58 .\" ========================================================================
59 .\"
60 .IX Title "Test2::Manual::Tooling::Plugin::ToolStarts 3pm"
61 .TH Test2::Manual::Tooling::Plugin::ToolStarts 3pm 2025-06-24 "perl v5.42.0" "Perl Programmers Reference Guide"
62 .\" For nroff, turn off justification. Always turn off hyphenation; it makes
63 .\" way too many mistakes in technical documents.
64 .if n .ad l
65 .nh
66 .SH NAME
67 Test2::Manual::Tooling::Plugin::ToolStarts \- How to add behaviors that occur
68 when a tool starts work.
69 .SH DESCRIPTION
70 .IX Header "DESCRIPTION"
71 This tutorial will help you write plugins that have behavior when a tool
72 starts. All tools should start by acquiring a context object. This tutorial
73 shows you the hooks you can use to take advantage of the context acquisition.
74 .SH "COMPLETE CODE UP FRONT"
75 .IX Header "COMPLETE CODE UP FRONT"
76 .Vb 1
77 \& package Test2::Plugin::MyPlugin;
78 \&
79 \& use Test2::API qw{
80 \& test2_add_callback_context_init
81 \& test2_add_callback_context_acquire
82 \& };
83 \&
84 \& sub import {
85 \& my $class = shift;
86 \&
87 \& # Let us know every time a tool requests a context, and give us a
88 \& # chance to modify the parameters before we find it.
89 \& test2_add_callback_context_acquire(sub {
90 \& my $params_ref = shift;
91 \&
92 \& print "A tool has requested the context\en";
93 \& });
94 \&
95 \& # Callback every time a new context is created, not called if an
96 \& # existing context is found.
97 \& test2_add_callback_context_init(sub {
98 \& my $ctx_ref = shift;
99 \&
100 \& print "A new context was created\en";
101 \& });
102 \& }
103 \&
104 \& 1;
105 .Ve
106 .SH "LINE BY LINE"
107 .IX Header "LINE BY LINE"
108 .IP "use Test2::API qw{test2_add_callback_context_init test2_add_callback_context_acquire};" 4
109 .IX Item "use Test2::API qw{test2_add_callback_context_init test2_add_callback_context_acquire};"
110 This imports the \f(CWtest2_add_callback_context_init()\fR and
111 \&\f(CWtest2_add_callback_context_acquire()\fR callbacks.
112 .IP "test2_add_callback_context_acquire(sub { ... })" 4
113 .IX Item "test2_add_callback_context_acquire(sub { ... })"
114 This is where we add our callback for context acquisition. Every time
115 \&\f(CWTest2::API::context()\fR is called the callback will be run.
116 .ie n .IP "my $params_ref = shift" 4
117 .el .IP "my \f(CW$params_ref\fR = shift" 4
118 .IX Item "my $params_ref = shift"
119 In the \fBtest2_add_callback_context_acquire()\fR callbacks we get exactly 1
120 argument, a reference to the parameters that \f(CWcontext()\fR will use to find the
121 context.
122 .IP "print ""A tool has requested the context\en""" 4
123 .IX Item "print ""A tool has requested the contextn"""
124 Print a notification whenever a tool asks for a context.
125 .IP "test2_add_callback_context_init(sub { ... })" 4
126 .IX Item "test2_add_callback_context_init(sub { ... })"
127 Add our context init callback. These callbacks are triggered whenever a
128 completely new context is created. This is not called if an existing context is
129 found. In short this only fires off for the top level tool, not nested tools.
130 .ie n .IP "my $ctx_ref = shift" 4
131 .el .IP "my \f(CW$ctx_ref\fR = shift" 4
132 .IX Item "my $ctx_ref = shift"
133 The coderefs for \fBtest2_add_callback_context_init()\fR will receive exactly 1
134 argument, the newly created context.
135 .IP "print ""A new context was created\en""" 4
136 .IX Item "print ""A new context was createdn"""
137 Print a notification whenever a new context is created.
138 .SH "SEE ALSO"
139 .IX Header "SEE ALSO"
140 Test2::Manual \- Primary index of the manual.
141 .SH SOURCE
142 .IX Header "SOURCE"
143 The source code repository for Test2\-Manual can be found at
144 \&\fIhttps://github.com/Test\-More/test\-more/\fR.
145 .SH MAINTAINERS
146 .IX Header "MAINTAINERS"
147 .IP "Chad Granum <[email protected]>" 4
148 .IX Item "Chad Granum <[email protected]>"
149 .SH AUTHORS
150 .IX Header "AUTHORS"
151 .IP "Chad Granum <[email protected]>" 4
152 .IX Item "Chad Granum <[email protected]>"
153 .SH COPYRIGHT
154 .IX Header "COPYRIGHT"
155 Copyright Chad Granum <[email protected]>.
156 .PP
157 This program is free software; you can redistribute it and/or
158 modify it under the same terms as Perl itself.
159 .PP
160 See \fIhttp://dev.perl.org/licenses/\fR