CPAN::Requirements::Dynamic(3) User Contributed Perl Documentation CPAN::Requirements::Dynamic(3)

CPAN::Requirements::Dynamic - Dynamic prerequisites in meta files

version 0.002

my $result = $dynamic->evaluate({
  expressions => [
    {
      condition => [ 'has_perl' => 'v5.20.0' ],
      prereqs => { Bar => "1.3" },
    },
    {
      condition => [ is_os => 'linux' ],
      prereqs => { Baz => "1.4" },
    },
    {
      condition => [ config_defined => 'usethreads' ],
      prereqs => { Quz => "1.5" },
    },
    {
      condition => [ and =>
        [ config_defined => 'usethreads' ],
        [ is_os => 'openbsd' ],
      ],
      prereqs => { Euz => "1.7" },
    },
    {
      condition => [ not => is_os_type => 'Unix'],
      error => 'OS unsupported',
    },
  ],
});

This module implements a format for describing dynamic prerequisites of a distribution.

This constructor takes two (optional but recommended) named arguments

  • config

    This is an ExtUtils::Config (compatible) object for reading configuration.

  • pureperl_only

    This should be the value of the "pureperl-only" flag.

This takes a hash with two named arguments: "version" and "expressions". The former is the version of the format, it currently defaults to 1. The latter is a list of hashes that can contain the following keys:

  • condition

    The condition of the dynamic requirement. This is an array with a name as first values and zero or more arguments following it. The semantics are described below under "Conditions"

  • prereqs

    The prereqs is a hash with modules for keys and the required version as values (e.g. "{ Foo => '1.234' }").

  • phase

    The phase of the requirements. This defaults to 'runtime'. Other valid values include 'build' and 'test'.

  • relation

    The relation of the requirements. This defaults to 'requires', but other valid values include 'recommends', 'suggests' and 'conflicts'.

  • error

    It will die with this error if set. The two messages "No support for OS" and "OS unsupported" have special meaning to CPAN Testers and are generally encouraged for situations that indicate not a failed build but an impossibility to build.

"condition" and one of "prereqs" or "error" are mandatory.

This takes a filename, that can be either a YAML file or a JSON file, and evaluates it.

can_run($command)

Returns true if a $command can be run.

config_defined($variable)

This returns true if a specific configuration variable is defined.

has_env($variable)

This returns true if the environmental variable with the name in $variable is true.

has_perl($version)

Returns true if the perl version satisfies $version. $version is interpreted exactly as in the CPAN::Meta spec (e.g. 1.2 equals '>= 1.2').

is_extended

Returns true if extended testing is asked for.

is_os(@systems)

Returns true if the OS name equals any of @systems.

is_os_type($type)

Returns true if the OS type equals $type. Typical values of $type are 'Unix' or 'Windows'.

is_smoker

Returns true when running on a smoker.

has_env

This returns true if the given environmental variable is true.

want_xs

This returns true if a compiler appears to be available, and the "pureperl_only" option has not been set.

not

This takes an expression and negates its value.

or

This takes list of arrayrefs, each containing a condition expression. If at least one of the conditions is true this will also return true.

and

This takes a list of arrayrefs, each containing a condition expression. If all of the conditions are true this will also return true.

Leon Timmermans <fawaka@gmail.com>

This software is copyright (c) 2023 by Leon Timmermans.

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

2025-05-18 perl v5.40.2