NAME

Sub::Spec::Clause::deps - Specify subroutine dependencies

VERSION

version 0.06

SYNOPSIS

In your spec:

deps => {
    DEPCLAUSE => DEPVALUE,
    ...,
    all => [
        {DEPCLAUSE=>DEPVALUE, ...},
        ...,
    },
    any => [
        {DEPCLAUSE => DEPVALUE, ...},
        ...,
    ],
    none => [
        {DEPCLAUSE => DEPVALUE, ...},
        ....,
    ],
}

DESCRIPTION

Th 'deps' clause adds information about subroutine dependency. It is extensible so you can specify anything as a dependency, be it another subroutine, Perl version and modules, environment variables, etc. It is up to some implementor to make use of this information.

The 'deps' clause is used, for example, by Sub::Spec::Runner to run subroutine in dependency order.

Dependencies are specified as a hash of clauses:

{
   DEPCLAUSE     => DEPVALUE,
   ANOTHERCLAUSE => VALUE,
   ...
 }

All of the clauses must be satisfied in order for the dependencies to be declared a success.

Below is the list of defined dependency clauses. New dependency clause may be defined by providing Sub::Spec::Clause::deps::check_<CLAUSE>().

sub => STR

Require that subroutine exists. STR is the name of the subroutine and will be assumed to be in the 'main' package if unqualified.

Example:

sub => 'foo'   # == main::foo
sub => '::foo' # == main::foo
sub => 'Package::foo'

mod => STR

Require that module is loadable. Example:

mod => 'Moo'

env => STR

Require that an environment variable exists and has a true value. Example:

env => 'HTTPS'

exec => STR

Require that an executable exists. If STR doesn't contain path separator character '/' it will be searched in PATH.

exec => 'rsync'   # any rsync found on PATH
exec => '/bin/su' # won't accept any other su

code => CODEREF

Require that CODEREF returns a true value after called. Example:

code => sub {$>}  # i am not being run as root

all => [DEPCLAUSES, ...]

A "meta" clause that allows several dependencies to be joined together in a logical-AND fashion. All dependencies must be satisfied. For example, to declare a dependency to several subroutines:

all => [
    {sub => 'Package::foo1'},
    {sub => 'Package::foo2'},
    {sub => 'Another::Package::bar'},
],

any => [DEPCLAUSES, ...]

Like 'all', but specify a logical-OR relationship. Any one of the dependencies will suffice. For example, to specify requirement to alternative modules:

or => [
    {mod => 'HTTP::Daemon'},
    {mod => 'HTTP::Daemon::SSL'},
],

none => [DEPCLAUSES, ...]

Specify that none of the dependencies must be satisfied for this clause to be satisfied. Example, to specify that the subroutine not run under SUDO or by root:

none => [
    {env  => 'SUDO_USER'},
    {code => sub {$> != 0} },
],

Note that the above is not equivalent to below:

none => [
    {env => 'SUDO_USER', code => sub {$> != 0} },
],

which means that if none or only one of 'env'/'code' is satisfied, the whole dependency becomes a success (since it is negated by 'none'). Probably not what you want.

SEE ALSO

Sub::Spec

AUTHOR

Steven Haryanto <stevenharyanto@gmail.com>

COPYRIGHT AND LICENSE

This software is copyright (c) 2011 by Steven Haryanto.

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