Filename | /home/ss5/perl5/perlbrew/perls/perl-5.14.1/lib/5.14.1/Test/Builder/Module.pm |
Statements | Executed 33 statements in 2.31ms |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
1 | 1 | 1 | 33.6ms | 42.5ms | BEGIN@5 | Test::Builder::Module::
5 | 4 | 2 | 267µs | 415µs | builder | Test::Builder::Module::
2 | 2 | 2 | 186µs | 8.04ms | import | Test::Builder::Module::
1 | 1 | 1 | 52µs | 64µs | BEGIN@3 | Test::Builder::Module::
1 | 1 | 1 | 20µs | 20µs | _strip_imports | Test::Builder::Module::
0 | 0 | 0 | 0s | 0s | import_extra | Test::Builder::Module::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | package Test::Builder::Module; | ||||
2 | |||||
3 | 2 | 98µs | 2 | 76µs | # spent 64µs (52+12) within Test::Builder::Module::BEGIN@3 which was called:
# once (52µs+12µs) by Test::More::BEGIN@23 at line 3 # spent 64µs making 1 call to Test::Builder::Module::BEGIN@3
# spent 12µs making 1 call to strict::import |
4 | |||||
5 | 2 | 1.73ms | 1 | 42.5ms | # spent 42.5ms (33.6+8.82) within Test::Builder::Module::BEGIN@5 which was called:
# once (33.6ms+8.82ms) by Test::More::BEGIN@23 at line 5 # spent 42.5ms making 1 call to Test::Builder::Module::BEGIN@5 |
6 | |||||
7 | 1 | 2µs | require Exporter; | ||
8 | 1 | 28µs | our @ISA = qw(Exporter); | ||
9 | |||||
10 | 1 | 2µs | our $VERSION = '0.98'; | ||
11 | 1 | 62µs | $VERSION = eval $VERSION; ## no critic (BuiltinFunctions::ProhibitStringyEval) # spent 8µs executing statements in string eval | ||
12 | |||||
13 | |||||
14 | =head1 NAME | ||||
15 | |||||
16 | Test::Builder::Module - Base class for test modules | ||||
17 | |||||
18 | =head1 SYNOPSIS | ||||
19 | |||||
20 | # Emulates Test::Simple | ||||
21 | package Your::Module; | ||||
22 | |||||
23 | my $CLASS = __PACKAGE__; | ||||
24 | |||||
25 | use base 'Test::Builder::Module'; | ||||
26 | @EXPORT = qw(ok); | ||||
27 | |||||
28 | sub ok ($;$) { | ||||
29 | my $tb = $CLASS->builder; | ||||
30 | return $tb->ok(@_); | ||||
31 | } | ||||
32 | |||||
33 | 1; | ||||
34 | |||||
35 | |||||
36 | =head1 DESCRIPTION | ||||
37 | |||||
38 | This is a superclass for Test::Builder-based modules. It provides a | ||||
39 | handful of common functionality and a method of getting at the underlying | ||||
40 | Test::Builder object. | ||||
41 | |||||
42 | |||||
43 | =head2 Importing | ||||
44 | |||||
45 | Test::Builder::Module is a subclass of Exporter which means your | ||||
46 | module is also a subclass of Exporter. @EXPORT, @EXPORT_OK, etc... | ||||
47 | all act normally. | ||||
48 | |||||
49 | A few methods are provided to do the C<use Your::Module tests => 23> part | ||||
50 | for you. | ||||
51 | |||||
52 | =head3 import | ||||
53 | |||||
54 | Test::Builder::Module provides an import() method which acts in the | ||||
55 | same basic way as Test::More's, setting the plan and controlling | ||||
56 | exporting of functions and variables. This allows your module to set | ||||
57 | the plan independent of Test::More. | ||||
58 | |||||
59 | All arguments passed to import() are passed onto | ||||
60 | C<< Your::Module->builder->plan() >> with the exception of | ||||
61 | C<< import =>[qw(things to import)] >>. | ||||
62 | |||||
63 | use Your::Module import => [qw(this that)], tests => 23; | ||||
64 | |||||
65 | says to import the functions this() and that() as well as set the plan | ||||
66 | to be 23 tests. | ||||
67 | |||||
68 | import() also sets the exported_to() attribute of your builder to be | ||||
69 | the caller of the import() function. | ||||
70 | |||||
71 | Additional behaviors can be added to your import() method by overriding | ||||
72 | import_extra(). | ||||
73 | |||||
74 | =cut | ||||
75 | |||||
76 | # spent 8.04ms (186µs+7.86) within Test::Builder::Module::import which was called 2 times, avg 4.02ms/call:
# once (170µs+7.86ms) by main::BEGIN@7 at line 7 of t/app_dpath.t
# once (16µs+0s) by Test::More::BEGIN@23 at line 23 of Test/More.pm | ||||
77 | 11 | 130µs | my($class) = shift; | ||
78 | |||||
79 | # Don't run all this when loading ourself. | ||||
80 | return 1 if $class eq 'Test::Builder::Module'; | ||||
81 | |||||
82 | 1 | 41µs | my $test = $class->builder; # spent 41µs making 1 call to Test::Builder::Module::builder | ||
83 | |||||
84 | my $caller = caller; | ||||
85 | |||||
86 | 1 | 17µs | $test->exported_to($caller); # spent 17µs making 1 call to Test::Builder::exported_to | ||
87 | |||||
88 | 1 | 20µs | $class->import_extra( \@_ ); # spent 20µs making 1 call to Test::More::import_extra | ||
89 | 1 | 20µs | my(@imports) = $class->_strip_imports( \@_ ); # spent 20µs making 1 call to Test::Builder::Module::_strip_imports | ||
90 | |||||
91 | 1 | 9µs | $test->plan(@_); # spent 9µs making 1 call to Test::Builder::plan | ||
92 | |||||
93 | 1 | 6.83ms | $class->export_to_level( 1, $class, @imports ); # spent 6.83ms making 1 call to Exporter::export_to_level | ||
94 | } | ||||
95 | |||||
96 | # spent 20µs within Test::Builder::Module::_strip_imports which was called:
# once (20µs+0s) by Test::Builder::Module::import at line 89 | ||||
97 | 8 | 28µs | my $class = shift; | ||
98 | my $list = shift; | ||||
99 | |||||
100 | my @imports = (); | ||||
101 | my @other = (); | ||||
102 | my $idx = 0; | ||||
103 | while( $idx <= $#{$list} ) { | ||||
104 | my $item = $list->[$idx]; | ||||
105 | |||||
106 | if( defined $item and $item eq 'import' ) { | ||||
107 | push @imports, @{ $list->[ $idx + 1 ] }; | ||||
108 | $idx++; | ||||
109 | } | ||||
110 | else { | ||||
111 | push @other, $item; | ||||
112 | } | ||||
113 | |||||
114 | $idx++; | ||||
115 | } | ||||
116 | |||||
117 | @$list = @other; | ||||
118 | |||||
119 | return @imports; | ||||
120 | } | ||||
121 | |||||
122 | =head3 import_extra | ||||
123 | |||||
124 | Your::Module->import_extra(\@import_args); | ||||
125 | |||||
126 | import_extra() is called by import(). It provides an opportunity for you | ||||
127 | to add behaviors to your module based on its import list. | ||||
128 | |||||
129 | Any extra arguments which shouldn't be passed on to plan() should be | ||||
130 | stripped off by this method. | ||||
131 | |||||
132 | See Test::More for an example of its use. | ||||
133 | |||||
134 | B<NOTE> This mechanism is I<VERY ALPHA AND LIKELY TO CHANGE> as it | ||||
135 | feels like a bit of an ugly hack in its current form. | ||||
136 | |||||
137 | =cut | ||||
138 | |||||
139 | sub import_extra { } | ||||
140 | |||||
141 | =head2 Builder | ||||
142 | |||||
143 | Test::Builder::Module provides some methods of getting at the underlying | ||||
144 | Test::Builder object. | ||||
145 | |||||
146 | =head3 builder | ||||
147 | |||||
148 | my $builder = Your::Class->builder; | ||||
149 | |||||
150 | This method returns the Test::Builder object associated with Your::Class. | ||||
151 | It is not a constructor so you can call it as often as you like. | ||||
152 | |||||
153 | This is the preferred way to get the Test::Builder object. You should | ||||
154 | I<not> get it via C<< Test::Builder->new >> as was previously | ||||
155 | recommended. | ||||
156 | |||||
157 | The object returned by builder() may change at runtime so you should | ||||
158 | call builder() inside each function rather than store it in a global. | ||||
159 | |||||
160 | sub ok { | ||||
161 | my $builder = Your::Class->builder; | ||||
162 | |||||
163 | return $builder->ok(@_); | ||||
164 | } | ||||
165 | |||||
166 | |||||
167 | =cut | ||||
168 | |||||
169 | # spent 415µs (267+148) within Test::Builder::Module::builder which was called 5 times, avg 83µs/call:
# 2 times (143µs+106µs) by Test::More::isnt at line 381 of Test/More.pm, avg 125µs/call
# once (77µs+21µs) by Test::More::diag at line 1142 of Test/More.pm
# once (29µs+12µs) by Test::Builder::Module::import at line 82
# once (18µs+9µs) by Test::More::done_testing at line 220 of Test/More.pm | ||||
170 | 5 | 215µs | 5 | 148µs | return Test::Builder->new; # spent 148µs making 5 calls to Test::Builder::new, avg 30µs/call |
171 | } | ||||
172 | |||||
173 | 1 | 13µs | 1; |