2 <!DOCTYPE html PUBLIC
"-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
3 <html xmlns=
"http://www.w3.org/1999/xhtml">
5 <title>Test::Builder::Module - Base class for test modules
</title>
6 <meta http-equiv=
"content-type" content=
"text/html; charset=utf-8" />
7 <link rev=
"made" href=
"mailto:" />
10 <body style=
"background-color: white">
11 <table border=
"0" width=
"100%" cellspacing=
"0" cellpadding=
"3">
12 <tr><td class=
"block" style=
"background-color: #cccccc" valign=
"middle">
13 <big><strong><span class=
"block"> Test::Builder::Module - Base class for test modules
</span></strong></big>
17 <p><a name=
"__index__"></a></p>
22 <li><a href=
"#name">NAME
</a></li>
23 <li><a href=
"#synopsis">SYNOPSIS
</a></li>
24 <li><a href=
"#description">DESCRIPTION
</a></li>
27 <li><a href=
"#importing">Importing
</a></li>
30 <li><a href=
"#import">import
</a></li>
31 <li><a href=
"#import_extra">import_extra
</a></li>
34 <li><a href=
"#builder">Builder
</a></li>
37 <li><a href=
"#builder">builder
</a></li>
48 <h1><a name=
"name">NAME
</a></h1>
49 <p>Test::Builder::Module - Base class for test modules
</p>
53 <h1><a name=
"synopsis">SYNOPSIS
</a></h1>
55 # Emulates Test::Simple
56 package Your::Module;
</pre>
58 my $CLASS = __PACKAGE__;
</pre>
60 use base 'Test::Builder::Module';
61 @EXPORT = qw(ok);
</pre>
64 my $tb = $CLASS-
>builder;
65 return $tb-
>ok(@_);
72 <h1><a name=
"description">DESCRIPTION
</a></h1>
73 <p>This is a superclass for Test::Builder-based modules. It provides a
74 handful of common functionality and a method of getting at the underlying
75 Test::Builder object.
</p>
78 <h2><a name=
"importing">Importing
</a></h2>
79 <p>Test::Builder::Module is a subclass of Exporter which means your
80 module is also a subclass of Exporter. @EXPORT, @EXPORT_OK, etc...
82 <p>A few methods are provided to do the
<code>use Your::Module tests =
</code> 23> part
86 <h3><a name=
"import">import
</a></h3>
87 <p>Test::Builder::Module provides an
<code>import()
</code> method which acts in the
88 same basic way as Test::More's, setting the plan and controling
89 exporting of functions and variables. This allows your module to set
90 the plan independent of Test::More.
</p>
91 <p>All arguments passed to
<code>import()
</code> are passed onto
92 <code>Your::Module-
>builder-
>plan()
</code> with the exception of
93 <code>import =
</code>[qw(things to import)]
>.
</p>
95 use Your::Module import =
> [qw(this that)], tests =
> 23;
</pre>
96 <p>says to import the functions
<code>this()
</code> and
<code>that()
</code> as well as set the plan
98 <p><code>import()
</code> also sets the
<code>exported_to()
</code> attribute of your builder to be
99 the caller of the
<code>import()
</code> function.
</p>
100 <p>Additional behaviors can be added to your
<code>import()
</code> method by overriding
104 <h3><a name=
"import_extra">import_extra
</a></h3>
106 Your::Module-
>import_extra(\@import_args);
</pre>
107 <p><code>import_extra()
</code> is called by import(). It provides an opportunity for you
108 to add behaviors to your module based on its import list.
</p>
109 <p>Any extra arguments which shouldn't be passed on to
<code>plan()
</code> should be
110 stripped off by this method.
</p>
111 <p>See Test::More for an example of its use.
</p>
112 <p><strong>NOTE
</strong> This mechanism is
<em>VERY ALPHA AND LIKELY TO CHANGE
</em> as it
113 feels like a bit of an ugly hack in its current form.
</p>
116 <h2><a name=
"builder">Builder
</a></h2>
117 <p>Test::Builder::Module provides some methods of getting at the underlying
118 Test::Builder object.
</p>
121 <h3><a name=
"builder">builder
</a></h3>
123 my $builder = Your::Class-
>builder;
</pre>
124 <p>This method returns the Test::Builder object associated with Your::Class.
125 It is not a constructor so you can call it as often as you like.
</p>
126 <p>This is the preferred way to get the Test::Builder object. You should
127 <em>not
</em> get it via
<code>Test::Builder-
>new
</code> as was previously
129 <p>The object returned by
<code>builder()
</code> may change at runtime so you should
130 call
<code>builder()
</code> inside each function rather than store it in a global.
</p>
133 my $builder = Your::Class-
>builder;
</pre>
135 return $builder-
>ok(@_);
137 <table border=
"0" width=
"100%" cellspacing=
"0" cellpadding=
"3">
138 <tr><td class=
"block" style=
"background-color: #cccccc" valign=
"middle">
139 <big><strong><span class=
"block"> Test::Builder::Module - Base class for test modules
</span></strong></big>