Debian Codegraph @

upstream/debian-unstable/man3/Test::Builder::Module.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 "Test::Builder::Module 3perl"
58 .TH Test::Builder::Module 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 Test::Builder::Module \- Base class for test modules
65 .SH SYNOPSIS
66 .IX Header "SYNOPSIS"
67 .Vb 2
68 \& # Emulates Test::Simple
69 \& package Your::Module;
70 \&
71 \& my $CLASS = _\|_PACKAGE_\|_;
72 \&
73 \& use parent \*(AqTest::Builder::Module\*(Aq;
74 \& @EXPORT = qw(ok);
75 \&
76 \& sub ok ($;$) {
77 \& my $tb = $CLASS\->builder;
78 \& return $tb\->ok(@_);
79 \& }
80 \&
81 \& 1;
82 .Ve
83 .SH DESCRIPTION
84 .IX Header "DESCRIPTION"
85 This is a superclass for Test::Builder\-based modules. It provides a
86 handful of common functionality and a method of getting at the underlying
87 Test::Builder object.
88 .SS Importing
89 .IX Subsection "Importing"
90 Test::Builder::Module is a subclass of Exporter which means your
91 module is also a subclass of Exporter. \f(CW@EXPORT\fR, \f(CW@EXPORT_OK\fR, etc...
92 all act normally.
93 .PP
94 A few methods are provided to do the \f(CW\*(C`use Your::Module tests => 23\*(C'\fR part
95 for you.
96 .PP
97 \fIimport\fR
98 .IX Subsection "import"
99 .PP
100 Test::Builder::Module provides an \f(CWimport()\fR method which acts in the
101 same basic way as Test::More's, setting the plan and controlling
102 exporting of functions and variables. This allows your module to set
103 the plan independent of Test::More.
104 .PP
105 All arguments passed to \f(CWimport()\fR are passed onto
106 \&\f(CW\*(C`Your::Module\->builder\->plan()\*(C'\fR with the exception of
107 \&\f(CW\*(C`import =>[qw(things to import)]\*(C'\fR.
108 .PP
109 .Vb 1
110 \& use Your::Module import => [qw(this that)], tests => 23;
111 .Ve
112 .PP
113 says to import the functions \f(CWthis()\fR and \f(CWthat()\fR as well as set the plan
114 to be 23 tests.
115 .PP
116 \&\f(CWimport()\fR also sets the \f(CWexported_to()\fR attribute of your builder to be
117 the caller of the \f(CWimport()\fR function.
118 .PP
119 Additional behaviors can be added to your \f(CWimport()\fR method by overriding
120 \&\f(CWimport_extra()\fR.
121 .PP
122 \fIimport_extra\fR
123 .IX Subsection "import_extra"
124 .PP
125 .Vb 1
126 \& Your::Module\->import_extra(\e@import_args);
127 .Ve
128 .PP
129 \&\f(CWimport_extra()\fR is called by \f(CWimport()\fR. It provides an opportunity for you
130 to add behaviors to your module based on its import list.
131 .PP
132 Any extra arguments which shouldn't be passed on to \f(CWplan()\fR should be
133 stripped off by this method.
134 .PP
135 See Test::More for an example of its use.
136 .PP
137 \&\fBNOTE\fR This mechanism is \fIVERY ALPHA AND LIKELY TO CHANGE\fR as it
138 feels like a bit of an ugly hack in its current form.
139 .SS Builder
140 .IX Subsection "Builder"
141 Test::Builder::Module provides some methods of getting at the underlying
142 Test::Builder object.
143 .PP
144 \fIbuilder\fR
145 .IX Subsection "builder"
146 .PP
147 .Vb 1
148 \& my $builder = Your::Class\->builder;
149 .Ve
150 .PP
151 This method returns the Test::Builder object associated with Your::Class.
152 It is not a constructor so you can call it as often as you like.
153 .PP
154 This is the preferred way to get the Test::Builder object. You should
155 \&\fInot\fR get it via \f(CW\*(C`Test::Builder\->new\*(C'\fR as was previously
156 recommended.
157 .PP
158 The object returned by \f(CWbuilder()\fR may change at runtime so you should
159 call \f(CWbuilder()\fR inside each function rather than store it in a global.
160 .PP
161 .Vb 2
162 \& sub ok {
163 \& my $builder = Your::Class\->builder;
164 \&
165 \& return $builder\->ok(@_);
166 \& }
167 .Ve
168 .SH "SEE ALSO"
169 .IX Header "SEE ALSO"
170 Test2::Manual::Tooling::TestBuilder describes the improved
171 options for writing testing modules provided by Test2.