1Test::Builder::Module(3pPme)rl Programmers Reference GuiTdeest::Builder::Module(3pm)
2
3
4

NAME

6       Test::Builder::Module - Base class for test modules
7

SYNOPSIS

9         # Emulates Test::Simple
10         package Your::Module;
11
12         my $CLASS = __PACKAGE__;
13
14         use base 'Test::Builder::Module';
15         @EXPORT = qw(ok);
16
17         sub ok ($;$) {
18             my $tb = $CLASS->builder;
19             return $tb->ok(@_);
20         }
21
22         1;
23

DESCRIPTION

25       This is a superclass for Test::Builder-based modules.  It provides a
26       handful of common functionality and a method of getting at the underly‐
27       ing Test::Builder object.
28
29       Importing
30
31       Test::Builder::Module is a subclass of Exporter which means your module
32       is also a subclass of Exporter.  @EXPORT, @EXPORT_OK, etc...  all act
33       normally.
34
35       A few methods are provided to do the "use Your::Module tests =" 23>
36       part for you.
37
38       import
39
40       Test::Builder::Module provides an import() method which acts in the
41       same basic way as Test::More's, setting the plan and controling export‐
42       ing of functions and variables.  This allows your module to set the
43       plan independent of Test::More.
44
45       All arguments passed to import() are passed onto "Your::Mod‐
46       ule->builder->plan()" with the exception of "import ="[qw(things to
47       import)]>.
48
49           use Your::Module import => [qw(this that)], tests => 23;
50
51       says to import the functions this() and that() as well as set the plan
52       to be 23 tests.
53
54       import() also sets the exported_to() attribute of your builder to be
55       the caller of the import() function.
56
57       Additional behaviors can be added to your import() method by overriding
58       import_extra().
59
60       import_extra
61
62           Your::Module->import_extra(\@import_args);
63
64       import_extra() is called by import().  It provides an opportunity for
65       you to add behaviors to your module based on its import list.
66
67       Any extra arguments which shouldn't be passed on to plan() should be
68       stripped off by this method.
69
70       See Test::More for an example of its use.
71
72       NOTE This mechanism is VERY ALPHA AND LIKELY TO CHANGE as it feels like
73       a bit of an ugly hack in its current form.
74
75       Builder
76
77       Test::Builder::Module provides some methods of getting at the underly‐
78       ing Test::Builder object.
79
80       builder
81
82         my $builder = Your::Class->builder;
83
84       This method returns the Test::Builder object associated with
85       Your::Class.  It is not a constructor so you can call it as often as
86       you like.
87
88       This is the preferred way to get the Test::Builder object.  You should
89       not get it via "Test::Builder->new" as was previously recommended.
90
91       The object returned by builder() may change at runtime so you should
92       call builder() inside each function rather than store it in a global.
93
94         sub ok {
95             my $builder = Your::Class->builder;
96
97             return $builder->ok(@_);
98         }
99
100
101
102perl v5.8.8                       2001-09-21        Test::Builder::Module(3pm)
Impressum