Change, Fix, Improve
[gitmo/Mouse.git] / Makefile.PL
1 use strict;
2 use warnings;
3 use inc::Module::Install;
4 use 5.008;
5
6 name     'Mouse';
7 all_from 'lib/Mouse.pm';
8
9 tests 't/*.t t/*/*.t';
10
11 # Scalar::Util < 1.14 has a bug.
12 # > Fixed looks_like_number(undef) to return false for perl >= 5.009002
13 requires 'Scalar::Util' => 1.14;
14
15 build_requires 'Test::Exception' => 0.21;
16 build_requires 'Test::More' => 0.80;
17
18 if ($Module::Install::AUTHOR) {
19     if (eval "package foo; use Moose; 1;") {
20         if (eval 'use Module::Install::AuthorTests; 1') {
21             create_moose_compatibility_test();
22             recursive_author_tests('xt');
23         } else {
24             print "you don't have a M::I::AuthorTests.\n";
25         }
26     } else {
27         print "you don't have a moose. skipping moose compatibility test\n";
28     }
29     system("author/generate-mouse-tiny.pl");
30 }
31
32 auto_include;
33 WriteAll;
34
35 sub create_moose_compatibility_test {
36     require File::Path;
37     require File::Spec;
38     require File::Basename;
39
40     print "Creating compatibility tests in xt/compatibility/* ...\n";
41
42     File::Path::rmtree(File::Spec->catfile('xt', 'compatibility'));
43
44     # some test does not pass... currently skip it.
45     my %SKIP_TEST = (
46         '016-trigger.t'    => "trigger's argument is incompatble :(",
47         '029-new.t'        => 'Class->new(undef) incompatible',
48         '010-isa-or.t'     => 'Mouse has a [BUG]',
49         '044-attribute-metaclass.t' => 'Moose::Meta::Attribute does not have a "create"',
50         '047-attribute-metaclass-role.t' => 'Moose::Meta::Attribute does not have a "create"',
51         '201-squirrel.t'      => 'skip Squirrel',
52         '202-squirrel-role.t' => 'Squirrel is ...',
53         '600-tiny-tiny.t'     => "Moose doesn't support ::Tiny",
54         '601-tiny-mouse.t'    => "Moose doesn't support ::Tiny",
55         '602-mouse-tiny.t'    => "Moose doesn't support ::Tiny",
56         '031_roles_applied_in_create.t' => 't/lib/* classes are not Moose classes/roles',
57     );
58
59     my @compat_tests;
60
61     File::Find::find(
62         {
63             wanted => sub {
64                 return unless -f $_;
65
66                 return if /failing/; # skip tests in failing/ directories
67
68                 my $basename = File::Basename::basename($_);
69                 return if $basename =~ /^\./;
70
71                 if(exists $SKIP_TEST{$basename}){
72                     print "# skip $basename because: $SKIP_TEST{$basename}\n";
73                     return;
74                 }
75
76                 my $dirname = File::Basename::dirname($_);
77
78                 my $tmpdir = File::Spec->catfile('xt', 'compatibility', $dirname);
79                 File::Path::mkpath($tmpdir);
80
81                 my $tmpfile = File::Spec->catfile($tmpdir, $basename);
82                 open my $wfh, '>', $tmpfile or die $!;
83                 print $wfh do {
84                     my $src = do {
85                         open my $rfh, '<', $_ or die $!;
86                         my $s = do { local $/; <$rfh> };
87                         close $rfh;
88                         $s;
89                     };
90                     $src =~ s/Mouse::is_class_loaded/Class::MOP::is_class_loaded/g;
91                     $src =~ s/Mouse::load_class/Class::MOP::load_class/g;
92                     $src =~ s/Mouse/Moose/g;
93                     $src;
94                 };
95                 close $wfh;
96                 push @compat_tests, $tmpfile;
97             },
98             no_chdir => 1
99         },
100         't',
101     );
102     print "Compatibility tests created.\n";
103
104     clean_files "@compat_tests";
105 }
106