28e54da70cec0d54c35f77b8c5a4b20afee63a2a
[gitmo/Mouse.git] / Makefile.PL
1 # COMPAT_TEST=1 genrates Moose compatible tests
2 # for developpers:
3 BEGIN{
4     if(grep{ $_ eq '--author' } @ARGV){
5         print "$^X -S cpanm < author/requires.cpanm\n";
6         system "$^X -S cpanm < author/requires.cpanm";
7     }
8 }
9
10 use strict;
11 use warnings;
12 BEGIN {
13         # author requires, or bundled modules
14     my @devmods = qw(
15         inc::Module::Install             1.00
16         Module::Install::TestTarget      0.13
17         Module::Install::AuthorTests     0.002
18         Module::Install::XSUtil          0.36
19                 Test::Exception::LessClever      0.005
20                 Test::Requires                   0.06
21     );
22     my @not_available;
23         while(my($mod, $ver) = splice @devmods, 0, 2) {
24         eval qq{use $mod $ver (); 1} or push @not_available, $mod;
25     }
26     if(@not_available) {
27         print qq{# The following modules are not available.\n};
28         print qq{# `perl $0 | cpanm` will install them:\n};
29         print $_, "\n" for @not_available;
30                 exit 1;
31      }
32 }
33 use inc::Module::Install;
34
35 all_from 'lib/Mouse.pm';
36
37 # Scalar::Util < 1.14 has a bug.
38 # > Fixed looks_like_number(undef) to return false for perl >= 5.009002
39 requires 'Scalar::Util' => 1.14;
40
41 test_requires 'Test::More' => 0.88;
42
43 # to keep zero-dependencies
44 include 'Test::Exception::LessClever';
45 include 'Test::Requires';
46
47 my %suggests = (
48     'Any::Moose'                     => 0.10,
49
50     'MouseX::AttributeHelpers'       => 0.06,
51     'MouseX::NativeTraits'           => 1.00,
52 );
53 while(my($mod, $least) = each %suggests){
54     my $status = system $^X, '-e', <<"CHECK";
55 if(eval q{ use $mod (); 1 }) {
56     if(eval q{ use $mod $least (); 1 }) {
57         exit 0; # installd, and new enough
58     }
59     else {
60         exit 1; # installed, but too old
61     }
62 }
63 CHECK
64
65     if($status != 0){
66         my $ver = `$^X -e "use $mod (); print $mod->VERSION"`;
67         warn("\n",
68             "WARNING: $mod is installed, but its version ($ver) is too old (< $least).\n",
69             "         Please update $mod after installation of Mouse.\n",
70             "\n"
71         );
72     }
73 }
74
75 # cc_want deals with the '--pp' and '--xs' options
76 my $use_xs = ($] >= 5.008_001 && want_xs());
77
78 if($use_xs){
79     print "Mouse configured with XS.\n";
80
81     use_ppport(3.19);
82     use_xshelper();
83     cc_warnings();
84     cc_src_paths('xs-src');
85 }
86     if($use_xs){
87         # repeat testing
88         # see also ExtUtils::MM_Any::test_via_harness()
89         my $t_pp =  q{$(FULLPERLRUN) -MExtUtils::Command::MM -e}
90                    .q{ "do 'tool/force-pp.pl'; test_harness($(TEST_VERBOSE), 'inc', '$(INST_LIB)', '$(INST_ARCHLIB)')"}
91                    .q{ $(TEST_FILES)} . "\n";
92
93         postamble qq{test_pp :: pure_all\n}
94                 . qq{\t} . $t_pp;
95         if($Module::Install::AUTHOR) {
96             postamble qq{test :: test_pp };
97         }
98     }
99 else{
100     print "Mouse configured with Pure Perl.\n";
101 }
102
103 tests 't/*.t t/*/*.t';
104 author_tests 'xt';
105
106 repository 'git://git.moose.perl.org/Mouse.git';
107
108 system($^X, 'tool/generate-mouse-tiny.pl', 'lib/Mouse/Tiny.pm') == 0
109     or warn "Cannot generate Mouse::Tiny: $!";
110 makemaker_args PL_FILES => {
111     'tool/generate-mouse-tiny.pl' => 'lib/Mouse/Tiny.pm',
112 };
113
114 if ($Module::Install::AUTHOR) {
115     require 'lib/Mouse/Spec.pm'; # for the version
116     my $require_version = Mouse::Spec->MooseVersion;
117
118     if ($ENV{COMPAT_TEST}
119             && eval { require Moose; Moose->VERSION($require_version) }) {
120         print "You have Moose ", Moose->VERSION, ".\n";
121         do 'tool/create-moose-compatibility-tests.pl';
122         # repeat testing
123         # see also ExtUtils::MM_Any::test_via_harness()
124         my $t_moose =  q{$(FULLPERLRUN) -MExtUtils::Command::MM -e}
125                       .q{ "test_harness($(TEST_VERBOSE), 'inc', '$(INST_LIB)', '$(INST_ARCHLIB)')"}
126                       .q{ xt/compat/t/*/*.t } . "\n";
127
128         postamble qq{test :: test_moose\n\n}
129                 . qq{test_moose :: pure_all\n}
130                 . qq{\t} . $t_moose;
131     } else {
132         print "You don't have Moose $require_version. skipping moose compatibility test\n";
133     }
134
135
136     # Hack to disable Test::Exception, which might pull a perl internal bug.
137     # See also Test::Exception::LessClever.
138     open my $out, '>', 'inc/Test/Exception.pm' or die $!;
139     print $out <<'EOT';
140 package Test::Exception; # wapper to T::E::LessClever
141 require Test::Exception::LessClever;
142 $INC{'Test/Exception.pm'} = __FILE__;
143 sub import {
144     shift;
145     Test::Exception::LessClever->export_to_level(1, @_);
146 }
147 1;
148 EOT
149     close $out or die $!;
150 }
151
152 clean_files q{
153     lib/Mouse/Tiny.pm $(O_FILES) test-mydeps-*.log
154     *.out
155     cover_db xs-src/*.gc{v,no,da}
156 };
157
158 WriteAll check_nmake => 0;