Debian Codegraph @

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