info > Module::Runtime

Not found locally for Module::Runtime. Try Google search

📛 NAME

Module::Runtime - runtime module handling

🚀 Quick Reference

Use CaseCommandDescription
Check valid module nameis_module_name($name)✅ Returns true if $name is a valid Perl module name
Load a module at runtimerequire_module("Data::Dumper")📦 Same as require Data::Dumper but at runtime
Use a module and call constructoruse_module("Math::BigInt", 1.31)->new("1_234")🧩 Loads module, checks version, returns class name
Generate notional filenamemodule_notional_filename("Foo::Bar")📄 Returns Foo/Bar.pm
Compose a module name from speccompose_module_name("Prefix", "Sub::Name")🔗 Combines prefix and spec, supports / separator
Optimistic package loadinguse_package_optimistically("Local::Widget")⚠️ Tries to load module; if fails, assumes package already exists

📖 SYNOPSIS

use Module::Runtime qw(
    $module_name_rx is_module_name check_module_name
    module_notional_filename require_module);

if($module_name =~ /\A$module_name_rx\z/o) { ...
if(is_module_name($module_name)) { ...
check_module_name($module_name);

$notional_filename = module_notional_filename($module_name);
require_module($module_name);

use Module::Runtime qw(use_module use_package_optimistically);

$bi = use_module("Math::BigInt", 1.31)->new("1_234");
$widget = use_package_optimistically("Local::Widget")->new;

use Module::Runtime qw(
    $top_module_spec_rx $sub_module_spec_rx
    is_module_spec check_module_spec
    compose_module_name);

if($spec =~ /\A$top_module_spec_rx\z/o) { ...
if($spec =~ /\A$sub_module_spec_rx\z/o) { ...
if(is_module_spec("Standard::Prefix", $spec)) { ...
check_module_spec("Standard::Prefix", $spec);

$module_name = compose_module_name("Standard::Prefix", $spec);

📝 DESCRIPTION

The functions exported by this module deal with runtime handling of Perl modules, which are normally handled at compile time. This module avoids using any other modules, so that it can be used in low-level infrastructure.

The parts of this module that work with module names apply the same syntax that is used for barewords in Perl source. In principle this syntax can vary between versions of Perl, and this module applies the syntax of the Perl on which it is running. In practice the usable syntax hasn't changed yet. There's some intent for Unicode module names to be supported in the future, but this hasn't yet amounted to any consistent facility.

The functions of this module whose purpose is to load modules include workarounds for three old Perl core bugs regarding require. These workarounds are applied on any Perl version where the bugs exist, except for a case where one of the bugs cannot be adequately worked around in pure Perl.

🏷️ Module name syntax

The usable module name syntax has not changed from Perl 5.000 up to Perl 5.19.8. The syntax is composed entirely of ASCII characters. From Perl 5.6 onwards there has been some attempt to allow the use of non-ASCII Unicode characters in Perl source, but it was fundamentally broken (like the entirety of Perl 5.6's Unicode handling) and remained pretty much entirely unusable until it got some attention in the Perl 5.15 series. Although Unicode is now consistently accepted by the parser in some places, it remains broken for module names. Furthermore, there has not yet been any work on how to map Unicode module names into filenames, so in that respect also Unicode module names are unusable.

The module name syntax is, precisely: the string must consist of one or more segments separated by ::; each segment must consist of one or more identifier characters (ASCII alphanumerics plus _); the first character of the string must not be a digit. Thus IO::File, warnings, and foo::123::x_0 are all valid module names, whereas IO:: and 1foo::bar are not. ' separators are not permitted by this module, though they remain usable in Perl source, being translated to :: in the parser.

🐞 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 required/used 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 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 %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 %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 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.

🔍 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.

🔧 FUNCTIONS

📦 Basic module handling

🧩 Structured module use

🧩 Module name composition

🐛 BUGS

On Perl versions 5.7.2 to 5.8.8, if require is overridden by the CORE::GLOBAL mechanism, it is likely to break the heuristics used by use_package_optimistically, making it signal an error for a missing module rather than assume that it was already loaded. From Perl 5.8.9 onwards, and on 5.7.1 and earlier, this module can avoid being confused by such an override. On the affected versions, a require override might be installed by Lexical::SealRequireHints, if something requires its bugfix but for some reason its XS implementation isn't available.

👀 SEE ALSO

Lexical::SealRequireHints, base, require in perlfunc, use in perlfunc

✍️ AUTHOR

Andrew Main (Zefram) <zefram AT fysh.org>

© COPYRIGHT

Copyright (C) 2004, 2006, 2007, 2009, 2010, 2011, 2012, 2014, 2017 Andrew Main (Zefram) <zefram AT fysh.org>

⚖️ LICENSE

This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

perl v5.26.1 2018-01-02 Module::Runtime(3pm)

Module::Runtime
📛 NAME 🚀 Quick Reference 📖 SYNOPSIS 📝 DESCRIPTION
🏷️ Module name syntax 🐞 Core bugs worked around
🔍 REGULAR EXPRESSIONS 🔧 FUNCTIONS
📦 Basic module handling 🧩 Structured module use 🧩 Module name composition
🐛 BUGS 👀 SEE ALSO ✍️ AUTHOR © COPYRIGHT ⚖️ LICENSE

Generated by phpman v4.10.0-7-g98e9fd5 Author: Che Dong Under GNU General Public License
2026-09-07 01:36 @2600:1f28:365:80b0:6da3:f3b7:3cc7:cae0
CrawledBy CCBot/2.0 (https://commoncrawl.org/faq/)
Valid XHTML 1.0 Transitional!Valid CSS!