/
CPANfile.pm
101 lines (71 loc) · 2.09 KB
/
CPANfile.pm
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
package Module::Install::CPANfile;
use strict;
use 5.008_001;
our $VERSION = '0.01';
use Module::CPANfile;
use base qw(Module::Install::Base);
sub cpanfile {
my $self = shift;
$self->include($_) for qw( Module::CPANfile Module::CPANfile::Environment Module::CPANfile::Result );
my $specs = Module::CPANfile->load->prereq_specs;
while (my($phase, $requirements) = each %$specs) {
while (my($type, $requirement) = each %$requirements) {
if (my $command = $self->command_for($phase, $type)) {
while (my($mod, $ver) = each %$requirement) {
$self->$command($mod, $ver);
}
}
}
}
}
sub command_for {
my($self, $phase, $type) = @_;
if ($type eq 'conflicts') {
warn 'conflicts is not supported';
return;
}
if ($phase eq 'develop') {
if ($INC{"Module/Install/AuthorRequires.pm"}) {
return 'author_requires';
} elsif ($Module::Install::AUTHOR) {
warn "develop phase is ignored unless Module::Install::AuthorRequires is installed.\n";
return;
} else {
return;
}
}
if ($type eq 'recommends' or $type eq 'suggests') {
return 'recommends';
}
return "${phase}_requires";
}
1;
__END__
=encoding utf-8
=for stopwords
=head1 NAME
Module::Install::CPANfile - Include cpanfile
=head1 SYNOPSIS
# cpanfile
requires 'Plack', 0.9;
on test => sub {
requires 'Test::Warn';
};
# Makefile.PL
use Module::Install;
cpanfile;
=head1 DESCRIPTION
Module::Install::CPANfile is a plugin for Module::Install to include
dependencies from L<cpanfile>.
Development requirement can only be checked if the developers has
installed L<Module::Install::AuthorRequires>.
=head1 AUTHOR
Tatsuhiko Miyagawa E<lt>miyagawa@bulknews.netE<gt>
=head1 COPYRIGHT
Copyright 2012- Tatsuhiko Miyagawa
=head1 LICENSE
This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.
=head1 SEE ALSO
L<cpanfile> L<Module::CPANfile> L<Module::Install>
=cut