1Module::Implementation(U3s)er Contributed Perl DocumentatMioodnule::Implementation(3)
2
3
4

NAME

6       Module::Implementation - Loads one of several alternate underlying
7       implementations for a module
8

VERSION

10       version 0.06
11

SYNOPSIS

13         package Foo::Bar;
14
15         use Module::Implementation;
16
17         BEGIN {
18             my $loader = Module::Implementation::build_loader_sub(
19                 implementations => [ 'XS',  'PurePerl' ],
20                 symbols         => [ 'run', 'check' ],
21             );
22
23             $loader->();
24         }
25
26         package Consumer;
27
28         # loads the first viable implementation
29         use Foo::Bar;
30

DESCRIPTION

32       This module abstracts out the process of choosing one of several
33       underlying implementations for a module. This can be used to provide XS
34       and pure Perl implementations of a module, or it could be used to load
35       an implementation for a given OS or any other case of needing to
36       provide multiple implementations.
37
38       This module is only useful when you know all the implementations ahead
39       of time. If you want to load arbitrary implementations then you
40       probably want something like a plugin system, not this module.
41

API

43       This module provides two subroutines, neither of which are exported.
44
45   Module::Implementation::<build_loader_sub(...)
46       This subroutine takes the following arguments.
47
48       ·   implementations
49
50           This should be an array reference of implementation names. Each
51           name should correspond to a module in the caller's namespace.
52
53           In other words, using the example in the "SYNOPSIS", this module
54           will look for the "Foo::Bar::XS" and "Foo::Bar::PurePerl" modules
55           will be installed
56
57           This argument is required.
58
59       ·   symbols
60
61           A list of symbols to copy from the implementation package to the
62           calling package.
63
64           These can be prefixed with a variable type: "$", "@", "%", "&", or
65           "*)". If no prefix is given, the symbol is assumed to be a
66           subroutine.
67
68           This argument is optional.
69
70       This subroutine returns the implementation loader as a sub reference.
71
72       It is up to you to call this loader sub in your code.
73
74       I recommend that you do not call this loader in an "import()" sub. If a
75       caller explicitly requests no imports, your "import()" sub will not be
76       run at all, which can cause weird breakage.
77
78   Module::Implementation::implementation_for($package)
79       Given a package name, this subroutine returns the implementation that
80       was loaded for the package. This is not a full package name, just the
81       suffix that identifies the implementation. For the "SYNOPSIS" example,
82       this subroutine would be called as
83       "Module::Implementation::implementation_for('Foo::Bar')", and it would
84       return "XS" or "PurePerl".
85

HOW THE IMPLEMENTATION LOADER WORKS

87       The implementation loader works like this ...
88
89       First, it checks for an %ENV var specifying the implementation to load.
90       The env var is based on the package name which loads the
91       implementations. The "::" package separator is replaced with "_", and
92       made entirely upper-case. Finally, we append "_IMPLEMENTATION" to this
93       name.
94
95       So in our "SYNOPSIS" example, the corresponding %ENV key would be
96       "FOO_BAR_IMPLEMENTATION".
97
98       If this is set, then the loader will only try to load this one
99       implementation.
100
101       If the env var requests an implementation which doesn't match one of
102       the implementations specified when the loader was created, an error is
103       thrown.
104
105       If this one implementation fails to load then loader throws an error.
106       This is useful for testing. You can request a specific implementation
107       in a test file by writing something like this:
108
109         BEGIN { $ENV{FOO_BAR_IMPLEMENTATION} = 'XS' }
110         use Foo::Bar;
111
112       If the environment variable is not set, then the loader simply tries
113       the implementations originally passed to "Module::Implementation". The
114       implementations are tried in the order in which they were originally
115       passed.
116
117       The loader will use the first implementation that loads without an
118       error. It will copy any requested symbols from this implementation.
119
120       If none of the implementations can be loaded, then the loader throws an
121       exception.
122
123       The loader returns the name of the package it loaded.
124

AUTHOR

126       Dave Rolsky <autarch@urth.org>
127
129       This software is Copyright (c) 2012 by Dave Rolsky.
130
131       This is free software, licensed under:
132
133         The Artistic License 2.0 (GPL Compatible)
134
135
136
137perl v5.16.3                      2012-02-12         Module::Implementation(3)
Impressum