File Coverage

blib/lib/Module/Build/Pluggable/CPANfile.pm
Criterion Covered Total %
statement 48 51 94.1
branch 14 20 70.0
condition 8 13 61.5
subroutine 9 9 100.0
pod 0 1 0.0
total 79 94 84.0


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