Augment did-author-run-makefile check to include OptDeps
[dbsrgits/DBIx-Class.git] / t / lib / DBICTest / AuthorCheck.pm
CommitLineData
ab340f7f 1package # hide from PAUSE
2 DBICTest::AuthorCheck;
3
4use strict;
5use warnings;
6
7use Path::Class qw/file dir/;
8
9_check_author_makefile() unless $ENV{DBICTEST_NO_MAKEFILE_VERIFICATION};
10
11# Die if the author did not update his makefile
12#
13# This is pretty heavy handed, so the check is pretty solid:
14#
15# 1) Assume that this particular module is loaded from -I <$root>/t/lib
16# 2) Make sure <$root>/Makefile.PL exists
17# 3) Make sure we can stat() <$root>/Makefile.PL
18#
19# If all of the above is satisfied
20#
21# *) die if <$root>/inc does not exist
22# *) die if no stat() results for <$root>/Makefile (covers no Makefile)
23# *) die if Makefile.PL mtime > Makefile mtime
24#
25sub _check_author_makefile {
26
27 my $root = _find_co_root()
28 or return;
29
7159a456 30 my $optdeps = file('lib/DBIx/Class/Optional/Dependencies.pm');
31
ab340f7f 32 # not using file->stat as it invokes File::stat which in turn breaks stat(_)
7159a456 33 my ($mf_pl_mtime, $mf_mtime, $optdeps_mtime) = ( map
ab340f7f 34 { (stat ($root->file ($_)) )[9] }
7159a456 35 (qw|Makefile.PL Makefile|, $optdeps)
ab340f7f 36 );
37
38 return unless $mf_pl_mtime; # something went wrong during co_root detection ?
39
7159a456 40 my @fail_reasons;
ab340f7f 41
7159a456 42 if(not -d $root->subdir ('inc')) {
43 push @fail_reasons, "Missing ./inc directory";
44 }
ab340f7f 45
7159a456 46 if (not $mf_mtime) {
47 push @fail_reasons, "Missing ./Makefile";
48 }
49 elsif($mf_mtime < $mf_pl_mtime) {
50 push @fail_reasons, "./Makefile.PL is newer than ./Makefile";
51 }
52
53 if ($mf_mtime < $optdeps_mtime) {
54 push @fail_reasons, "./$optdeps is newer than ./Makefile";
55 }
56
57 if (@fail_reasons) {
58 print STDERR <<'EOE';
ab340f7f 59
60
61!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
62======================== FATAL ERROR ===========================
63!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
64
65We have a number of reasons to believe that this is a development
66checkout and that you, the user, did not run `perl Makefile.PL`
67before using this code. You absolutely _must_ perform this step,
dc4600b2 68and ensure you have all required dependencies present. Not doing
69so often results in a lot of wasted time for other contributors
70trying to assit you with spurious "its broken!" problems.
ab340f7f 71
72If you are seeing this message unexpectedly (i.e. you are in fact
dc4600b2 73attempting a regular installation be it through CPAN or manually),
74please report the situation to either the mailing list or to the
75irc channel as described in
ab340f7f 76
77http://search.cpan.org/dist/DBIx-Class/lib/DBIx/Class.pm#GETTING_HELP/SUPPORT
78
ab340f7f 79The DBIC team
80
81
7159a456 82Reasons you received this message:
ab340f7f 83
84EOE
85
7159a456 86 foreach my $r (@fail_reasons) {
87 print STDERR " * $r\n";
88 }
89 print STDERR "\n\n\n";
90
ab340f7f 91 exit 1;
92 }
93}
94
dc4600b2 95# Mimic $Module::Install::AUTHOR
96sub is_author {
97
98 my $root = _find_co_root()
99 or return undef;
100
101 return (
102 ( not -d $root->subdir ('inc') )
103 or
104 ( -e $root->subdir ('inc')->file ($^O eq 'VMS' ? '_author' : '.author') )
105 );
106}
107
ab340f7f 108# Try to determine the root of a checkout/untar if possible
109# or return undef
110sub _find_co_root {
111
112 my @mod_parts = split /::/, (__PACKAGE__ . '.pm');
fd3d890d 113 my $rel_path = join ('/', @mod_parts); # %INC stores paths with / regardless of OS
ab340f7f 114
115 return undef unless ($INC{$rel_path});
116
117 # a bit convoluted, but what we do here essentially is:
118 # - get the file name of this particular module
119 # - do 'cd ..' as many times as necessary to get to t/lib/../..
120
121 my $root = dir ($INC{$rel_path});
fd3d890d 122 for (1 .. @mod_parts + 2) {
ab340f7f 123 $root = $root->parent;
124 }
125
126 return (-f $root->file ('Makefile.PL') )
127 ? $root
128 : undef
129 ;
130}
131
1321;