Debian Codegraph @

upstream/mageia-cauldron/man3pm/Test2::Manual::Tooling::Plugin::TestExit.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::TestExit 3pm"
61 .TH Test2::Manual::Tooling::Plugin::TestExit 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::TestExit \- How to safely add pre\-exit
68 behaviors.
69 .SH DESCRIPTION
70 .IX Header "DESCRIPTION"
71 This describes the correct/safe way to add pre\-exit behaviors to tests via a
72 custom plugin.
73 .PP
74 The naive way to attempt this would be to add an \f(CW\*(C`END { ... }\*(C'\fR block. That can
75 work, and may not cause problems.... On the other hand there are a lot of ways
76 that can bite you. Describing all the potential problems of an END block, and
77 how it might conflict with Test2 (Which has its own END block) is beyond the
78 scope of this document.
79 .SH "COMPLETE CODE UP FRONT"
80 .IX Header "COMPLETE CODE UP FRONT"
81 .Vb 1
82 \& package Test2::Plugin::MyPlugin;
83 \&
84 \& use Test2::API qw{test2_add_callback_exit};
85 \&
86 \& sub import {
87 \& my $class = shift;
88 \&
89 \& test2_add_callback_exit(sub {
90 \& my ($ctx, $orig_code, $new_exit_code_ref) = @_;
91 \&
92 \& return if $orig_code == 42;
93 \&
94 \& $$new_exit_code_ref = 42;
95 \& });
96 \& }
97 \&
98 \& 1;
99 .Ve
100 .SH "LINE BY LINE"
101 .IX Header "LINE BY LINE"
102 .IP "use Test2::API qw{test2_add_callback_exit};" 4
103 .IX Item "use Test2::API qw{test2_add_callback_exit};"
104 This imports the \f(CW\*(C`(test2_add_callback_exit)\*(C'\fR callback.
105 .IP "test2_add_callback_exit(sub { ... });" 4
106 .IX Item "test2_add_callback_exit(sub { ... });"
107 This adds our callback to be called before exiting.
108 .ie n .IP "my ($ctx, $orig_code, $new_exit_code_ref) = @_" 4
109 .el .IP "my ($ctx, \f(CW$orig_code\fR, \f(CW$new_exit_code_ref\fR) = \f(CW@_\fR" 4
110 .IX Item "my ($ctx, $orig_code, $new_exit_code_ref) = @_"
111 The callback gets 3 arguments. First is a context object you may use. The
112 second is the original exit code of the \f(CW\*(C`END\*(C'\fR block Test2 is using. The third
113 argument is a scalar reference which you may use to get the current exit code,
114 or set a new one.
115 .ie n .IP "return if $orig_code == 42" 4
116 .el .IP "return if \f(CW$orig_code\fR == 42" 4
117 .IX Item "return if $orig_code == 42"
118 This is a short\-cut to do nothing if the original exit code was already 42.
119 .IP "$$new_exit_code_ref = 42" 4
120 .IX Item "$$new_exit_code_ref = 42"
121 This changes the exit code to 42.
122 .SH "SEE ALSO"
123 .IX Header "SEE ALSO"
124 Test2::Manual \- Primary index of the manual.
125 .SH SOURCE
126 .IX Header "SOURCE"
127 The source code repository for Test2\-Manual can be found at
128 \&\fIhttps://github.com/Test\-More/test\-more/\fR.
129 .SH MAINTAINERS
130 .IX Header "MAINTAINERS"
131 .IP "Chad Granum <[email protected]>" 4
132 .IX Item "Chad Granum <[email protected]>"
133 .SH AUTHORS
134 .IX Header "AUTHORS"
135 .IP "Chad Granum <[email protected]>" 4
136 .IX Item "Chad Granum <[email protected]>"
137 .SH COPYRIGHT
138 .IX Header "COPYRIGHT"
139 Copyright Chad Granum <[email protected]>.
140 .PP
141 This program is free software; you can redistribute it and/or
142 modify it under the same terms as Perl itself.
143 .PP
144 See \fIhttp://dev.perl.org/licenses/\fR