$Dist::Zilla::Plugin::DynamicPrereqs::Meta::VERSION
=
'0.003'
;
use
5.020;
my
$coder
= Cpanel::JSON::XS->new->pretty;
sub
mvp_multivalue_args {
return
qw/conditions prereqs/
;
}
sub
mvp_aliases {
return
{
condition
=>
'conditions'
,
prereq
=>
'prereqs'
,
};
}
has
filename
=> (
is
=>
'ro'
,
isa
=> Str,
default
=>
'dynamic-prereqs.json'
,
);
has
joiner
=> (
is
=>
'ro'
,
isa
=> Str,
default
=>
'and'
,
);
has
input_conditions
=> (
init_arg
=>
'conditions'
,
required
=> 1,
isa
=> ArrayRef[Str],
traits
=> [
'Array'
],
handles
=> {
input_conditions
=>
'elements'
,
},
);
sub
condition(
$self
) {
my
@conditions
=
map
{ [ shellwords(
$_
) ] }
$self
->input_conditions;
return
@conditions
== 1 ?
$conditions
[0] : [
$self
->joiner,
@conditions
];
}
has
input_prereqs
=> (
init_arg
=>
'prereqs'
,
traits
=> [
'Array'
],
isa
=> ArrayRef,
handles
=> {
input_prereqs
=>
'elements'
,
},
);
sub
prereqs(
$self
) {
my
%result
;
for
my
$line
(
$self
->input_prereqs) {
my
(
$module
,
$version
) =
split
' '
,
$line
, 2;
$version
//= 0;
$result
{
$module
} =
$version
;
}
return
\
%result
;
}
has
error
=> (
is
=>
'ro'
,
isa
=> Str,
);
has
phase
=> (
is
=>
'ro'
,
isa
=> Str,
default
=>
'runtime'
,
);
has
relationship
=> (
is
=>
'ro'
,
isa
=> Str,
default
=>
'requires'
,
);
sub
metadata {
my
(
$self
) =
@_
;
my
%entry
= (
condition
=>
$self
->condition );
$entry
{phase} =
$self
->phase
if
$self
->phase ne
'runtime'
;
$entry
{relationship} =
$self
->relationship
if
$self
->relationship ne
'requires'
;
if
(
$self
->error) {
$entry
{error} =
$self
->error;
}
else
{
$entry
{prereqs} =
$self
->prereqs;
}
return
{
x_dynamic_prereqs
=> {
version
=> 1,
expressions
=> [
\
%entry
],
},
};
}
sub
register_prereqs(
$self
) {
$self
->zilla->register_prereqs({
phase
=>
'configure'
},
'CPAN::Requirements::Dynamic'
=> 0);
return
;
}
1;