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