use
5.008;
our
$VERSION
=
'0.002002'
;
our
$AUTHORITY
=
'cpan:KENTNL'
;
use
Moose
qw( has around with )
;
has
conditions
=> (
is
=>
'ro'
,
lazy_build
=> 1 );
sub
_build_conditions {
return
[] }
around
dump_config
=>
sub
{
my
(
$orig
,
$self
,
@args
) =
@_
;
my
$config
=
$self
->
$orig
(
@args
);
my
$localconf
=
$config
->{ +__PACKAGE__ } = {};
$localconf
->{conditions} =
$self
->conditions;
$localconf
->{
q[$]
. __PACKAGE__ .
'::VERSION'
} =
$VERSION
unless
__PACKAGE__ eq
ref
$self
;
return
$config
;
};
around
mvp_aliases
=>
sub
{
my
(
$orig
,
$self
,
@rest
) =
@_
;
my
$hash
=
$self
->
$orig
(
@rest
);
$hash
= {
%{
$hash
},
q{?}
=>
'conditions'
,
q[condition]
=>
'conditions'
,
};
return
$hash
;
};
around
mvp_multivalue_args
=>
sub
{
my
(
$orig
,
$self
,
@args
) =
@_
;
return
(
qw( conditions )
,
$self
->
$orig
(
@args
) );
};
sub
check_conditions {
my
(
$self
) =
@_
;
my
$env
= {};
$env
->{
q[$root]
} = \
$self
->zilla->root;
$env
->{
q[$zilla]
} = \
$self
->zilla;
my
$code
=
join
q[ and ]
, @{
$self
->conditions },
q[1]
;
my
$closure
= eval_closure(
source
=>
qq[sub { \n]
.
$code
.
qq[ }\n]
,
environment
=>
$env
,
);
return
!
$closure
->();
}
around
'load_plugins'
=>
sub
{
my
(
$orig
,
$self
,
$loader
) =
@_
;
return
unless
$self
->check_conditions;
return
$self
->
$orig
(
$loader
);
};
no
Moose;
__PACKAGE__->meta->make_immutable;
1;