Module::Spec::V2 - Load modules based on V2 specifications
version 0.9.0
use Module::Spec::V2 (); Module::Spec::V2::need_module('Mango~2.3');
This is alpha software. The API is likely to change.
As string
M M~V minimum match, ≥ V M~0 same as M, accepts any version
Example version specs are
2 2.3 2.3.4 v3.2.3
As a hash ref
{ M => V } minimum match, ≥ V { M => '0' } accepts any version
As an array ref
[ M ] [ M => V ] minimum match, ≥ V [ M => '0' ] same as [ M ], accepts any version
Module::Spec::V2 implements the following functions.
$module = need_module('SomeModule~2.3'); $module = need_module( { SomeModule => '2.3' } ); $module = need_module( [ SomeModule => '2.3' ] ); $module = need_module($spec); $module = need_module($spec, \%opts);
Loads a module and checks for a version requirement (if any). Returns the name of the loaded module.
On list context, returns the name of the loaded module and its version (as reported by $m->VERSION).
$m->VERSION
( $m, $v ) = need_module($spec); ( $m, $v ) = need_module($spec, \%opts);
These options are currently available:
require => 1 # default require => 0 require => sub { my ($m, @v) = @_; ... }
Controls whether the specified module should be required or not. It can be given as a non-subroutine value, which gets interpreted as a boolean: true means that the module should be loaded with require and false means that no attempt should be made to load it. This option can also be specified as a subroutine which gets passed the module name and version requirement (if any) and which should return true if the module should be loaded with require or false otherwise.
require
try => 0 # default try => 1
If try is true, it behaves as "try_module".
try
@modules = need_modules(@spec); @modules = need_modules(-all => @spec); @modules = need_modules(-any => @spec); @modules = need_modules(-oneof => @spec); @modules = need_modules(\%spec); @modules = need_modules(-all => \%spec); @modules = need_modules(-any => \%spec); @modules = need_modules(-oneof => \%spec);
Loads some modules according to a specified rule.
The current supported rules are -all, -any and -oneof. If none of these are given as the first argument, -all is assumed.
-all
-any
-oneof
The specified modules are given as module specs, either as a list or as a single hashref. If given as a list, the corresponding order will be respected. If given as a hashref, a random order is to be expected.
The behavior of the rules are as follows:
All specified modules are loaded by need_module. If successful, returns the names of the loaded modules.
need_module
All specified modules are loaded by try_module. Returns the names of the modules successfully loaded.
try_module
Specified modules are loaded by try_module until a successful load. Returns (in list context) the name of the loaded module.
$module = try_module('SomeModule~2.3'); $module = try_module( { SomeModule => '2.3' } ); $module = try_module( [ SomeModule => '2.3' ] ); $module = try_module($spec); $module = try_module($spec, \%opts);
Tries to load a module (if available) and checks for a version requirement (if any). Returns the name of the loaded module if it can be loaded successfully and satisfies any specified version requirement.
( $m, $v ) = try_module($spec); ( $m, $v ) = try_module($spec, \%opts);
@modules = try_modules(@spec); @modules = try_modules(\%spec);
Shortcut for
@modules = need_modules(-any => @spec); @modules = need_modules(-any => \%spec);
Single quotes (') are not accepted as package separators.
'
Exceptions are not thrown from the perspective of the caller.
Module::Runtime
Adriano Ferreira <ferreira@cpan.org>
This software is copyright (c) 2018 by Adriano Ferreira.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
To install Module::Spec, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Module::Spec
CPAN shell
perl -MCPAN -e shell install Module::Spec
For more information on module installation, please visit the detailed CPAN module installation guide.