Fix author/generate-mouse-tiny.pl. Now Mouse::Tiny is generated in the "make" command
[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 makemaker_args PL_FILES => { 'author/generate-mouse-tiny.pl' => 'lib/Mouse/Tiny.pm' };
23
24 if ($Module::Install::AUTHOR) {
25     local @INC = ('lib', @INC);
26     require 'lib/Mouse/Spec.pm';
27     my $require_version = Mouse::Spec->MooseVersion;
28
29     if (eval{ require Moose; Moose->VERSION($require_version) }) {
30         if (eval 'use Module::Install::AuthorTests; 1') {
31             create_moose_compatibility_test();
32             recursive_author_tests('xt');
33         } else {
34             print "you don't have a M::I::AuthorTests.\n";
35         }
36     } else {
37         print "you don't have Moose $require_version. skipping moose compatibility test\n";
38     }
39 }
40
41 WriteAll check_nmake => 0;
42
43 sub create_moose_compatibility_test {
44     require File::Path;
45     require File::Spec;
46     require File::Basename;
47
48     print "Creating compatibility tests in xt/compatibility/* ...\n";
49
50     File::Path::rmtree(File::Spec->catfile('xt', 'compatibility'));
51
52     # some test does not pass... currently skip it.
53     my %SKIP_TEST = (
54         '016-trigger.t'    => "trigger's argument is incompatble :(",
55         '010-isa-or.t'     => "Mouse has a [BUG]",
56
57         '052-undefined-type-in-union.t' => "Mouse accepts undefined type as a member of union types",
58         '054-anon-leak.t'     => 'Moose has memory leaks',
59
60         '600-tiny-tiny.t'     => "Moose doesn't support ::Tiny",
61         '601-tiny-mouse.t'    => "Moose doesn't support ::Tiny",
62         '602-mouse-tiny.t'    => "Moose doesn't support ::Tiny",
63
64         '031_roles_applied_in_create.t' => 't/lib/* classes are not Moose classes/roles',
65     );
66
67     my @compat_tests;
68
69     File::Find::find(
70         {
71             wanted => sub {
72                 return unless -f $_;
73
74                 return if /failing/; # skip tests in failing/ directories which  are Moose specific
75
76                 return if /100_with_moose/; # tests with Moose
77                 return if /deprecated/;
78
79                 my $basename = File::Basename::basename($_);
80                 return if $basename =~ /^\./;
81
82                 if(exists $SKIP_TEST{$basename}){
83                     print "# skip $basename because: $SKIP_TEST{$basename}\n";
84                     return;
85                 }
86
87                 my $dirname = File::Basename::dirname($_);
88
89                 my $tmpdir = File::Spec->catfile('xt', 'compatibility', $dirname);
90                 File::Path::mkpath($tmpdir);
91
92                 my $tmpfile = File::Spec->catfile($tmpdir, $basename);
93                 open my $wfh, '>', $tmpfile or die $!;
94                 print $wfh do {
95                     my $src = do {
96                         open my $rfh, '<', $_ or die $!;
97                         my $s = do { local $/; <$rfh> };
98                         close $rfh;
99                         $s;
100                     };
101                     $src =~ s/Mouse::(?:Util::)?is_class_loaded/Class::MOP::is_class_loaded/g;
102                     $src =~ s/Mouse::(?:Util::)?load_class/Class::MOP::load_class/g;
103                     $src =~ s/Mouse/Moose/g;
104                     $src;
105                 };
106                 close $wfh;
107                 push @compat_tests, $tmpfile;
108             },
109             no_chdir => 1
110         },
111         't',
112     );
113     print "Compatibility tests created.\n";
114
115     clean_files "@compat_tests";
116 }
117