{
    "mode": "perldoc",
    "parameter": "Module::Implementation",
    "section": "",
    "url": "https://www.chedong.com/phpMan.php/perldoc/Module%3A%3AImplementation/json",
    "generated": "2026-06-12T20:56:59Z",
    "synopsis": "package Foo::Bar;\nuse Module::Implementation;\nBEGIN {\nmy $loader = Module::Implementation::buildloadersub(\nimplementations => [ 'XS',  'PurePerl' ],\nsymbols         => [ 'run', 'check' ],\n);\n$loader->();\n}\npackage Consumer;\n# loads the first viable implementation\nuse Foo::Bar;",
    "sections": {
        "NAME": {
            "content": "Module::Implementation - Loads one of several alternate underlying implementations for a module\n",
            "subsections": []
        },
        "VERSION": {
            "content": "version 0.09\n",
            "subsections": []
        },
        "SYNOPSIS": {
            "content": "package Foo::Bar;\n\nuse Module::Implementation;\n\nBEGIN {\nmy $loader = Module::Implementation::buildloadersub(\nimplementations => [ 'XS',  'PurePerl' ],\nsymbols         => [ 'run', 'check' ],\n);\n\n$loader->();\n}\n\npackage Consumer;\n\n# loads the first viable implementation\nuse Foo::Bar;\n",
            "subsections": []
        },
        "DESCRIPTION": {
            "content": "This module abstracts out the process of choosing one of several underlying implementations for\na module. This can be used to provide XS and pure Perl implementations of a module, or it could\nbe used to load an implementation for a given OS or any other case of needing to provide\nmultiple implementations.\n\nThis module is only useful when you know all the implementations ahead of time. If you want to\nload arbitrary implementations then you probably want something like a plugin system, not this\nmodule.\n",
            "subsections": []
        },
        "API": {
            "content": "This module provides two subroutines, neither of which are exported.\n\nModule::Implementation::buildloadersub(...)\nThis subroutine takes the following arguments.\n\n*   implementations\n\nThis should be an array reference of implementation names. Each name should correspond to a\nmodule in the caller's namespace.\n\nIn other words, using the example in the \"SYNOPSIS\", this module will look for the\n\"Foo::Bar::XS\" and \"Foo::Bar::PurePerl\" modules.\n\nThis argument is required.\n\n*   symbols\n\nA list of symbols to copy from the implementation package to the calling package.\n\nThese can be prefixed with a variable type: \"$\", \"@\", \"%\", \"&\", or \"*)\". If no prefix is\ngiven, the symbol is assumed to be a subroutine.\n\nThis argument is optional.\n\nThis subroutine *returns* the implementation loader as a sub reference.\n\nIt is up to you to call this loader sub in your code.\n\nI recommend that you *do not* call this loader in an \"import()\" sub. If a caller explicitly\nrequests no imports, your \"import()\" sub will not be run at all, which can cause weird breakage.\n\nModule::Implementation::implementationfor($package)\nGiven a package name, this subroutine returns the implementation that was loaded for the\npackage. This is not a full package name, just the suffix that identifies the implementation.\nFor the \"SYNOPSIS\" example, this subroutine would be called as\n\"Module::Implementation::implementationfor('Foo::Bar')\", and it would return \"XS\" or\n\"PurePerl\".\n",
            "subsections": []
        },
        "HOW THE IMPLEMENTATION LOADER WORKS": {
            "content": "The implementation loader works like this ...\n\nFirst, it checks for an %ENV var specifying the implementation to load. The env var is based on\nthe package name which loads the implementations. The \"::\" package separator is replaced with\n\"\", and made entirely upper-case. Finally, we append \"IMPLEMENTATION\" to this name.\n\nSo in our \"SYNOPSIS\" example, the corresponding %ENV key would be \"FOOBARIMPLEMENTATION\".\n\nIf this is set, then the loader will only try to load this one implementation.\n\nIf the env var requests an implementation which doesn't match one of the implementations\nspecified when the loader was created, an error is thrown.\n\nIf this one implementation fails to load then loader throws an error. This is useful for\ntesting. You can request a specific implementation in a test file by writing something like\nthis:\n\nBEGIN { $ENV{FOOBARIMPLEMENTATION} = 'XS' }\nuse Foo::Bar;\n\nIf the environment variable is *not* set, then the loader simply tries the implementations\noriginally passed to \"Module::Implementation\". The implementations are tried in the order in\nwhich they were originally passed.\n\nThe loader will use the first implementation that loads without an error. It will copy any\nrequested symbols from this implementation.\n\nIf none of the implementations can be loaded, then the loader throws an exception.\n\nThe loader returns the name of the package it loaded.\n",
            "subsections": []
        },
        "AUTHOR": {
            "content": "Dave Rolsky <autarch@urth.org>\n",
            "subsections": []
        },
        "COPYRIGHT AND LICENSE": {
            "content": "This software is Copyright (c) 2014 by Dave Rolsky.\n\nThis is free software, licensed under:\n\nThe Artistic License 2.0 (GPL Compatible)\n",
            "subsections": []
        }
    },
    "summary": "Module::Implementation - Loads one of several alternate underlying implementations for a module",
    "flags": [],
    "examples": [],
    "see_also": []
}