← Index
NYTProf Performance Profile   « line view »
For ../prof.pl
  Run on Wed Dec 14 15:33:55 2022
Reported on Wed Dec 14 15:40:03 2022

Filename/Users/ether/.perlbrew/libs/36.0@std/lib/perl5/Module/Runtime.pm
StatementsExecuted 416 statements in 10.6ms
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
303324.2ms80.4msModule::Runtime::::require_moduleModule::Runtime::require_module
3011235µs843µsModule::Runtime::::module_notional_filenameModule::Runtime::module_notional_filename
331215µs215µsModule::Runtime::::CORE:regcompModule::Runtime::CORE:regcomp (opcode)
3011169µs449µsModule::Runtime::::is_module_nameModule::Runtime::is_module_name
3521138µs138µsModule::Runtime::::CORE:matchModule::Runtime::CORE:match (opcode)
301195µs544µsModule::Runtime::::check_module_nameModule::Runtime::check_module_name
163186µs60.8msModule::Runtime::::use_moduleModule::Runtime::use_module
44483µs91µsModule::Runtime::::importModule::Runtime::import
301181µs81µsModule::Runtime::::_is_stringModule::Runtime::_is_string
301164µs64µsModule::Runtime::::CORE:substModule::Runtime::CORE:subst (opcode)
11150µs50µsModule::Runtime::::BEGIN@113Module::Runtime::BEGIN@113
11134µs34µsModule::Runtime::::BEGIN@286Module::Runtime::BEGIN@286
66113µs13µsModule::Runtime::::CORE:qrModule::Runtime::CORE:qr (opcode)
1114µs4µsModule::Runtime::::BEGIN@117Module::Runtime::BEGIN@117
1114µs4µsModule::Runtime::::BEGIN@293Module::Runtime::BEGIN@293
0000s0sModule::Runtime::::check_module_specModule::Runtime::check_module_spec
0000s0sModule::Runtime::::compose_module_nameModule::Runtime::compose_module_name
0000s0sModule::Runtime::::is_module_specModule::Runtime::is_module_spec
0000s0sModule::Runtime::::use_package_optimisticallyModule::Runtime::use_package_optimistically
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 if($module_name =~ /\A$module_name_rx\z/o) { ...
12 if(is_module_name($module_name)) { ...
13 check_module_name($module_name);
14
15 $notional_filename = module_notional_filename($module_name);
16 require_module($module_name);
17
18 use Module::Runtime qw(use_module use_package_optimistically);
19
20 $bi = use_module("Math::BigInt", 1.31)->new("1_234");
21 $widget = use_package_optimistically("Local::Widget")->new;
22
23 use Module::Runtime qw(
24 $top_module_spec_rx $sub_module_spec_rx
25 is_module_spec check_module_spec
26 compose_module_name);
27
28 if($spec =~ /\A$top_module_spec_rx\z/o) { ...
29 if($spec =~ /\A$sub_module_spec_rx\z/o) { ...
30 if(is_module_spec("Standard::Prefix", $spec)) { ...
31 check_module_spec("Standard::Prefix", $spec);
32
33 $module_name = compose_module_name("Standard::Prefix", $spec);
34
35=head1 DESCRIPTION
36
37The functions exported by this module deal with runtime handling of
38Perl modules, which are normally handled at compile time. This module
39avoids using any other modules, so that it can be used in low-level
40infrastructure.
41
42The parts of this module that work with module names apply the same syntax
43that is used for barewords in Perl source. In principle this syntax
44can vary between versions of Perl, and this module applies the syntax of
45the Perl on which it is running. In practice the usable syntax hasn't
46changed yet. There's some intent for Unicode module names to be supported
47in the future, but this hasn't yet amounted to any consistent facility.
48
49The functions of this module whose purpose is to load modules include
50workarounds for three old Perl core bugs regarding C<require>. These
51workarounds are applied on any Perl version where the bugs exist, except
52for a case where one of the bugs cannot be adequately worked around in
53pure Perl.
54
55=head2 Module name syntax
56
57The usable module name syntax has not changed from Perl 5.000 up to
58Perl 5.19.8. The syntax is composed entirely of ASCII characters.
59From Perl 5.6 onwards there has been some attempt to allow the use of
60non-ASCII Unicode characters in Perl source, but it was fundamentally
61broken (like the entirety of Perl 5.6's Unicode handling) and remained
62pretty much entirely unusable until it got some attention in the Perl
635.15 series. Although Unicode is now consistently accepted by the
64parser in some places, it remains broken for module names. Furthermore,
65there has not yet been any work on how to map Unicode module names into
66filenames, so in that respect also Unicode module names are unusable.
67
68The module name syntax is, precisely: the string must consist of one or
69more segments separated by C<::>; each segment must consist of one or more
70identifier characters (ASCII alphanumerics plus "_"); the first character
71of the string must not be a digit. Thus "C<IO::File>", "C<warnings>",
72and "C<foo::123::x_0>" are all valid module names, whereas "C<IO::>"
73and "C<1foo::bar>" are not. C<'> separators are not permitted by this
74module, though they remain usable in Perl source, being translated to
75C<::> in the parser.
76
77=head2 Core bugs worked around
78
79The first bug worked around is core bug [perl #68590], which causes
80lexical state in one file to leak into another that is C<require>d/C<use>d
81from it. This bug is present from Perl 5.6 up to Perl 5.10, and is
82fixed in Perl 5.11.0. From Perl 5.9.4 up to Perl 5.10.0 no satisfactory
83workaround is possible in pure Perl. The workaround means that modules
84loaded via this module don't suffer this pollution of their lexical
85state. Modules loaded in other ways, or via this module on the Perl
86versions where the pure Perl workaround is impossible, remain vulnerable.
87The module L<Lexical::SealRequireHints> provides a complete workaround
88for this bug.
89
90The second bug worked around causes some kinds of failure in module
91loading, principally compilation errors in the loaded module, to be
92recorded in C<%INC> as if they were successful, so later attempts to load
93the same module immediately indicate success. This bug is present up
94to Perl 5.8.9, and is fixed in Perl 5.9.0. The workaround means that a
95compilation error in a module loaded via this module won't be cached as
96a success. Modules loaded in other ways remain liable to produce bogus
97C<%INC> entries, and if a bogus entry exists then it will mislead this
98module if it is used to re-attempt loading.
99
100The third bug worked around causes the wrong context to be seen at
101file scope of a loaded module, if C<require> is invoked in a location
102that inherits context from a higher scope. This bug is present up to
103Perl 5.11.2, and is fixed in Perl 5.11.3. The workaround means that
104a module loaded via this module will always see the correct context.
105Modules loaded in other ways remain vulnerable.
106
107=cut
108
109package Module::Runtime;
110
111# Don't "use 5.006" here, because Perl 5.15.6 will load feature.pm if
112# the version check is done that way.
113151µs150µs
# spent 50µs within Module::Runtime::BEGIN@113 which was called: # once (50µs+0s) by JSON::Schema::Modern::BEGIN@28 at line 113
BEGIN { require 5.006; }
# spent 50µs making 1 call to Module::Runtime::BEGIN@113
114# Don't "use warnings" here, to avoid dependencies. Do standardise the
115# warning status by lexical override; unfortunately the only safe bitset
116# to build in is the empty set, equivalent to "no warnings".
11711.20ms14µs
# spent 4µs within Module::Runtime::BEGIN@117 which was called: # once (4µs+0s) by JSON::Schema::Modern::BEGIN@28 at line 117
BEGIN { ${^WARNING_BITS} = ""; }
# spent 4µs making 1 call to Module::Runtime::BEGIN@117
118# Don't "use strict" here, to avoid dependencies.
119
12011µsour $VERSION = "0.016";
121
122# Don't use Exporter here, to avoid dependencies.
12315µsour @EXPORT_OK = qw(
124 $module_name_rx is_module_name is_valid_module_name check_module_name
125 module_notional_filename require_module
126 use_module use_package_optimistically
127 $top_module_spec_rx $sub_module_spec_rx
128 is_module_spec is_valid_module_spec check_module_spec
129 compose_module_name
130);
131112µsmy %export_ok = map { ($_ => undef) } @EXPORT_OK;
132
# spent 91µs (83+8) within Module::Runtime::import which was called 4 times, avg 23µs/call: # once (35µs+3µs) by JSON::Schema::Modern::BEGIN@28 at line 28 of JSON/Schema/Modern.pm # once (23µs+2µs) by MooX::HandlesVia::BEGIN@9 at line 9 of MooX/HandlesVia.pm # once (12µs+2µs) by Module::Implementation::BEGIN@8 at line 8 of Module/Implementation.pm # once (13µs+1µs) by Data::Perl::Role::Collection::Hash::BEGIN@9 at line 9 of Data/Perl/Role/Collection/Hash.pm
sub import {
13343µs my $me = shift;
13445µs my $callpkg = caller(0);
13541µs my $errs = "";
13643µs foreach(@_) {
137513µs if(exists $export_ok{$_}) {
138 # We would need to do "no strict 'refs'" here
139 # if we had enabled strict at file scope.
140525µs58µs if(/\A\$(.*)\z/s) {
# spent 8µs making 5 calls to Module::Runtime::CORE:match, avg 2µs/call
141 *{$callpkg."::".$1} = \$$1;
142 } else {
143524µs *{$callpkg."::".$_} = \&$_;
144 }
145 } else {
146 $errs .= "\"$_\" is not exported by the $me module\n";
147 }
148 }
149415µs if($errs ne "") {
150 die "${errs}Can't continue after import errors ".
151 "at @{[(caller(0))[1]]} line @{[(caller(0))[2]]}.\n";
152 }
153}
154
155# Logic duplicated from Params::Classify. Duplicating it here avoids
156# an extensive and potentially circular dependency graph.
157
# spent 81µs within Module::Runtime::_is_string which was called 30 times, avg 3µs/call: # 30 times (81µs+0s) by Module::Runtime::is_module_name at line 219, avg 3µs/call
sub _is_string($) {
1583011µs my($arg) = @_;
1593085µs return defined($arg) && ref(\$arg) eq "SCALAR";
160}
161
162=head1 REGULAR EXPRESSIONS
163
164These regular expressions do not include any anchors, so to check
165whether an entire string matches a syntax item you must supply the
166anchors yourself.
167
168=over
169
170=item $module_name_rx
171
172Matches a valid Perl module name in bareword syntax.
173
174=cut
175
176112µs14µsour $module_name_rx = qr/[A-Z_a-z][0-9A-Z_a-z]*(?:::[0-9A-Z_a-z]+)*/;
# spent 4µs making 1 call to Module::Runtime::CORE:qr
177
178=item $top_module_spec_rx
179
180Matches a module specification for use with L</compose_module_name>,
181where no prefix is being used.
182
183=cut
184
18514µs11µsmy $qual_module_spec_rx =
# spent 1µs making 1 call to Module::Runtime::CORE:qr
186 qr#(?:/|::)[A-Z_a-z][0-9A-Z_a-z]*(?:(?:/|::)[0-9A-Z_a-z]+)*#;
187
18812µs11µsmy $unqual_top_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
1911111µs2102µsour $top_module_spec_rx = qr/$qual_module_spec_rx|$unqual_top_module_spec_rx/o;
# spent 97µs making 1 call to Module::Runtime::CORE:regcomp # spent 5µs making 1 call to Module::Runtime::CORE:qr
192
193=item $sub_module_spec_rx
194
195Matches a module specification for use with L</compose_module_name>,
196where a prefix is being used.
197
198=cut
199
20013µs11µsmy $unqual_sub_module_spec_rx = qr#[0-9A-Z_a-z]+(?:(?:/|::)[0-9A-Z_a-z]+)*#;
# spent 1µs making 1 call to Module::Runtime::CORE:qr
201
202155µs250µsour $sub_module_spec_rx = qr/$qual_module_spec_rx|$unqual_sub_module_spec_rx/o;
# spent 49µs making 1 call to Module::Runtime::CORE:regcomp # spent 1µs making 1 call to Module::Runtime::CORE:qr
203
204=back
205
206=head1 FUNCTIONS
207
208=head2 Basic module handling
209
210=over
211
212=item is_module_name(ARG)
213
214Returns a truth value indicating whether I<ARG> is a plain string
215satisfying Perl module name syntax as described for L</$module_name_rx>.
216
217=cut
218
21930380µs61280µs
# spent 449µs (169+280) within Module::Runtime::is_module_name which was called 30 times, avg 15µs/call: # 30 times (169µs+280µs) by Module::Runtime::check_module_name at line 238, avg 15µs/call
sub is_module_name($) { _is_string($_[0]) && $_[0] =~ /\A$module_name_rx\z/o }
# spent 130µs making 30 calls to Module::Runtime::CORE:match, avg 4µs/call # spent 81µs making 30 calls to Module::Runtime::_is_string, avg 3µs/call # spent 69µs making 1 call to Module::Runtime::CORE:regcomp
220
221=item is_valid_module_name(ARG)
222
223Deprecated alias for L</is_module_name>.
224
225=cut
226
22712µs*is_valid_module_name = \&is_module_name;
228
229=item check_module_name(ARG)
230
231Check whether I<ARG> is a plain string
232satisfying Perl module name syntax as described for L</$module_name_rx>.
233Return normally if it is, or C<die> if it is not.
234
235=cut
236
237
# spent 544µs (95+449) within Module::Runtime::check_module_name which was called 30 times, avg 18µs/call: # 30 times (95µs+449µs) by Module::Runtime::module_notional_filename at line 261, avg 18µs/call
sub check_module_name($) {
2383080µs30449µs unless(&is_module_name) {
# spent 449µs making 30 calls to Module::Runtime::is_module_name, avg 15µs/call
239 die +(_is_string($_[0]) ? "`$_[0]'" : "argument").
240 " is not a module name\n";
241 }
242}
243
244=item module_notional_filename(NAME)
245
246Generates a notional relative filename for a module, which is used in
247some Perl core interfaces.
248The I<NAME> is a string, which should be a valid module name (one or
249more C<::>-separated segments). If it is not a valid name, the function
250C<die>s.
251
252The notional filename for the named module is generated and returned.
253This filename is always in Unix style, with C</> directory separators
254and a C<.pm> suffix. This kind of filename can be used as an argument to
255C<require>, and is the key that appears in C<%INC> to identify a module,
256regardless of actual local filename syntax.
257
258=cut
259
260
# spent 843µs (235+608) within Module::Runtime::module_notional_filename which was called 30 times, avg 28µs/call: # 30 times (235µs+608µs) by Module::Runtime::require_module at line 314, avg 28µs/call
sub module_notional_filename($) {
2613042µs30544µs &check_module_name;
# spent 544µs making 30 calls to Module::Runtime::check_module_name, avg 18µs/call
262309µs my($name) = @_;
26330184µs3064µs $name =~ s!::!/!g;
# spent 64µs making 30 calls to Module::Runtime::CORE:subst, avg 2µs/call
2643060µs return $name.".pm";
265}
266
267=item require_module(NAME)
268
269This is essentially the bareword form of C<require>, in runtime form.
270The I<NAME> is a string, which should be a valid module name (one or
271more C<::>-separated segments). If it is not a valid name, the function
272C<die>s.
273
274The module specified by I<NAME> is loaded, if it hasn't been already,
275in the manner of the bareword form of C<require>. That means that a
276search through C<@INC> is performed, and a byte-compiled form of the
277module will be used if available.
278
279The return value is as for C<require>. That is, it is the value returned
280by the module itself if the module is loaded anew, or C<1> if the module
281was already loaded.
282
283=cut
284
285# Don't "use constant" here, to avoid dependencies.
286
# spent 34µs within Module::Runtime::BEGIN@286 which was called: # once (34µs+0s) by JSON::Schema::Modern::BEGIN@28 at line 291
BEGIN {
287 *_WORK_AROUND_HINT_LEAKAGE =
288 "$]" < 5.011 && !("$]" >= 5.009004 && "$]" < 5.010001)
289119µs ? sub(){1} : sub(){0};
290112µs *_WORK_AROUND_BROKEN_MODULE_STATE = "$]" < 5.009 ? sub(){1} : sub(){0};
291168µs134µs}
# spent 34µs making 1 call to Module::Runtime::BEGIN@286
292
29313µs
# spent 4µs within Module::Runtime::BEGIN@293 which was called: # once (4µs+0s) by JSON::Schema::Modern::BEGIN@28 at line 298
BEGIN { if(_WORK_AROUND_BROKEN_MODULE_STATE) { eval q{
294 sub Module::Runtime::__GUARD__::DESTROY {
295 delete $INC{$_[0]->[0]} if @{$_[0]};
296 }
297 1;
2981781µs14µs}; die $@ if $@ ne ""; } }
# spent 4µs making 1 call to Module::Runtime::BEGIN@293
299
300
# spent 80.4ms (24.2+56.2) within Module::Runtime::require_module which was called 30 times, avg 2.68ms/call: # 16 times (20.9ms+39.9ms) by Module::Runtime::use_module at line 345, avg 3.80ms/call # 12 times (1.75ms+9.05ms) by MooX::HandlesVia::process_has at line 53 of MooX/HandlesVia.pm, avg 900µs/call # 2 times (1.60ms+7.24ms) by Module::Implementation::try {...} at line 93 of Module/Implementation.pm, avg 4.42ms/call
sub require_module($) {
301 # Localise %^H to work around [perl #68590], where the bug exists
302 # and this is a satisfactory workaround. The bug consists of
303 # %^H state leaking into each required module, polluting the
304 # module's lexical state.
305 local %^H if _WORK_AROUND_HINT_LEAKAGE;
306306µs if(_WORK_AROUND_BROKEN_MODULE_STATE) {
307 my $notional_filename = &module_notional_filename;
308 my $guard = bless([ $notional_filename ],
309 "Module::Runtime::__GUARD__");
310 my $result = CORE::require($notional_filename);
311 pop @$guard;
312 return $result;
313 } else {
314307.22ms30843µs return scalar(CORE::require(&module_notional_filename));
# spent 843µs making 30 calls to Module::Runtime::module_notional_filename, avg 28µs/call
315 }
316}
317
318=back
319
320=head2 Structured module use
321
322=over
323
324=item use_module(NAME[, VERSION])
325
326This is essentially C<use> in runtime form, but without the importing
327feature (which is fundamentally a compile-time thing). The I<NAME> is
328handled just like in C<require_module> above: it must be a module name,
329and the named module is loaded as if by the bareword form of C<require>.
330
331If a I<VERSION> is specified, the C<VERSION> method of the loaded module is
332called with the specified I<VERSION> as an argument. This normally serves to
333ensure that the version loaded is at least the version required. This is
334the same functionality provided by the I<VERSION> parameter of C<use>.
335
336On success, the name of the module is returned. This is unlike
337L</require_module>, and is done so that the entire call to L</use_module>
338can be used as a class name to call a constructor, as in the example in
339the synopsis.
340
341=cut
342
343
# spent 60.8ms (86µs+60.8) within Module::Runtime::use_module which was called 16 times, avg 3.80ms/call: # 8 times (62µs+55.7ms) by JSON::Schema::Modern::__ANON__[/Users/ether/.perlbrew/libs/36.0@std/lib/perl5/JSON/Schema/Modern.pm:670] at line 666 of JSON/Schema/Modern.pm, avg 6.97ms/call # 7 times (16µs+78µs) by JSON::Schema::Modern::__ANON__[/Users/ether/.perlbrew/libs/36.0@std/lib/perl5/JSON/Schema/Modern.pm:712] at line 704 of JSON/Schema/Modern.pm, avg 13µs/call # once (8µs+4.96ms) by JSON::Schema::Modern::add_vocabulary at line 676 of JSON/Schema/Modern.pm
sub use_module($;$) {
344165µs my($name, $version) = @_;
3451623µs1660.8ms require_module($name);
# spent 60.8ms making 16 calls to Module::Runtime::require_module, avg 3.80ms/call
346168µs $name->VERSION($version) if @_ >= 2;
3471633µs return $name;
348}
349
350=item use_package_optimistically(NAME[, VERSION])
351
352This is an analogue of L</use_module> for the situation where there is
353uncertainty as to whether a package/class is defined in its own module
354or by some other means. It attempts to arrange for the named package to
355be available, either by loading a module or by doing nothing and hoping.
356
357An attempt is made to load the named module (as if by the bareword form
358of C<require>). If the module cannot be found then it is assumed that
359the package was actually already loaded by other means, and no error
360is signalled. That's the optimistic bit.
361
362I<Warning:> this optional module loading is liable to cause unreliable
363behaviour, including security problems. It interacts especially badly
364with having C<.> in C<@INC>, which was the default state of affairs in
365Perls prior to 5.25.11. If a package is actually defined by some means
366other than a module, then applying this function to it causes a spurious
367attempt to load a module that is expected to be non-existent. If a
368module actually exists under that name then it will be unintentionally
369loaded. If C<.> is in C<@INC> and this code is ever run with the current
370directory being one writable by a malicious user (such as F</tmp>), then
371the malicious user can easily cause the victim to run arbitrary code, by
372creating a module file under the predictable spuriously-loaded name in the
373writable directory. Generally, optional module loading should be avoided.
374
375This is mostly the same operation that is performed by the L<base> pragma
376to ensure that the specified base classes are available. The behaviour
377of L<base> was simplified in version 2.18, and later improved in version
3782.20, and on both occasions this function changed to match.
379
380If a I<VERSION> is specified, the C<VERSION> method of the loaded package is
381called with the specified I<VERSION> as an argument. This normally serves
382to ensure that the version loaded is at least the version required.
383On success, the name of the package is returned. These aspects of the
384function work just like L</use_module>.
385
386=cut
387
388sub use_package_optimistically($;$) {
389 my($name, $version) = @_;
390 my $fn = module_notional_filename($name);
391 eval { local $SIG{__DIE__}; require_module($name); };
392 die $@ if $@ ne "" &&
393 ($@ !~ /\ACan't locate \Q$fn\E .+ at \Q@{[__FILE__]}\E line/s ||
394 $@ =~ /^Compilation\ failed\ in\ require
395 \ at\ \Q@{[__FILE__]}\E\ line/xm);
396 $name->VERSION($version) if @_ >= 2;
397 return $name;
398}
399
400=back
401
402=head2 Module name composition
403
404=over
405
406=item is_module_spec(PREFIX, SPEC)
407
408Returns a truth value indicating
409whether I<SPEC> is valid input for L</compose_module_name>.
410See below for what that entails. Whether a I<PREFIX> is supplied affects
411the validity of I<SPEC>, but the exact value of the prefix is unimportant,
412so this function treats I<PREFIX> as a truth value.
413
414=cut
415
416sub is_module_spec($$) {
417 my($prefix, $spec) = @_;
418 return _is_string($spec) &&
419 $spec =~ ($prefix ? qr/\A$sub_module_spec_rx\z/o :
420 qr/\A$top_module_spec_rx\z/o);
421}
422
423=item is_valid_module_spec(PREFIX, SPEC)
424
425Deprecated alias for L</is_module_spec>.
426
427=cut
428
42910s*is_valid_module_spec = \&is_module_spec;
430
431=item check_module_spec(PREFIX, SPEC)
432
433Check whether I<SPEC> is valid input for L</compose_module_name>.
434Return normally if it is, or C<die> if it is not.
435
436=cut
437
438sub check_module_spec($$) {
439 unless(&is_module_spec) {
440 die +(_is_string($_[1]) ? "`$_[1]'" : "argument").
441 " is not a module specification\n";
442 }
443}
444
445=item compose_module_name(PREFIX, SPEC)
446
447This function is intended to make it more convenient for a user to specify
448a Perl module name at runtime. Users have greater need for abbreviations
449and context-sensitivity than programmers, and Perl module names get a
450little unwieldy. I<SPEC> is what the user specifies, and this function
451translates it into a module name in standard form, which it returns.
452
453I<SPEC> has syntax approximately that of a standard module name: it
454should consist of one or more name segments, each of which consists
455of one or more identifier characters. However, C</> is permitted as a
456separator, in addition to the standard C<::>. The two separators are
457entirely interchangeable.
458
459Additionally, if I<PREFIX> is not C<undef> then it must be a module
460name in standard form, and it is prefixed to the user-specified name.
461The user can inhibit the prefix addition by starting I<SPEC> with a
462separator (either C</> or C<::>).
463
464=cut
465
466sub compose_module_name($$) {
467 my($prefix, $spec) = @_;
468 check_module_name($prefix) if defined $prefix;
469 &check_module_spec;
470 if($spec =~ s#\A(?:/|::)##) {
471 # OK
472 } else {
473 $spec = $prefix."::".$spec if defined $prefix;
474 }
475 $spec =~ s#/#::#g;
476 return $spec;
477}
478
479=back
480
481=head1 BUGS
482
483On Perl versions 5.7.2 to 5.8.8, if C<require> is overridden by the
484C<CORE::GLOBAL> mechanism, it is likely to break the heuristics used by
485L</use_package_optimistically>, making it signal an error for a missing
486module rather than assume that it was already loaded. From Perl 5.8.9
487onwards, and on 5.7.1 and earlier, this module can avoid being confused
488by such an override. On the affected versions, a C<require> override
489might be installed by L<Lexical::SealRequireHints>, if something requires
490its bugfix but for some reason its XS implementation isn't available.
491
492=head1 SEE ALSO
493
494L<Lexical::SealRequireHints>,
495L<base>,
496L<perlfunc/require>,
497L<perlfunc/use>
498
499=head1 AUTHOR
500
501Andrew Main (Zefram) <zefram@fysh.org>
502
503=head1 COPYRIGHT
504
505Copyright (C) 2004, 2006, 2007, 2009, 2010, 2011, 2012, 2014, 2017
506Andrew Main (Zefram) <zefram@fysh.org>
507
508=head1 LICENSE
509
510This module is free software; you can redistribute it and/or modify it
511under the same terms as Perl itself.
512
513=cut
514
515123µs1;
 
# spent 138µs within Module::Runtime::CORE:match which was called 35 times, avg 4µs/call: # 30 times (130µs+0s) by Module::Runtime::is_module_name at line 219, avg 4µs/call # 5 times (8µs+0s) by Module::Runtime::import at line 140, avg 2µs/call
sub Module::Runtime::CORE:match; # opcode
# spent 13µs within Module::Runtime::CORE:qr which was called 6 times, avg 2µs/call: # once (5µs+0s) by JSON::Schema::Modern::BEGIN@28 at line 191 # once (4µs+0s) by JSON::Schema::Modern::BEGIN@28 at line 176 # once (1µs+0s) by JSON::Schema::Modern::BEGIN@28 at line 188 # once (1µs+0s) by JSON::Schema::Modern::BEGIN@28 at line 185 # once (1µs+0s) by JSON::Schema::Modern::BEGIN@28 at line 202 # once (1µs+0s) by JSON::Schema::Modern::BEGIN@28 at line 200
sub Module::Runtime::CORE:qr; # opcode
# spent 215µs within Module::Runtime::CORE:regcomp which was called 3 times, avg 72µs/call: # once (97µs+0s) by JSON::Schema::Modern::BEGIN@28 at line 191 # once (69µs+0s) by Module::Runtime::is_module_name at line 219 # once (49µs+0s) by JSON::Schema::Modern::BEGIN@28 at line 202
sub Module::Runtime::CORE:regcomp; # opcode
# spent 64µs within Module::Runtime::CORE:subst which was called 30 times, avg 2µs/call: # 30 times (64µs+0s) by Module::Runtime::module_notional_filename at line 263, avg 2µs/call
sub Module::Runtime::CORE:subst; # opcode