← Index
NYTProf Performance Profile   « line view »
For t/optimization.t
  Run on Thu Jan 8 22:47:42 2015
Reported on Thu Jan 8 22:48:05 2015

Filename/home/ss5/perl5/perlbrew/perls/tapper-perl/lib/5.16.3/Test/Builder/Module.pm
StatementsExecuted 34 statements in 1.25ms
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
1118.01ms10.4msTest::Builder::Module::::BEGIN@5Test::Builder::Module::BEGIN@5
22248µs1.90msTest::Builder::Module::::importTest::Builder::Module::import
54234µs47µsTest::Builder::Module::::builderTest::Builder::Module::builder
11113µs28µsTest::Builder::Module::::BEGIN@3Test::Builder::Module::BEGIN@3
1114µs4µsTest::Builder::Module::::_strip_importsTest::Builder::Module::_strip_imports
0000s0sTest::Builder::Module::::import_extraTest::Builder::Module::import_extra
Call graph for these subroutines as a Graphviz dot language file.
Line State
ments
Time
on line
Calls Time
in subs
Code
1package Test::Builder::Module;
2
3230µs243µs
# spent 28µs (13+15) within Test::Builder::Module::BEGIN@3 which was called: # once (13µs+15µs) by Test::More::BEGIN@23 at line 3
use strict;
# spent 28µs making 1 call to Test::Builder::Module::BEGIN@3 # spent 15µs making 1 call to strict::import
4
53501µs210.4ms
# spent 10.4ms (8.01+2.38) within Test::Builder::Module::BEGIN@5 which was called: # once (8.01ms+2.38ms) by Test::More::BEGIN@23 at line 5
use Test::Builder 0.99;
# spent 10.4ms making 1 call to Test::Builder::Module::BEGIN@5 # spent 21µs making 1 call to UNIVERSAL::VERSION
6
71618µsrequire Exporter;
818µsour @ISA = qw(Exporter);
9
101400nsour $VERSION = '1.001002';
11116µs$VERSION = eval $VERSION; ## no critic (BuiltinFunctions::ProhibitStringyEval)
# spent 2µs executing statements in string eval
12
13
14=head1 NAME
15
16Test::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
38This is a superclass for Test::Builder-based modules. It provides a
39handful of common functionality and a method of getting at the underlying
40Test::Builder object.
41
42
43=head2 Importing
44
45Test::Builder::Module is a subclass of Exporter which means your
46module is also a subclass of Exporter. @EXPORT, @EXPORT_OK, etc...
47all act normally.
48
49A few methods are provided to do the C<use Your::Module tests => 23> part
50for you.
51
52=head3 import
53
54Test::Builder::Module provides an import() method which acts in the
55same basic way as Test::More's, setting the plan and controlling
56exporting of functions and variables. This allows your module to set
57the plan independent of Test::More.
58
59All arguments passed to import() are passed onto
60C<< Your::Module->builder->plan() >> with the exception of
61C<< import =>[qw(things to import)] >>.
62
63 use Your::Module import => [qw(this that)], tests => 23;
64
65says to import the functions this() and that() as well as set the plan
66to be 23 tests.
67
68import() also sets the exported_to() attribute of your builder to be
69the caller of the import() function.
70
71Additional behaviors can be added to your import() method by overriding
72import_extra().
73
74=cut
75
76
# spent 1.90ms (48µs+1.85) within Test::Builder::Module::import which was called 2 times, avg 951µs/call: # once (45µs+1.85ms) by main::BEGIN@6 at line 6 of t/optimization.t # once (3µs+0s) by Test::More::BEGIN@23 at line 23 of Test/More.pm
sub import {
7722µs my($class) = shift;
78
79 # Don't run all this when loading ourself.
8026µs return 1 if $class eq 'Test::Builder::Module';
81
8214µs110µs my $test = $class->builder;
# spent 10µs making 1 call to Test::Builder::Module::builder
83
8411µs my $caller = caller;
85
8613µs15µs $test->exported_to($caller);
# spent 5µs making 1 call to Test::Builder::exported_to
87
8813µs14µs $class->import_extra( \@_ );
# spent 4µs making 1 call to Test::More::import_extra
8915µs14µs my(@imports) = $class->_strip_imports( \@_ );
# spent 4µs making 1 call to Test::Builder::Module::_strip_imports
90
9112µs13µs $test->plan(@_);
# spent 3µs making 1 call to Test::Builder::plan
92
9318µs11.60ms $class->export_to_level( 1, $class, @imports );
# spent 1.60ms making 1 call to Exporter::export_to_level
94}
95
96
# spent 4µs within Test::Builder::Module::_strip_imports which was called: # once (4µs+0s) by Test::Builder::Module::import at line 89
sub _strip_imports {
971500ns my $class = shift;
981200ns my $list = shift;
99
1001400ns my @imports = ();
1011200ns my @other = ();
1021200ns my $idx = 0;
1031600ns 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
1171400ns @$list = @other;
118
11914µs return @imports;
120}
121
122=head3 import_extra
123
124 Your::Module->import_extra(\@import_args);
125
126import_extra() is called by import(). It provides an opportunity for you
127to add behaviors to your module based on its import list.
128
129Any extra arguments which shouldn't be passed on to plan() should be
130stripped off by this method.
131
132See Test::More for an example of its use.
133
134B<NOTE> This mechanism is I<VERY ALPHA AND LIKELY TO CHANGE> as it
135feels like a bit of an ugly hack in its current form.
136
137=cut
138
139sub import_extra { }
140
141=head2 Builder
142
143Test::Builder::Module provides some methods of getting at the underlying
144Test::Builder object.
145
146=head3 builder
147
148 my $builder = Your::Class->builder;
149
150This method returns the Test::Builder object associated with Your::Class.
151It is not a constructor so you can call it as often as you like.
152
153This is the preferred way to get the Test::Builder object. You should
154I<not> get it via C<< Test::Builder->new >> as was previously
155recommended.
156
157The object returned by builder() may change at runtime so you should
158call 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 47µs (34+13) within Test::Builder::Module::builder which was called 5 times, avg 9µs/call: # 2 times (11µs+5µs) by Test::More::is at line 374 of Test/More.pm, avg 8µs/call # once (8µs+3µs) by Test::More::plan at line 166 of Test/More.pm # once (8µs+2µs) by Test::Builder::Module::import at line 82 # once (7µs+2µs) by Test::More::use_ok at line 940 of Test/More.pm
sub builder {
170534µs513µs return Test::Builder->new;
# spent 13µs making 5 calls to Test::Builder::new, avg 3µs/call
171}
172
17313µs1;