← Index
NYTProf Performance Profile   « line view »
For flows_to_es.pl
  Run on Mon May 9 23:27:59 2016
Reported on Mon May 9 23:28:08 2016

Filename/usr/share/perl5/Module/Runtime.pm
StatementsExecuted 1386 statements in 13.1ms
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
403223.1ms149msModule::Runtime::::require_moduleModule::Runtime::require_module (recurses: max depth 2, inclusive time 74.8ms)
130315.58ms7.18msModule::Runtime::::check_module_nameModule::Runtime::check_module_name
13011942µs1.60msModule::Runtime::::is_module_nameModule::Runtime::is_module_name
9432536µs2.22msModule::Runtime::::module_notional_filenameModule::Runtime::module_notional_filename
14431389µs389µsModule::Runtime::::CORE:matchModule::Runtime::CORE:match (opcode)
2911310µs68.0msModule::Runtime::::use_package_optimisticallyModule::Runtime::use_package_optimistically (recurses: max depth 1, inclusive time 7.47ms)
10831263µs263µsModule::Runtime::::CORE:substModule::Runtime::CORE:subst (opcode)
13721259µs259µsModule::Runtime::::_is_stringModule::Runtime::_is_string
14641170µs170µsModule::Runtime::::CORE:regcompModule::Runtime::CORE:regcomp (opcode)
711100µs5.76msModule::Runtime::::compose_module_nameModule::Runtime::compose_module_name
71179µs192µsModule::Runtime::::is_module_specModule::Runtime::is_module_spec
44477µs82µsModule::Runtime::::importModule::Runtime::import
91155µs146msModule::Runtime::::use_moduleModule::Runtime::use_module
71122µs213µsModule::Runtime::::check_module_specModule::Runtime::check_module_spec
137121µs21µsModule::Runtime::::CORE:qrModule::Runtime::CORE:qr (opcode)
11116µs16µsModule::Runtime::::BEGIN@116Module::Runtime::BEGIN@116
1118µs8µsModule::Runtime::::BEGIN@289Module::Runtime::BEGIN@289
1114µs4µsModule::Runtime::::BEGIN@120Module::Runtime::BEGIN@120
1114µs4µsModule::Runtime::::BEGIN@296Module::Runtime::BEGIN@296
Call graph for these subroutines as a Graphviz dot language file.
Line State
ments
Time
on line
Calls Time
in subs
Code
1=head1 NAME
2
3Module::Runtime - runtime module handling
4
5=head1 SYNOPSIS
6
7 use Module::Runtime qw(
8 $module_name_rx is_module_name check_module_name
9 module_notional_filename require_module
10 );
11
12 if($module_name =~ /\A$module_name_rx\z/o) { ...
13 if(is_module_name($module_name)) { ...
14 check_module_name($module_name);
15
16 $notional_filename = module_notional_filename($module_name);
17 require_module($module_name);
18
19 use Module::Runtime qw(use_module use_package_optimistically);
20
21 $bi = use_module("Math::BigInt", 1.31)->new("1_234");
22 $widget = use_package_optimistically("Local::Widget")->new;
23
24 use Module::Runtime qw(
25 $top_module_spec_rx $sub_module_spec_rx
26 is_module_spec check_module_spec
27 compose_module_name
28 );
29
30 if($spec =~ /\A$top_module_spec_rx\z/o) { ...
31 if($spec =~ /\A$sub_module_spec_rx\z/o) { ...
32 if(is_module_spec("Standard::Prefix", $spec)) { ...
33 check_module_spec("Standard::Prefix", $spec);
34
35 $module_name =
36 compose_module_name("Standard::Prefix", $spec);
37
38=head1 DESCRIPTION
39
40The functions exported by this module deal with runtime handling of
41Perl modules, which are normally handled at compile time. This module
42avoids using any other modules, so that it can be used in low-level
43infrastructure.
44
45The parts of this module that work with module names apply the same
46syntax that is used for barewords in Perl source. In principle this
47syntax can vary between versions of Perl, and this module applies the
48syntax of the Perl on which it is running. In practice the usable syntax
49hasn't changed yet, but there's a good chance of it changing in Perl 5.18.
50
51The functions of this module whose purpose is to load modules include
52workarounds for three old Perl core bugs regarding C<require>. These
53workarounds are applied on any Perl version where the bugs exist, except
54for a case where one of the bugs cannot be adequately worked around in
55pure Perl.
56
57=head2 Module name syntax
58
59The usable module name syntax has not changed from Perl 5.000 up to
60Perl 5.15.7. The syntax is composed entirely of ASCII characters.
61From Perl 5.6 onwards there has been some attempt to allow the use of
62non-ASCII Unicode characters in Perl source, but it was fundamentally
63broken (like the entirety of Perl 5.6's Unicode handling) and remained
64pretty much entirely unusable until it got some attention in the Perl
655.15 series. Although Unicode is now consistently accepted by the
66parser in some places, it remains broken for module names. Furthermore,
67there has not yet been any work on how to map Unicode module names into
68filenames, so in that respect also Unicode module names are unusable.
69This may finally be addressed in the Perl 5.17 series.
70
71The module name syntax is, precisely: the string must consist of one or
72more segments separated by C<::>; each segment must consist of one or more
73identifier characters (ASCII alphanumerics plus "_"); the first character
74of the string must not be a digit. Thus "C<IO::File>", "C<warnings>",
75and "C<foo::123::x_0>" are all valid module names, whereas "C<IO::>"
76and "C<1foo::bar>" are not. C<'> separators are not permitted by this
77module, though they remain usable in Perl source, being translated to
78C<::> in the parser.
79
80=head2 Core bugs worked around
81
82The first bug worked around is core bug [perl #68590], which causes
83lexical state in one file to leak into another that is C<require>d/C<use>d
84from it. This bug is present from Perl 5.6 up to Perl 5.10, and is
85fixed in Perl 5.11.0. From Perl 5.9.4 up to Perl 5.10.0 no satisfactory
86workaround is possible in pure Perl. The workaround means that modules
87loaded via this module don't suffer this pollution of their lexical
88state. Modules loaded in other ways, or via this module on the Perl
89versions where the pure Perl workaround is impossible, remain vulnerable.
90The module L<Lexical::SealRequireHints> provides a complete workaround
91for this bug.
92
93The second bug worked around causes some kinds of failure in module
94loading, principally compilation errors in the loaded module, to be
95recorded in C<%INC> as if they were successful, so later attempts to load
96the same module immediately indicate success. This bug is present up
97to Perl 5.8.9, and is fixed in Perl 5.9.0. The workaround means that a
98compilation error in a module loaded via this module won't be cached as
99a success. Modules loaded in other ways remain liable to produce bogus
100C<%INC> entries, and if a bogus entry exists then it will mislead this
101module if it is used to re-attempt loading.
102
103The third bug worked around causes the wrong context to be seen at
104file scope of a loaded module, if C<require> is invoked in a location
105that inherits context from a higher scope. This bug is present up to
106Perl 5.11.2, and is fixed in Perl 5.11.3. The workaround means that
107a module loaded via this module will always see the correct context.
108Modules loaded in other ways remain vulnerable.
109
110=cut
111
112package Module::Runtime;
113
114# Don't "use 5.006" here, because Perl 5.15.6 will load feature.pm if
115# the version check is done that way.
116142µs116µs
# spent 16µs within Module::Runtime::BEGIN@116 which was called: # once (16µs+0s) by Moo::_Utils::BEGIN@12 at line 116
BEGIN { require 5.006; }
# spent 16µs making 1 call to Module::Runtime::BEGIN@116
117# Don't "use warnings" here, to avoid dependencies. Do standardise the
118# warning status by lexical override; unfortunately the only safe bitset
119# to build in is the empty set, equivalent to "no warnings".
1201729µs14µs
# spent 4µs within Module::Runtime::BEGIN@120 which was called: # once (4µs+0s) by Moo::_Utils::BEGIN@12 at line 120
BEGIN { ${^WARNING_BITS} = ""; }
# spent 4µs making 1 call to Module::Runtime::BEGIN@120
121# Don't "use strict" here, to avoid dependencies.
122
1231800nsour $VERSION = "0.013";
124
125# Don't use Exporter here, to avoid dependencies.
12612µsour @EXPORT_OK = qw(
127 $module_name_rx is_module_name is_valid_module_name check_module_name
128 module_notional_filename require_module
129 use_module use_package_optimistically
130 $top_module_spec_rx $sub_module_spec_rx
131 is_module_spec is_valid_module_spec check_module_spec
132 compose_module_name
133);
134111µsmy %export_ok = map { ($_ => undef) } @EXPORT_OK;
135
# spent 82µs (77+5) within Module::Runtime::import which was called 4 times, avg 21µs/call: # once (22µs+1µs) by Search::Elasticsearch::Util::BEGIN@6 at line 6 of /opt/flows/lib/lib/perl5/Search/Elasticsearch/Util.pm # once (22µs+1µs) by Moo::_Utils::BEGIN@12 at line 12 of Moo/_Utils.pm # once (20µs+2µs) by Method::Generate::Accessor::BEGIN@10 at line 10 of Method/Generate/Accessor.pm # once (13µs+900ns) by Module::Implementation::BEGIN@12 at line 12 of Module/Implementation.pm
sub import {
13642µs my $me = shift;
13743µs my $callpkg = caller(0);
13841µs my $errs = "";
13945µs foreach(@_) {
14079µs if(exists $export_ok{$_}) {
141 # We would need to do "no strict 'refs'" here
142 # if we had enabled strict at file scope.
143726µs75µs if(/\A\$(.*)\z/s) {
# spent 5µs making 7 calls to Module::Runtime::CORE:match, avg 743ns/call
144 *{$callpkg."::".$1} = \$$1;
145 } else {
146728µs *{$callpkg."::".$_} = \&$_;
147 }
148 } else {
149 $errs .= "\"$_\" is not exported by the $me module\n";
150 }
151 }
152416µs if($errs ne "") {
153 die "${errs}Can't continue after import errors ".
154 "at @{[(caller(0))[1]]} line @{[(caller(0))[2]]}.\n";
155 }
156}
157
158# Logic duplicated from Params::Classify. Duplicating it here avoids
159# an extensive and potentially circular dependency graph.
160
# spent 259µs within Module::Runtime::_is_string which was called 137 times, avg 2µs/call: # 130 times (249µs+0s) by Module::Runtime::is_module_name at line 222, avg 2µs/call # 7 times (10µs+0s) by Module::Runtime::is_module_spec at line 408, avg 1µs/call
sub _is_string($) {
16113750µs my($arg) = @_;
162137462µs return defined($arg) && ref(\$arg) eq "SCALAR";
163}
164
165=head1 REGULAR EXPRESSIONS
166
167These regular expressions do not include any anchors, so to check
168whether an entire string matches a syntax item you must supply the
169anchors yourself.
170
171=over
172
173=item $module_name_rx
174
175Matches a valid Perl module name in bareword syntax.
176
177=cut
178
17919µs12µsour $module_name_rx = qr/[A-Z_a-z][0-9A-Z_a-z]*(?:::[0-9A-Z_a-z]+)*/;
# spent 2µs making 1 call to Module::Runtime::CORE:qr
180
181=item $top_module_spec_rx
182
183Matches a module specification for use with L</compose_module_name>,
184where no prefix is being used.
185
186=cut
187
18814µs11µsmy $qual_module_spec_rx =
# spent 1µs making 1 call to Module::Runtime::CORE:qr
189 qr#(?:/|::)[A-Z_a-z][0-9A-Z_a-z]*(?:(?:/|::)[0-9A-Z_a-z]+)*#;
190
19113µs1700nsmy $unqual_top_module_spec_rx =
# spent 700ns making 1 call to Module::Runtime::CORE:qr
192 qr#[A-Z_a-z][0-9A-Z_a-z]*(?:(?:/|::)[0-9A-Z_a-z]+)*#;
193
194138µs231µsour $top_module_spec_rx = qr/$qual_module_spec_rx|$unqual_top_module_spec_rx/o;
# spent 30µs making 1 call to Module::Runtime::CORE:regcomp # spent 1µs making 1 call to Module::Runtime::CORE:qr
195
196=item $sub_module_spec_rx
197
198Matches a module specification for use with L</compose_module_name>,
199where a prefix is being used.
200
201=cut
202
20313µs1700nsmy $unqual_sub_module_spec_rx = qr#[0-9A-Z_a-z]+(?:(?:/|::)[0-9A-Z_a-z]+)*#;
# spent 700ns making 1 call to Module::Runtime::CORE:qr
204
205129µs223µsour $sub_module_spec_rx = qr/$qual_module_spec_rx|$unqual_sub_module_spec_rx/o;
# spent 22µs making 1 call to Module::Runtime::CORE:regcomp # spent 900ns making 1 call to Module::Runtime::CORE:qr
206
207=back
208
209=head1 FUNCTIONS
210
211=head2 Basic module handling
212
213=over
214
215=item is_module_name(ARG)
216
217Returns a truth value indicating whether I<ARG> is a plain string
218satisfying Perl module name syntax as described for L</$module_name_rx>.
219
220=cut
221
2221306.55ms390662µs
# spent 1.60ms (942µs+662µs) within Module::Runtime::is_module_name which was called 130 times, avg 12µs/call: # 130 times (942µs+662µs) by Module::Runtime::check_module_name at line 241, avg 12µs/call
sub is_module_name($) { _is_string($_[0]) && $_[0] =~ /\A$module_name_rx\z/o }
# spent 367µs making 130 calls to Module::Runtime::CORE:match, avg 3µs/call # spent 249µs making 130 calls to Module::Runtime::_is_string, avg 2µs/call # spent 46µs making 130 calls to Module::Runtime::CORE:regcomp, avg 358ns/call
223
224=item is_valid_module_name(ARG)
225
226Deprecated alias for L</is_module_name>.
227
228=cut
229
23012µs*is_valid_module_name = \&is_module_name;
231
232=item check_module_name(ARG)
233
234Check whether I<ARG> is a plain string
235satisfying Perl module name syntax as described for L</$module_name_rx>.
236Return normally if it is, or C<die> if it is not.
237
238=cut
239
240
# spent 7.18ms (5.58+1.60) within Module::Runtime::check_module_name which was called 130 times, avg 55µs/call: # 94 times (197µs+1.23ms) by Module::Runtime::module_notional_filename at line 264, avg 15µs/call # 29 times (58µs+263µs) by Module::Runtime::use_package_optimistically at line 382, avg 11µs/call # 7 times (5.32ms+110µs) by Module::Runtime::compose_module_name at line 458, avg 776µs/call
sub check_module_name($) {
241130277µs1301.60ms unless(&is_module_name) {
# spent 1.60ms making 130 calls to Module::Runtime::is_module_name, avg 12µs/call
242 die +(_is_string($_[0]) ? "`$_[0]'" : "argument").
243 " is not a module name\n";
244 }
245}
246
247=item module_notional_filename(NAME)
248
249Generates a notional relative filename for a module, which is used in
250some Perl core interfaces.
251The I<NAME> is a string, which should be a valid module name (one or
252more C<::>-separated segments). If it is not a valid name, the function
253C<die>s.
254
255The notional filename for the named module is generated and returned.
256This filename is always in Unix style, with C</> directory separators
257and a C<.pm> suffix. This kind of filename can be used as an argument to
258C<require>, and is the key that appears in C<%INC> to identify a module,
259regardless of actual local filename syntax.
260
261=cut
262
263
# spent 2.22ms (536µs+1.68) within Module::Runtime::module_notional_filename which was called 94 times, avg 24µs/call: # 40 times (206µs+551µs) by Module::Runtime::require_module at line 317, avg 19µs/call # 29 times (170µs+598µs) by Moo::_Utils::_load_module at line 43 of Moo/_Utils.pm, avg 26µs/call # 25 times (160µs+533µs) by Moo::_Utils::_set_loaded at line 75 of Moo/_Utils.pm, avg 28µs/call
sub module_notional_filename($) {
2649485µs941.43ms &check_module_name;
# spent 1.43ms making 94 calls to Module::Runtime::check_module_name, avg 15µs/call
2659434µs my($name) = @_;
26694441µs94253µs $name =~ s!::!/!g;
# spent 253µs making 94 calls to Module::Runtime::CORE:subst, avg 3µs/call
26794241µs return $name.".pm";
268}
269
270=item require_module(NAME)
271
272This is essentially the bareword form of C<require>, in runtime form.
273The I<NAME> is a string, which should be a valid module name (one or
274more C<::>-separated segments). If it is not a valid name, the function
275C<die>s.
276
277The module specified by I<NAME> is loaded, if it hasn't been already,
278in the manner of the bareword form of C<require>. That means that a
279search through C<@INC> is performed, and a byte-compiled form of the
280module will be used if available.
281
282The return value is as for C<require>. That is, it is the value returned
283by the module itself if the module is loaded anew, or C<1> if the module
284was already loaded.
285
286=cut
287
288# Don't "use constant" here, to avoid dependencies.
289
# spent 8µs within Module::Runtime::BEGIN@289 which was called: # once (8µs+0s) by Moo::_Utils::BEGIN@12 at line 294
BEGIN {
290 *_WORK_AROUND_HINT_LEAKAGE =
291 "$]" < 5.011 && !("$]" >= 5.009004 && "$]" < 5.010001)
29213µs ? sub(){1} : sub(){0};
29317µs *_WORK_AROUND_BROKEN_MODULE_STATE = "$]" < 5.009 ? sub(){1} : sub(){0};
294147µs18µs}
# spent 8µs making 1 call to Module::Runtime::BEGIN@289
295
29614µs
# spent 4µs within Module::Runtime::BEGIN@296 which was called: # once (4µs+0s) by Moo::_Utils::BEGIN@12 at line 301
BEGIN { if(_WORK_AROUND_BROKEN_MODULE_STATE) { eval q{
297 sub Module::Runtime::__GUARD__::DESTROY {
298 delete $INC{$_[0]->[0]} if @{$_[0]};
299 }
300 1;
3011538µs14µs}; die $@ if $@ ne ""; } }
# spent 4µs making 1 call to Module::Runtime::BEGIN@296
302
303
# spent 149ms (23.1+126) within Module::Runtime::require_module which was called 40 times, avg 3.72ms/call: # 29 times (16.6ms+-16.6ms) by Module::Runtime::use_package_optimistically at line 383, avg 0s/call # 9 times (5.89ms+140ms) by Module::Runtime::use_module at line 348, avg 16.2ms/call # 2 times (644µs+1.84ms) by Module::Implementation::try {...} at line 88 of Module/Implementation.pm, avg 1.24ms/call
sub require_module($) {
304 # Localise %^H to work around [perl #68590], where the bug exists
305 # and this is a satisfactory workaround. The bug consists of
306 # %^H state leaking into each required module, polluting the
307 # module's lexical state.
308 local %^H if _WORK_AROUND_HINT_LEAKAGE;
309407µs if(_WORK_AROUND_BROKEN_MODULE_STATE) {
310 my $notional_filename = &module_notional_filename;
311 my $guard = bless([ $notional_filename ],
312 "Module::Runtime::__GUARD__");
313 my $result = require($notional_filename);
314 pop @$guard;
315 return $result;
316 } else {
317402.81ms40757µs return scalar(require(&module_notional_filename));
# spent 757µs making 40 calls to Module::Runtime::module_notional_filename, avg 19µs/call
318 }
319}
320
321=back
322
323=head2 Structured module use
324
325=over
326
327=item use_module(NAME[, VERSION])
328
329This is essentially C<use> in runtime form, but without the importing
330feature (which is fundamentally a compile-time thing). The I<NAME> is
331handled just like in C<require_module> above: it must be a module name,
332and the named module is loaded as if by the bareword form of C<require>.
333
334If a I<VERSION> is specified, the C<VERSION> method of the loaded module is
335called with the specified I<VERSION> as an argument. This normally serves to
336ensure that the version loaded is at least the version required. This is
337the same functionality provided by the I<VERSION> parameter of C<use>.
338
339On success, the name of the module is returned. This is unlike
340L</require_module>, and is done so that the entire call to L</use_module>
341can be used as a class name to call a constructor, as in the example in
342the synopsis.
343
344=cut
345
346
# spent 146ms (55µs+146) within Module::Runtime::use_module which was called 9 times, avg 16.3ms/call: # 9 times (55µs+146ms) by Search::Elasticsearch::Util::load_plugin at line 64 of /opt/flows/lib/lib/perl5/Search/Elasticsearch/Util.pm, avg 16.3ms/call
sub use_module($;$) {
34794µs my($name, $version) = @_;
348914µs9146ms require_module($name);
# spent 146ms making 9 calls to Module::Runtime::require_module, avg 16.2ms/call
34993µs if(defined $version) {
350 $name->VERSION($version);
351 }
352924µs return $name;
353}
354
355=item use_package_optimistically(NAME[, VERSION])
356
357This is an analogue of L</use_module> for the situation where there is
358uncertainty as to whether a package/class is defined in its own module
359or by some other means. It attempts to arrange for the named package to
360be available, either by loading a module or by doing nothing and hoping.
361
362An attempt is made to load the named module (as if by the bareword form
363of C<require>). If the module cannot be found then it is assumed that
364the package was actually already loaded by other means, and no error
365is signalled. That's the optimistic bit.
366
367This is mostly the same operation that is performed by the L<base> pragma
368to ensure that the specified base classes are available. The behaviour
369of L<base> was simplified in version 2.18, and this function changed
370to match.
371
372If a I<VERSION> is specified, the C<VERSION> method of the loaded package is
373called with the specified I<VERSION> as an argument. This normally serves
374to ensure that the version loaded is at least the version required.
375On success, the name of the package is returned. These aspects of the
376function work just like L</use_module>.
377
378=cut
379
380
# spent 68.0ms (310µs+67.7) within Module::Runtime::use_package_optimistically which was called 29 times, avg 2.34ms/call: # 29 times (310µs+67.7ms) by Moo::_Utils::_load_module at line 44 of Moo/_Utils.pm, avg 2.34ms/call
sub use_package_optimistically($;$) {
3812911µs my($name, $version) = @_;
3822926µs29321µs check_module_name($name);
# spent 321µs making 29 calls to Module::Runtime::check_module_name, avg 11µs/call
38387151µs290s eval { local $SIG{__DIE__}; require_module($name); };
# spent 74.8ms making 29 calls to Module::Runtime::require_module, avg 2.58ms/call, recursion: max depth 2, sum of overlapping time 74.8ms
384 die $@ if $@ ne "" &&
3852911µs $@ !~ /\ACan't locate .+ at \Q@{[__FILE__]}\E line/s;
386296µs $name->VERSION($version) if defined $version;
3872956µs return $name;
388}
389
390=back
391
392=head2 Module name composition
393
394=over
395
396=item is_module_spec(PREFIX, SPEC)
397
398Returns a truth value indicating
399whether I<SPEC> is valid input for L</compose_module_name>.
400See below for what that entails. Whether a I<PREFIX> is supplied affects
401the validity of I<SPEC>, but the exact value of the prefix is unimportant,
402so this function treats I<PREFIX> as a truth value.
403
404=cut
405
406
# spent 192µs (79+113) within Module::Runtime::is_module_spec which was called 7 times, avg 27µs/call: # 7 times (79µs+113µs) by Module::Runtime::check_module_spec at line 429, avg 27µs/call
sub is_module_spec($$) {
40774µs my($prefix, $spec) = @_;
4087176µs35113µs return _is_string($spec) &&
# spent 71µs making 14 calls to Module::Runtime::CORE:regcomp, avg 5µs/call # spent 17µs making 7 calls to Module::Runtime::CORE:match, avg 2µs/call # spent 14µs making 7 calls to Module::Runtime::CORE:qr, avg 2µs/call # spent 10µs making 7 calls to Module::Runtime::_is_string, avg 1µs/call
409 $spec =~ ($prefix ? qr/\A$sub_module_spec_rx\z/o :
410 qr/\A$top_module_spec_rx\z/o);
411}
412
413=item is_valid_module_spec(PREFIX, SPEC)
414
415Deprecated alias for L</is_module_spec>.
416
417=cut
418
4191500ns*is_valid_module_spec = \&is_module_spec;
420
421=item check_module_spec(PREFIX, SPEC)
422
423Check whether I<SPEC> is valid input for L</compose_module_name>.
424Return normally if it is, or C<die> if it is not.
425
426=cut
427
428
# spent 213µs (22+192) within Module::Runtime::check_module_spec which was called 7 times, avg 30µs/call: # 7 times (22µs+192µs) by Module::Runtime::compose_module_name at line 459, avg 30µs/call
sub check_module_spec($$) {
429719µs7192µs unless(&is_module_spec) {
# spent 192µs making 7 calls to Module::Runtime::is_module_spec, avg 27µs/call
430 die +(_is_string($_[1]) ? "`$_[1]'" : "argument").
431 " is not a module specification\n";
432 }
433}
434
435=item compose_module_name(PREFIX, SPEC)
436
437This function is intended to make it more convenient for a user to specify
438a Perl module name at runtime. Users have greater need for abbreviations
439and context-sensitivity than programmers, and Perl module names get a
440little unwieldy. I<SPEC> is what the user specifies, and this function
441translates it into a module name in standard form, which it returns.
442
443I<SPEC> has syntax approximately that of a standard module name: it
444should consist of one or more name segments, each of which consists
445of one or more identifier characters. However, C</> is permitted as a
446separator, in addition to the standard C<::>. The two separators are
447entirely interchangeable.
448
449Additionally, if I<PREFIX> is not C<undef> then it must be a module
450name in standard form, and it is prefixed to the user-specified name.
451The user can inhibit the prefix addition by starting I<SPEC> with a
452separator (either C</> or C<::>).
453
454=cut
455
456
# spent 5.76ms (100µs+5.66) within Module::Runtime::compose_module_name which was called 7 times, avg 822µs/call: # 7 times (100µs+5.66ms) by Search::Elasticsearch::Util::load_plugin at line 60 of /opt/flows/lib/lib/perl5/Search/Elasticsearch/Util.pm, avg 822µs/call
sub compose_module_name($$) {
45773µs my($prefix, $spec) = @_;
458711µs75.43ms check_module_name($prefix) if defined $prefix;
# spent 5.43ms making 7 calls to Module::Runtime::check_module_name, avg 776µs/call
459716µs7213µs &check_module_spec;
# spent 213µs making 7 calls to Module::Runtime::check_module_spec, avg 30µs/call
460723µs77µs if($spec =~ s#\A(?:/|::)##) {
# spent 7µs making 7 calls to Module::Runtime::CORE:subst, avg 1µs/call
461 # OK
462 } else {
46379µs $spec = $prefix."::".$spec if defined $prefix;
464 }
465718µs73µs $spec =~ s#/#::#g;
# spent 3µs making 7 calls to Module::Runtime::CORE:subst, avg 429ns/call
466717µs return $spec;
467}
468
469=back
470
471=head1 SEE ALSO
472
473L<Lexical::SealRequireHints>,
474L<base>,
475L<perlfunc/require>,
476L<perlfunc/use>
477
478=head1 AUTHOR
479
480Andrew Main (Zefram) <zefram@fysh.org>
481
482=head1 COPYRIGHT
483
484Copyright (C) 2004, 2006, 2007, 2009, 2010, 2011, 2012
485Andrew Main (Zefram) <zefram@fysh.org>
486
487=head1 LICENSE
488
489This module is free software; you can redistribute it and/or modify it
490under the same terms as Perl itself.
491
492=cut
493
494113µs1;
 
# spent 389µs within Module::Runtime::CORE:match which was called 144 times, avg 3µs/call: # 130 times (367µs+0s) by Module::Runtime::is_module_name at line 222, avg 3µs/call # 7 times (17µs+0s) by Module::Runtime::is_module_spec at line 408, avg 2µs/call # 7 times (5µs+0s) by Module::Runtime::import at line 143, avg 743ns/call
sub Module::Runtime::CORE:match; # opcode
# spent 21µs within Module::Runtime::CORE:qr which was called 13 times, avg 2µs/call: # 7 times (14µs+0s) by Module::Runtime::is_module_spec at line 408, avg 2µs/call # once (2µs+0s) by Moo::_Utils::BEGIN@12 at line 179 # once (1µs+0s) by Moo::_Utils::BEGIN@12 at line 194 # once (1µs+0s) by Moo::_Utils::BEGIN@12 at line 188 # once (900ns+0s) by Moo::_Utils::BEGIN@12 at line 205 # once (700ns+0s) by Moo::_Utils::BEGIN@12 at line 191 # once (700ns+0s) by Moo::_Utils::BEGIN@12 at line 203
sub Module::Runtime::CORE:qr; # opcode
# spent 170µs within Module::Runtime::CORE:regcomp which was called 146 times, avg 1µs/call: # 130 times (46µs+0s) by Module::Runtime::is_module_name at line 222, avg 358ns/call # 14 times (71µs+0s) by Module::Runtime::is_module_spec at line 408, avg 5µs/call # once (30µs+0s) by Moo::_Utils::BEGIN@12 at line 194 # once (22µs+0s) by Moo::_Utils::BEGIN@12 at line 205
sub Module::Runtime::CORE:regcomp; # opcode
# spent 263µs within Module::Runtime::CORE:subst which was called 108 times, avg 2µs/call: # 94 times (253µs+0s) by Module::Runtime::module_notional_filename at line 266, avg 3µs/call # 7 times (7µs+0s) by Module::Runtime::compose_module_name at line 460, avg 1µs/call # 7 times (3µs+0s) by Module::Runtime::compose_module_name at line 465, avg 429ns/call
sub Module::Runtime::CORE:subst; # opcode