package Dist::Zilla::Plugin::PerlVersionPrereqs; use Moose; # ABSTRACT: set additional prereqs for older perls with 'Dist::Zilla::Role::InstallTool', 'Dist::Zilla::Role::MetaProvider'; =head1 SYNOPSIS ; dist.ini [PerlVersionPrereqs / 5.010] Perl6::Say = 0 =head1 DESCRIPTION When perl gets new features, oftentimes they are reimplemented as CPAN modules for earlier perls which don't have those features. It's a bit silly to unconditionally depend on those backwards compatiblity modules if they are just going to do nothing at all on the version of perl you're installing them on though, so this module allows you to specify that certain dependencies aren't required on perls newer than a certain version. NOTE: This plugin only works on dists that are using the default C<[MakeMaker]> plugin. =cut has prereq_perl_version => ( is => 'ro', isa => 'Str', lazy => 1, default => sub { my $self = shift; return $self->plugin_name; }, ); has _prereqs => ( is => 'ro', isa => 'HashRef[Str]', required => 1, ); sub BUILDARGS { my $class = shift; my $opts = $class->SUPER::BUILDARGS(@_); my $zilla = delete $opts->{zilla}; my $plugin_name = delete $opts->{plugin_name}; my %extra = map { $_ => delete $opts->{$_} } grep { /^\W/ } keys %$opts; return { zilla => $zilla, plugin_name => $plugin_name, _prereqs => $opts, %extra, }; } sub setup_installer { my $self = shift; my $perl_version = $self->prereq_perl_version; confess "You must specify a perl version" unless $perl_version; my ($makefile_pl) = grep { $_->name eq 'Makefile.PL' } @{ $self->zilla->files }; confess "This plugin only supports [MakeMaker]" unless $makefile_pl; my $prereqs = $self->_prereqs; return unless keys %$prereqs; my $content = $makefile_pl->content; my $prereq_string = join("\n ", map { qq["$_" => "$prereqs->{$_}",] } keys %$prereqs); my $extra_content = <content($content); } sub metadata { return { dynamic_config => 1 }; } around dump_config => sub { my $orig = shift; my $self = shift; my $config = $self->$orig(@_); $config->{''.__PACKAGE__} = { perl_version => $self->prereq_perl_version, }; return $config; }; __PACKAGE__->meta->make_immutable; no Moose; =head1 BUGS No known bugs. Please report any bugs through RT: email C, or browse to L. =head1 SEE ALSO L This plugin is based heavily on code from the C<[OSPrereqs]> plugin. =head1 SUPPORT You can find this documentation for this module with the perldoc command. perldoc Dist::Zilla::Plugin::PerlVersionPrereqs You can also look for information at: =over 4 =item * MetaCPAN L =item * RT: CPAN's request tracker L =item * Github L =item * CPAN Ratings L =back =begin Pod::Coverage metadata setup_installer =end Pod::Coverage =cut 1;