Alt-Module-Runtime-ButEUMM
view release on metacpan or search on metacpan
lib/Module/Runtime.pm view on Meta::CPAN
module, though they remain usable in Perl source, being translated to
C<::> in the parser.
=head2 Core bugs worked around
The first bug worked around is core bug [perl #68590], which causes
lexical state in one file to leak into another that is C<require>d/C<use>d
from it. This bug is present from Perl 5.6 up to Perl 5.10, and is
fixed in Perl 5.11.0. From Perl 5.9.4 up to Perl 5.10.0 no satisfactory
workaround is possible in pure Perl. The workaround means that modules
loaded via this module don't suffer this pollution of their lexical
state. Modules loaded in other ways, or via this module on the Perl
versions where the pure Perl workaround is impossible, remain vulnerable.
The module L<Lexical::SealRequireHints> provides a complete workaround
for this bug.
The second bug worked around causes some kinds of failure in module
loading, principally compilation errors in the loaded module, to be
recorded in C<%INC> as if they were successful, so later attempts to load
the same module immediately indicate success. This bug is present up
to Perl 5.8.9, and is fixed in Perl 5.9.0. The workaround means that a
compilation error in a module loaded via this module won't be cached as
a success. Modules loaded in other ways remain liable to produce bogus
C<%INC> entries, and if a bogus entry exists then it will mislead this
module if it is used to re-attempt loading.
The third bug worked around causes the wrong context to be seen at
file scope of a loaded module, if C<require> is invoked in a location
that inherits context from a higher scope. This bug is present up to
Perl 5.11.2, and is fixed in Perl 5.11.3. The workaround means that
a module loaded via this module will always see the correct context.
Modules loaded in other ways remain vulnerable.
=cut
package Module::Runtime;
# Don't "use 5.006" here, because Perl 5.15.6 will load feature.pm if
# the version check is done that way.
BEGIN { require 5.006; }
# Don't "use warnings" here, to avoid dependencies. Do standardise the
# warning status by lexical override; unfortunately the only safe bitset
# to build in is the empty set, equivalent to "no warnings".
BEGIN { ${^WARNING_BITS} = ""; }
# Don't "use strict" here, to avoid dependencies.
our $VERSION = "0.016";
# Don't use Exporter here, to avoid dependencies.
our @EXPORT_OK = qw(
$module_name_rx is_module_name is_valid_module_name check_module_name
module_notional_filename require_module
use_module use_package_optimistically
$top_module_spec_rx $sub_module_spec_rx
is_module_spec is_valid_module_spec check_module_spec
compose_module_name
);
my %export_ok = map { ($_ => undef) } @EXPORT_OK;
sub import {
my $me = shift;
my $callpkg = caller(0);
my $errs = "";
foreach(@_) {
if(exists $export_ok{$_}) {
# We would need to do "no strict 'refs'" here
# if we had enabled strict at file scope.
if(/\A\$(.*)\z/s) {
*{$callpkg."::".$1} = \$$1;
} else {
*{$callpkg."::".$_} = \&$_;
}
} else {
$errs .= "\"$_\" is not exported by the $me module\n";
}
}
if($errs ne "") {
die "${errs}Can't continue after import errors ".
"at @{[(caller(0))[1]]} line @{[(caller(0))[2]]}.\n";
}
}
# Logic duplicated from Params::Classify. Duplicating it here avoids
# an extensive and potentially circular dependency graph.
sub _is_string($) {
my($arg) = @_;
return defined($arg) && ref(\$arg) eq "SCALAR";
}
=head1 REGULAR EXPRESSIONS
These regular expressions do not include any anchors, so to check
whether an entire string matches a syntax item you must supply the
anchors yourself.
=over
=item $module_name_rx
Matches a valid Perl module name in bareword syntax.
=cut
our $module_name_rx = qr/[A-Z_a-z][0-9A-Z_a-z]*(?:::[0-9A-Z_a-z]+)*/;
=item $top_module_spec_rx
Matches a module specification for use with L</compose_module_name>,
where no prefix is being used.
=cut
my $qual_module_spec_rx =
qr#(?:/|::)[A-Z_a-z][0-9A-Z_a-z]*(?:(?:/|::)[0-9A-Z_a-z]+)*#;
my $unqual_top_module_spec_rx =
qr#[A-Z_a-z][0-9A-Z_a-z]*(?:(?:/|::)[0-9A-Z_a-z]+)*#;
our $top_module_spec_rx = qr/$qual_module_spec_rx|$unqual_top_module_spec_rx/o;
=item $sub_module_spec_rx
Matches a module specification for use with L</compose_module_name>,
where a prefix is being used.
=cut
my $unqual_sub_module_spec_rx = qr#[0-9A-Z_a-z]+(?:(?:/|::)[0-9A-Z_a-z]+)*#;
our $sub_module_spec_rx = qr/$qual_module_spec_rx|$unqual_sub_module_spec_rx/o;
=back
=head1 FUNCTIONS
=head2 Basic module handling
=over
( run in 0.434 second using v1.01-cache-2.11-cpan-39bf76dae61 )