1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124
|
package Module::Build::Pluggable::CPANfile;
use strict;
use warnings;
use 5.008005;
use parent qw/Module::Build::Pluggable::Base/;
use Module::CPANfile;
use version;
use List::Util;
our $VERSION = '0.05';
require Module::Build;
my $support_test_requries =
( version->parse($Module::Build::VERSION) >= version->parse('0.4004') ) ? 1 : 0;
sub HOOK_prepare {
my $self = shift;
my $args = shift;
my @phases = qw/configure build devel test runtime/;
my %copy_prereqs = $support_test_requries ?
(
'configure_requires' => [qw/configure/],
'build_requires' => [qw/build/],
'test_requires' => [qw/test/],
'requires' => [qw/runtime/]
) :
(
'configure_requires' => [qw/configure/],
'build_requires' => [qw/build test/],
'requires' => [qw/runtime/]
);
my $file = Module::CPANfile->load("cpanfile");
my $prereq = $file->prereq_specs;
if ( !$support_test_requries && exists $prereq->{test} ) {
warn("[INFO] Module::Build < 0.4004 does not support test_requries. ",
"prereqs for test will be merged into build_requires\n");
}
for my $args_key ( keys %copy_prereqs ) {
my $requires = $args->{$args_key} || {};
for my $cpanfile_key ( @{$copy_prereqs{$args_key}} ) {
next if ! exists $prereq->{$cpanfile_key};
$requires = {
%$requires,
$prereq->{$cpanfile_key}->{requires} ? %{$prereq->{$cpanfile_key}->{requires}} : ()
};
my $unsupport = List::Util::first { exists $prereq->{$cpanfile_key}->{$_} }
qw/recommends suggests conflicts/;
if ( $cpanfile_key ne 'runtime' && $unsupport ) {
warn("[WARN] Module::Build does not support '$unsupport' prereqs type on $cpanfile_key phase\n");
}
if ( $cpanfile_key eq 'runtime' && exists $prereq->{$cpanfile_key}->{suggests} ) {
warn("[WARN] Module::Build does not support 'suggests' prereqs type on $cpanfile_key phase\n");
}
if ( $cpanfile_key eq 'runtime' ) {
for my $prereq_type ( qw/recommends conflicts/ ) {
$args->{$prereq_type} ||= {};
$args->{$prereq_type} = {
%{$args->{$prereq_type}},
$prereq->{$cpanfile_key}->{$prereq_type} ? %{$prereq->{$cpanfile_key}->{$prereq_type}} : ()
};
delete $args->{$prereq_type} if ! keys %{$args->{$prereq_type}};
}
}
}
$args->{$args_key} = $requires if keys %$requires;
}
}
1;
__END__
=encoding utf8
=head1 NAME
Module::Build::Pluggable::CPANfile - Include cpanfile
=head1 SYNOPSIS
# cpanfile
requires 'Plack', 0.9;
on test => sub {
requires 'Test::Warn';
};
# Build.PL
use Module::Build::Pluggable (
'CPANfile'
);
my $builder = Module::Build::Pluggable->new(
... # normal M::B args. but not required prereqs
);
$builder->create_build_script();
=head1 DESCRIPTION
Module::Build::Pluggable::CPANfile is plugin for Module::Build::Pluggable to include dependencies from cpanfile into meta files.
This modules is L<Module::Install::CPANfile> for Module::Build
B<THIS IS A DEVELOPMENT RELEASE. API MAY CHANGE WITHOUT NOTICE>.
=head1 AUTHOR
Masahiro Nagano E<lt>kazeburo@gmail.comE<gt>
=head1 SEE ALSO
L<Module::Install::CPANfile>, L<cpanfile>, L<Module::Build::Pluggable>
=head1 LICENSE
Copyright (C) Masahiro Nagano
This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.
=cut
|