Dist::Zilla::Plugin::DynamicPrereqs - Specify dynamic (user-side) prerequisites for your distribution
version 0.018
In your dist.ini:
[DynamicPrereqs] -condition = has_module('Role::Tiny') -condition = !parse_args()->{PUREPERL_ONLY} -condition = can_xs() -body = requires('Role::Tiny', '1.003000')
or:
[DynamicPrereqs] -delimiter = | -raw = |test_requires('Devel::Cover') -raw = | if $ENV{EXTENDED_TESTING} or is_smoker(); -include_sub = is_smoker
[DynamicPrereqs] -raw_from_file = Makefile.args # code snippet in this file
This is a Dist::Zilla plugin that inserts code into your Makefile.PL to indicate dynamic (installer-side) prerequisites.
Code is inserted immediately after the declarations for %WriteMakefileArgs and %FallbackPrereqs, before they are conditionally modified (when an older ExtUtils::MakeMaker is installed). This gives you an opportunity to add to the WriteMakefile arguments: PREREQ_PM, BUILD_REQUIRES, and TEST_REQUIRES, and therefore modify the prerequisites in the user's MYMETA.yml and MYMETA.json based on conditions found on the user's system.
%WriteMakefileArgs
%FallbackPrereqs
WriteMakefile
PREREQ_PM
BUILD_REQUIRES
TEST_REQUIRES
The dynamic_config field in metadata is already set for you.
dynamic_config
You could potentially use this plugin for performing other modifications in Makefile.PL other than user-side prerequisite modifications, but I can't think of a situation where this makes sense. Contact me if you have any ideas!
Only Makefile.PL modification is supported at this time. This author considers the use of Module::Build to be questionable in all circumstances, and Module::Build::Tiny does not (yet?) support dynamic configuration.
You are urged to check the generated Makefile.PL for sanity, and to run it at least once to validate its syntax. Although every effort is made to generate valid and correct code, mistakes can happen, so verification is needed before shipping.
Please also see the other warnings later in this document.
-raw
-body
The code to be inserted; must be valid and complete perl statements. You can reference and modify the already-declared %WriteMakefileArgs and %FallbackPrereqs variables, as inserted into Makefile.PL by Dist::Zilla::Plugin::MakeMaker and subclasses (e.g. Dist::Zilla::Plugin::MakeMaker::Awesome since Dist::Zilla 5.001.
5.001
This option can be used more than once; lines are added in the order in which they are provided.
If you use external libraries in the code you are inserting, you must add these modules to configure_requires prereqs in metadata (e.g. via [Prereqs / ConfigureRequires] in your dist.ini).
configure_requires
[Prereqs / ConfigureRequires]
-body first became available in version 0.018.
-delimiter
(Available since version 0.007)
A string, usually a single character, which is stripped from the beginning of all -raw/-body lines. This is because the INI file format strips all leading whitespace from option values, so including this character at the front allows you to use leading whitespace in an option string, so you can indent blocks of code properly.
-raw_from_file
(Available since version 0.010)
-body_from_file
(Available since version 0.018)
A filename that contains the code to be inserted; must be valid and complete perl statements, as with -raw/-body above. This file must be part of the build, but it is pruned from the built distribution.
-condition
(Available since version 0.014)
A perl expression to be included in the condition statement in the Makefile.PL. Multiple -conditions can be provided, in which case they are ANDed together to form the final condition statement. (You must appropriately parenthesize each of your conditions to ensure correct order of operations.) Any use of recognized subroutines will cause their definitions to be included automatically (see "AVAILABLE SUBROUTINE DEFINITIONS", below).
When combined with -raw/-body lines, the condition is placed first in a if statement, and the -raw/-body lines are contained as the body of the block. For example:
if
[DynamicPrereqs] -condition = $] > '5.020' -body = requires('1.003000')
results in the Makefile.PL snippet:
if ($] > '5.020') { requires('Role::Tiny', '1.003000') }
-include_sub
(Available since version 0.010; rendered unnecessary in 0.016 (all definitions are now included automatically, when used).
A number of helper subroutines are available for use within your code inserted via -body, -body_from_file, -raw, -raw_from_file, or -condition clauses. When used, their definition(s) will be included automatically in Makefile.PL (as well as those of any other subroutines they call); necessary prerequisite modules will be added to configure requires metadata.
configure requires
Unless otherwise noted, these all became available in version 0.010. Available subs are:
prompt_default_yes($message) - takes a string (appending "[Y/n]" to it), returns a boolean; see "prompt" in ExtUtils::MakeMaker
prompt_default_yes($message)
prompt_default_no($message) - takes a string (appending "[y/N]" to it), returns a boolean; see "prompt" in ExtUtils::MakeMaker
prompt_default_no($message)
parse_args() - returns the hashref of options that were passed as arguments to perl Makefile.PL
parse_args()
perl Makefile.PL
can_xs() - Secondary compile testing via ExtUtils::CBuilder
can_xs()
can_cc() - can we locate a (the) C compiler
can_cc()
can_run() - check if we can run some command
can_run()
can_use($module, $version (optional)) - checks if a module (optionally, at a specified version) can be loaded. (If you don't want to load the module, you should use has_module, see below.)
can_use($module, $version (optional))
has_module
has_module($module, $version_or_range (optional)) - checks if a module (optionally, at a specified version or matching a version range) is available in %INC. Does not load the module, so is safe to use with modules that have side effects when loaded. When passed a second argument, returns true or false; otherwise, returns undef or the module's $VERSION. (Current API available since version 0.015.)
has_module($module, $version_or_range (optional))
%INC
$VERSION
is_smoker() - is the installation on a smoker machine?
is_smoker()
is_interactive() - is the installation in an interactive terminal?
is_interactive()
is_trial() - is the release a -TRIAL or _XXX-versioned release?
is_trial()
is_os($os, ...) - true if the OS is any of those listed
is_os($os, ...)
isnt_os($os, ...) - true if the OS is none of those listed
isnt_os($os, ...)
maybe_command - actually a monkeypatch to MM->maybe_command (please keep using the fully-qualified form) to work in Cygwin
maybe_command
MM->maybe_command
runtime_requires($module, $version (optional)) - adds the module to runtime prereqs (as a shorthand for editing the hashes in Makefile.PL directly). Added in 0.016.
runtime_requires($module, $version (optional))
requires($module, $version (optional)) - alias for runtime_requires. Added in 0.016.
requires($module, $version (optional))
runtime_requires
build_requires($module, $version (optional)) - adds the module to runtime prereqs (as a shorthand for editing the hashes in Makefile.PL directly). Added in 0.016.
build_requires($module, $version (optional))
test_requires($module, $version (optional)) - adds the module to runtime prereqs (as a shorthand for editing the hashes in Makefile.PL directly). Added in 0.016.
test_requires($module, $version (optional))
The implementations for some subroutines (in particular, can_xs, can_cc and can_run are still incomplete, incompatible with some architectures and cannot yet be considered a suitable generic solution. Until we are more confident in their implementations, a warning will be printed upon use, and their use is not advised without prior consultation with the author.
can_xs
can_cc
can_run
This plugin is still undergoing active development, and the interfaces will change and grow as I work through the proper way to do various things. As I make changes, I will be using metacpan's reverse dependencies list and http://grep.cpan.me to find and fix any upstream users, but I obviously cannot do this for DarkPAN users. Regardless, please contact me (see below) and I will keep you directly advised of interface changes.
Future options may include:
-phase the phase in which subsequently-specified module/version pairs will be added
-phase
-runtime a module and version that is added to runtime prereqs should the -condition be satisfied
-runtime
-test a module and version that is added to test prereqs should the -condition be satisfied
-test
-build a module and version that is added to build prereqs should the -condition be satisfied
-build
Dist::Zilla::Plugin::MakeMaker
"Using Attributes and Parameters" in ExtUtils::MakeMaker
Dist::Zilla::Plugin::OSPrereqs
Dist::Zilla::Plugin::PerlVersionPrereqs
Module::Install::Can
Bugs may be submitted through the RT bug tracker (or bug-Dist-Zilla-Plugin-DynamicPrereqs@rt.cpan.org).
There is also a mailing list available for users of this distribution, at http://dzil.org/#mailing-list.
There is also an irc channel available for users of this distribution, at irc://irc.perl.org/#distzilla.
I am also usually active on irc, as 'ether' at irc.perl.org.
irc.perl.org
Karen Etheridge <ether@cpan.org>
This software is copyright (c) 2014 by Karen Etheridge.
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 Dist::Zilla::Plugin::DynamicPrereqs, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Dist::Zilla::Plugin::DynamicPrereqs
CPAN shell
perl -MCPAN -e shell install Dist::Zilla::Plugin::DynamicPrereqs
For more information on module installation, please visit the detailed CPAN module installation guide.