use
5.008;
$Dist::Zilla::Plugin::Prereqs::Soften::VERSION
=
'0.001000'
;
our
$AUTHORITY
=
'cpan:KENTNL'
;
use
Moose
qw( with has around )
;
has
'modules'
=> (
is
=>
ro
=>,
isa
=> ArrayRef [Str],
lazy
=> 1,
default
=>
sub
{ [] },
);
has
'_modules_hash'
=> (
is
=>
ro
=>,
isa
=> HashRef,
lazy
=> 1,
builder
=>
_build__modules_hash
=>,
);
sub
mvp_multivalue_args {
return
qw(modules)
}
sub
mvp_aliases {
return
{
'module'
=>
'modules'
} }
sub
_build__modules_hash {
my
$self
=
shift
;
return
{
map
{ (
$_
, 1 ) } @{
$self
->modules } };
}
sub
_user_wants_softening_on {
my
(
$self
,
$module
) =
@_
;
return
exists
$self
->_modules_hash->{
$module
};
}
around
dump_config
=>
sub
{
my
(
$orig
,
$self
) =
@_
;
my
$config
=
$self
->
$orig
;
my
$this_config
= {
modules
=>
$self
->modules, };
$config
->{
q{}
. __PACKAGE__ } =
$this_config
;
return
$config
;
};
sub
_soften_prereqs {
my
(
$self
,
$conf
) =
@_
;
my
$prereqs
=
$self
->zilla->prereqs;
my
$source_reqs
=
$prereqs
->requirements_for(
$conf
->{from_phase},
$conf
->{from_relation} );
my
$target_reqs
=
$prereqs
->requirements_for(
$conf
->{to_phase},
$conf
->{to_relation} );
for
my
$module
(
$source_reqs
->required_modules ) {
next
unless
$self
->_user_wants_softening_on(
$module
);
my
$reqstring
=
$source_reqs
->requirements_for_module(
$module
);
$target_reqs
->add_string_requirement(
$module
,
$reqstring
);
$source_reqs
->clear_requirement(
$module
);
}
return
$self
;
}
sub
register_prereqs {
my
(
$self
) =
@_
;
for
my
$phase
(
qw( build test runtime )
) {
for
my
$relation
(
qw( requires )
) {
$self
->_soften_prereqs(
{
from_phase
=>
$phase
,
from_relation
=>
$relation
,
to_phase
=>
$phase
,
to_relation
=>
'recommends'
,
},
);
}
}
return
;
}
__PACKAGE__->meta->make_immutable;
no
Moose;
1;