Profile of Test/Builder/Module.pm

← Index
NYTProf Performance Profile «line view»
For t/bug-md-11.t
Run on Fri Mar 8 13:27:24 2024
Reported on Fri Mar 8 13:30:22 2024

Filename | /home/micha/.plenv/versions/5.38.2/lib/perl5/site_perl/5.38.2/Test/Builder/Module.pm
Statements | Executed 39 statements in 317µs

Subroutines
Calls | P | F | Exclusive Time | Inclusive Time | Subroutine
--- | --- | --- | --- | --- | ---
1 | 1 | 1 | 5.89ms | 49.3ms | Test::Builder::Module::::BEGIN@5Test::Builder::Module::BEGIN@5
2 | 2 | 2 | 23µs | 631µs | Test::Builder::Module::::importTest::Builder::Module::import
1 | 1 | 1 | 10µs | 12µs | Test::Builder::Module::::BEGIN@3Test::Builder::Module::BEGIN@3
4 | 4 | 2 | 10µs | 15µs | Test::Builder::Module::::builderTest::Builder::Module::builder
1 | 1 | 1 | 7µs | 7µs | Test::Builder::Module::::_strip_importsTest::Builder::Module::_strip_imports
1 | 1 | 1 | 300ns | 300ns | Test::Builder::Module::::__ANON__Test::Builder::Module::__ANON__ (xsub)
0 | 0 | 0 | 0s | 0s | Test::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
--- | --- | --- | --- | --- | ---
1 |  |  |  |  | package Test::Builder::Module;
2 |  |  |  |  |
3 | 2 | 19µs | 2 | 13µs | # spent 12µs (10+2) within Test::Builder::Module::BEGIN@3 which was called: # once (10µs+2µs) by Test::More::BEGIN@22 at line 3 use strict; # spent 12µs making 1 call to Test::Builder::Module::BEGIN@3 # spent 2µs making 1 call to strict::import
4 |  |  |  |  |
5 | 2 | 255µs | 2 | 49.3ms | # spent 49.3ms (5.89+43.4) within Test::Builder::Module::BEGIN@5 which was called: # once (5.89ms+43.4ms) by Test::More::BEGIN@22 at line 5 use Test::Builder; # spent 49.3ms making 1 call to Test::Builder::Module::BEGIN@5 # spent 300ns making 1 call to Test::Builder::Module::__ANON__
6 |  |  |  |  |
7 | 1 | 400ns |  |  | require Exporter;
8 | 1 | 5µs |  |  | our @ISA = qw(Exporter);
9 |  |  |  |  |
10 | 1 | 200ns |  |  | our $VERSION = '1.302198';
11 |  |  |  |  |
12 |  |  |  |  |
13 |  |  |  |  | =head1 NAME
14 |  |  |  |  |
15 |  |  |  |  | Test::Builder::Module - Base class for test modules
16 |  |  |  |  |
17 |  |  |  |  | =head1 SYNOPSIS
18 |  |  |  |  |
19 |  |  |  |  | # Emulates Test::Simple
20 |  |  |  |  | package Your::Module;
21 |  |  |  |  |
22 |  |  |  |  | my $CLASS = __PACKAGE__;
23 |  |  |  |  |
24 |  |  |  |  | use parent 'Test::Builder::Module';
25 |  |  |  |  | @EXPORT = qw(ok);
26 |  |  |  |  |
27 |  |  |  |  | sub ok ($;$) {
28 |  |  |  |  | my $tb = $CLASS->builder;
29 |  |  |  |  | return $tb->ok(@_);
30 |  |  |  |  | }
31 |  |  |  |  |
32 |  |  |  |  | 1;
33 |  |  |  |  |
34 |  |  |  |  |
35 |  |  |  |  | =head1 DESCRIPTION
36 |  |  |  |  |
37 |  |  |  |  | This is a superclass for L<Test::Builder>-based modules. It provides a
38 |  |  |  |  | handful of common functionality and a method of getting at the underlying
39 |  |  |  |  | L<Test::Builder> object.
40 |  |  |  |  |
41 |  |  |  |  |
42 |  |  |  |  | =head2 Importing
43 |  |  |  |  |
44 |  |  |  |  | Test::Builder::Module is a subclass of L<Exporter> which means your
45 |  |  |  |  | module is also a subclass of Exporter. @EXPORT, @EXPORT_OK, etc...
46 |  |  |  |  | all act normally.
47 |  |  |  |  |
48 |  |  |  |  | A few methods are provided to do the C<< use Your::Module tests => 23 >> part
49 |  |  |  |  | for you.
50 |  |  |  |  |
51 |  |  |  |  | =head3 import
52 |  |  |  |  |
53 |  |  |  |  | Test::Builder::Module provides an C<import()> method which acts in the
54 |  |  |  |  | same basic way as L<Test::More>'s, setting the plan and controlling
55 |  |  |  |  | exporting of functions and variables. This allows your module to set
56 |  |  |  |  | the plan independent of L<Test::More>.
57 |  |  |  |  |
58 |  |  |  |  | All arguments passed to C<import()> are passed onto
59 |  |  |  |  | C<< Your::Module->builder->plan() >> with the exception of
60 |  |  |  |  | C<< import =>[qw(things to import)] >>.
61 |  |  |  |  |
62 |  |  |  |  | use Your::Module import => [qw(this that)], tests => 23;
63 |  |  |  |  |
64 |  |  |  |  | says to import the functions C<this()> and C<that()> as well as set the plan
65 |  |  |  |  | to be 23 tests.
66 |  |  |  |  |
67 |  |  |  |  | C<import()> also sets the C<exported_to()> attribute of your builder to be
68 |  |  |  |  | the caller of the C<import()> function.
69 |  |  |  |  |
70 |  |  |  |  | Additional behaviors can be added to your C<import()> method by overriding
71 |  |  |  |  | C<import_extra()>.
72 |  |  |  |  |
73 |  |  |  |  | =cut
74 |  |  |  |  |
75 |  |  |  |  | # spent 631µs (23+608) within Test::Builder::Module::import which was called 2 times, avg 315µs/call: # once (5µs+489µs) by Test::More::BEGIN@22 at line 22 of Test/More.pm # once (18µs+120µs) by main::BEGIN@5 at line 5 of /home/micha/Projekt/spreadsheet-parsexlsx/t/bug-md-11.t sub import {
76 | 2 | 900ns |  |  | my($class) = shift;
77 |  |  |  |  |
78 | 2 | 2µs | 4 | 496µs | Test2::API::test2_load() unless Test2::API::test2_in_preload(); # spent 486µs making 2 calls to Test2::API::test2_load, avg 243µs/call # spent 10µs making 2 calls to Test2::API::test2_in_preload, avg 5µs/call
79 |  |  |  |  |
80 |  |  |  |  | # Don't run all this when loading ourself.
81 | 2 | 2µs |  |  | return 1 if $class eq 'Test::Builder::Module';
82 |  |  |  |  |
83 | 1 | 2µs | 1 | 4µs | my $test = $class->builder; # spent 4µs making 1 call to Test::Builder::Module::builder
84 |  |  |  |  |
85 | 1 | 500ns |  |  | my $caller = caller;
86 |  |  |  |  |
87 | 1 | 800ns | 1 | 2µs | $test->exported_to($caller); # spent 2µs making 1 call to Test::Builder::exported_to
88 |  |  |  |  |
89 | 1 | 900ns | 1 | 13µs | $class->import_extra( \@_ ); # spent 13µs making 1 call to Test::More::import_extra
90 | 1 | 2µs | 1 | 7µs | my(@imports) = $class->_strip_imports( \@_ ); # spent 7µs making 1 call to Test::Builder::Module::_strip_imports
91 |  |  |  |  |
92 | 1 | 1µs | 1 | 1µs | $test->plan(@_); # spent 1µs making 1 call to Test::Builder::plan
93 |  |  |  |  |
94 | 1 | 300ns |  |  | local $Exporter::ExportLevel = $Exporter::ExportLevel + 1;
95 | 1 | 4µs | 1 | 85µs | $class->Exporter::import(@imports); # spent 85µs making 1 call to Exporter::import
96 |  |  |  |  | }
97 |  |  |  |  |
98 |  |  |  |  | # spent 7µs within Test::Builder::Module::_strip_imports which was called: # once (7µs+0s) by Test::Builder::Module::import at line 90 sub _strip_imports {
99 | 1 | 100ns |  |  | my $class = shift;
100 | 1 | 200ns |  |  | my $list = shift;
101 |  |  |  |  |
102 | 1 | 100ns |  |  | my @imports = ();
103 | 1 | 100ns |  |  | my @other = ();
104 | 1 | 200ns |  |  | my $idx = 0;
105 | 1 | 400ns |  |  | while( $idx <= $#{$list} ) {
106 | 1 | 400ns |  |  | my $item = $list->[$idx];
107 |  |  |  |  |
108 | 1 | 300ns |  |  | if( defined $item and $item eq 'import' ) {
109 | 1 | 2µs |  |  | push @imports, @{ $list->[ $idx + 1 ] };
110 | 1 | 100ns |  |  | $idx++;
111 |  |  |  |  | }
112 |  |  |  |  | else {
113 |  |  |  |  | push @other, $item;
114 |  |  |  |  | }
115 |  |  |  |  |
116 | 1 | 300ns |  |  | $idx++;
117 |  |  |  |  | }
118 |  |  |  |  |
119 | 1 | 900ns |  |  | @$list = @other;
120 |  |  |  |  |
121 | 1 | 3µs |  |  | return @imports;
122 |  |  |  |  | }
123 |  |  |  |  |
124 |  |  |  |  | =head3 import_extra
125 |  |  |  |  |
126 |  |  |  |  | Your::Module->import_extra(\@import_args);
127 |  |  |  |  |
128 |  |  |  |  | C<import_extra()> is called by C<import()>. It provides an opportunity for you
129 |  |  |  |  | to add behaviors to your module based on its import list.
130 |  |  |  |  |
131 |  |  |  |  | Any extra arguments which shouldn't be passed on to C<plan()> should be
132 |  |  |  |  | stripped off by this method.
133 |  |  |  |  |
134 |  |  |  |  | See L<Test::More> for an example of its use.
135 |  |  |  |  |
136 |  |  |  |  | B<NOTE> This mechanism is I<VERY ALPHA AND LIKELY TO CHANGE> as it
137 |  |  |  |  | feels like a bit of an ugly hack in its current form.
138 |  |  |  |  |
139 |  |  |  |  | =cut
140 |  |  |  |  |
141 |  |  |  |  | sub import_extra { }
142 |  |  |  |  |
143 |  |  |  |  | =head2 Builder
144 |  |  |  |  |
145 |  |  |  |  | Test::Builder::Module provides some methods of getting at the underlying
146 |  |  |  |  | Test::Builder object.
147 |  |  |  |  |
148 |  |  |  |  | =head3 builder
149 |  |  |  |  |
150 |  |  |  |  | my $builder = Your::Class->builder;
151 |  |  |  |  |
152 |  |  |  |  | This method returns the L<Test::Builder> object associated with Your::Class.
153 |  |  |  |  | It is not a constructor so you can call it as often as you like.
154 |  |  |  |  |
155 |  |  |  |  | This is the preferred way to get the L<Test::Builder> object. You should
156 |  |  |  |  | I<not> get it via C<< Test::Builder->new >> as was previously
157 |  |  |  |  | recommended.
158 |  |  |  |  |
159 |  |  |  |  | The object returned by C<builder()> may change at runtime so you should
160 |  |  |  |  | call C<builder()> inside each function rather than store it in a global.
161 |  |  |  |  |
162 |  |  |  |  | sub ok {
163 |  |  |  |  | my $builder = Your::Class->builder;
164 |  |  |  |  |
165 |  |  |  |  | return $builder->ok(@_);
166 |  |  |  |  | }
167 |  |  |  |  |
168 |  |  |  |  |
169 |  |  |  |  | =cut
170 |  |  |  |  |
171 |  |  |  |  | # spent 15µs (10+5) within Test::Builder::Module::builder which was called 4 times, avg 4µs/call: # once (4µs+2µs) by Test::More::ok at line 321 of Test/More.pm # once (3µs+900ns) by Test::Builder::Module::import at line 83 # once (2µs+1µs) by Test::More::done_testing at line 248 of Test/More.pm # once (1µs+600ns) by Test::More::import_extra at line 208 of Test/More.pm sub builder {
172 | 4 | 11µs | 4 | 5µs | return Test::Builder->new; # spent 5µs making 4 calls to Test::Builder::new, avg 1µs/call
173 |  |  |  |  | }
174 |  |  |  |  |
175 |  |  |  |  | =head1 SEE ALSO
176 |  |  |  |  |
177 |  |  |  |  | L<< Test2::Manual::Tooling::TestBuilder >> describes the improved
178 |  |  |  |  | options for writing testing modules provided by L<< Test2 >>.
179 |  |  |  |  |
180 |  |  |  |  | =cut
181 |  |  |  |  |
182 | 1 | 3µs |  |  | 1;
|  |  |  |  | # spent 300ns within Test::Builder::Module::__ANON__ which was called: # once (300ns+0s) by Test::Builder::Module::BEGIN@5 at line 5 sub Test::Builder::Module::__ANON__; # xsub