Update Makefile.PL
[gitmo/Mouse.git] / Makefile.PL
1 use strict;
2 use warnings;
3 use inc::Module::Install;
4
5 name     'Mouse';
6 all_from 'lib/Mouse.pm';
7
8 tests 't/*.t t/*/*.t';
9
10 # Scalar::Util < 1.14 has a bug.
11 # > Fixed looks_like_number(undef) to return false for perl >= 5.009002
12 requires 'Scalar::Util' => 1.14;
13
14 test_requires 'Test::More'      => 0.88;
15 test_requires 'Test::Exception' => 0.27;
16 # test_requires 'Test::Output'    => 0.16; # too many dependencies!
17
18 include 'Test::Exception'; # work around 0.27_0x (its use of diehook might be wrong)
19
20 recommends 'MRO::Compat' if $] < 5.010;
21
22 if ($Module::Install::AUTHOR) {
23     local @INC = ('lib', @INC);
24     require 'lib/Mouse/Spec.pm';
25     my $require_version = Mouse::Spec->MooseVersion;
26
27     if (eval{ require Moose; Moose->VERSION($require_version) }) {
28         if (eval 'use Module::Install::AuthorTests; 1') {
29             create_moose_compatibility_test();
30             recursive_author_tests('xt');
31         } else {
32             print "you don't have a M::I::AuthorTests.\n";
33         }
34     } else {
35         print "you don't have Moose $require_version. skipping moose compatibility test\n";
36     }
37     system("author/generate-mouse-tiny.pl");
38 }
39
40 WriteAll check_nmake => 0;
41
42 sub create_moose_compatibility_test {
43     require File::Path;
44     require File::Spec;
45     require File::Basename;
46
47     print "Creating compatibility tests in xt/compatibility/* ...\n";
48
49     File::Path::rmtree(File::Spec->catfile('xt', 'compatibility'));
50
51     # some test does not pass... currently skip it.
52     my %SKIP_TEST = (
53         '016-trigger.t'    => "trigger's argument is incompatble :(",
54         '010-isa-or.t'     => "Mouse has a [BUG]",
55
56         '052-undefined-type-in-union.t' => "Mouse accepts undefined type as a member of union types",
57
58         '600-tiny-tiny.t'     => "Moose doesn't support ::Tiny",
59         '601-tiny-mouse.t'    => "Moose doesn't support ::Tiny",
60         '602-mouse-tiny.t'    => "Moose doesn't support ::Tiny",
61
62         '031_roles_applied_in_create.t' => 't/lib/* classes are not Moose classes/roles',
63     );
64
65     my @compat_tests;
66
67     File::Find::find(
68         {
69             wanted => sub {
70                 return unless -f $_;
71
72                 return if /failing/; # skip tests in failing/ directories which  are Moose specific
73
74                 return if /100_with_moose/; # tests with Moose
75                 return if /deprecated/;
76
77                 my $basename = File::Basename::basename($_);
78                 return if $basename =~ /^\./;
79
80                 if(exists $SKIP_TEST{$basename}){
81                     print "# skip $basename because: $SKIP_TEST{$basename}\n";
82                     return;
83                 }
84
85                 my $dirname = File::Basename::dirname($_);
86
87                 my $tmpdir = File::Spec->catfile('xt', 'compatibility', $dirname);
88                 File::Path::mkpath($tmpdir);
89
90                 my $tmpfile = File::Spec->catfile($tmpdir, $basename);
91                 open my $wfh, '>', $tmpfile or die $!;
92                 print $wfh do {
93                     my $src = do {
94                         open my $rfh, '<', $_ or die $!;
95                         my $s = do { local $/; <$rfh> };
96                         close $rfh;
97                         $s;
98                     };
99                     $src =~ s/Mouse::(?:Util::)?is_class_loaded/Class::MOP::is_class_loaded/g;
100                     $src =~ s/Mouse::(?:Util::)?load_class/Class::MOP::load_class/g;
101                     $src =~ s/Mouse/Moose/g;
102                     $src;
103                 };
104                 close $wfh;
105                 push @compat_tests, $tmpfile;
106             },
107             no_chdir => 1
108         },
109         't',
110     );
111     print "Compatibility tests created.\n";
112
113     clean_files "@compat_tests";
114 }
115