Commit | Line | Data |
4bea1fe7 |
1 | package # hide from PAUSE |
39c9c72d |
2 | DBICTest::RunMode; |
ab340f7f |
3 | |
4 | use strict; |
5 | use warnings; |
6 | |
4bea1fe7 |
7 | BEGIN { |
8 | if ($INC{'DBIx/Class.pm'}) { |
9 | my ($fr, @frame) = 1; |
10 | while (@frame = caller($fr++)) { |
11 | last if $frame[1] !~ m|^t/lib/DBICTest|; |
12 | } |
13 | |
14 | die __PACKAGE__ . " must be loaded before DBIx::Class (or modules using DBIx::Class) at $frame[1] line $frame[2]\n"; |
15 | } |
16 | } |
17 | |
ab340f7f |
18 | use Path::Class qw/file dir/; |
19 | |
20 | _check_author_makefile() unless $ENV{DBICTEST_NO_MAKEFILE_VERIFICATION}; |
21 | |
22 | # Die if the author did not update his makefile |
23 | # |
24 | # This is pretty heavy handed, so the check is pretty solid: |
25 | # |
26 | # 1) Assume that this particular module is loaded from -I <$root>/t/lib |
27 | # 2) Make sure <$root>/Makefile.PL exists |
28 | # 3) Make sure we can stat() <$root>/Makefile.PL |
29 | # |
30 | # If all of the above is satisfied |
31 | # |
32 | # *) die if <$root>/inc does not exist |
33 | # *) die if no stat() results for <$root>/Makefile (covers no Makefile) |
34 | # *) die if Makefile.PL mtime > Makefile mtime |
35 | # |
36 | sub _check_author_makefile { |
37 | |
38 | my $root = _find_co_root() |
39 | or return; |
40 | |
7159a456 |
41 | my $optdeps = file('lib/DBIx/Class/Optional/Dependencies.pm'); |
42 | |
ab340f7f |
43 | # not using file->stat as it invokes File::stat which in turn breaks stat(_) |
7159a456 |
44 | my ($mf_pl_mtime, $mf_mtime, $optdeps_mtime) = ( map |
50360f3e |
45 | { (stat ($root->file ($_)) )[9] || undef } # stat returns () on nonexistent files |
7159a456 |
46 | (qw|Makefile.PL Makefile|, $optdeps) |
ab340f7f |
47 | ); |
48 | |
49 | return unless $mf_pl_mtime; # something went wrong during co_root detection ? |
50 | |
7159a456 |
51 | my @fail_reasons; |
ab340f7f |
52 | |
7159a456 |
53 | if(not -d $root->subdir ('inc')) { |
54 | push @fail_reasons, "Missing ./inc directory"; |
55 | } |
ab340f7f |
56 | |
a256e995 |
57 | if(not $mf_mtime) { |
7159a456 |
58 | push @fail_reasons, "Missing ./Makefile"; |
59 | } |
a256e995 |
60 | else { |
61 | if($mf_mtime < $mf_pl_mtime) { |
62 | push @fail_reasons, "./Makefile.PL is newer than ./Makefile"; |
63 | } |
64 | if($mf_mtime < $optdeps_mtime) { |
65 | push @fail_reasons, "./$optdeps is newer than ./Makefile"; |
66 | } |
7159a456 |
67 | } |
68 | |
69 | if (@fail_reasons) { |
70 | print STDERR <<'EOE'; |
ab340f7f |
71 | |
72 | |
73 | !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
74 | ======================== FATAL ERROR =========================== |
75 | !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! |
76 | |
77 | We have a number of reasons to believe that this is a development |
78 | checkout and that you, the user, did not run `perl Makefile.PL` |
79 | before using this code. You absolutely _must_ perform this step, |
0424d17a |
80 | to ensure you have all required dependencies present. Not doing |
dc4600b2 |
81 | so often results in a lot of wasted time for other contributors |
82 | trying to assit you with spurious "its broken!" problems. |
ab340f7f |
83 | |
0424d17a |
84 | By default DBICs Makefile.PL turns all optional dependenciess into |
85 | *HARD REQUIREMENTS*, in order to make sure that the entire test |
86 | suite is executed, and no tests are skipped due to missing modules. |
87 | If you for some reason need to disable this behavior - supply the |
88 | --skip_author_deps option when running perl Makefile.PL |
89 | |
ab340f7f |
90 | If you are seeing this message unexpectedly (i.e. you are in fact |
dc4600b2 |
91 | attempting a regular installation be it through CPAN or manually), |
92 | please report the situation to either the mailing list or to the |
93 | irc channel as described in |
ab340f7f |
94 | |
95 | http://search.cpan.org/dist/DBIx-Class/lib/DBIx/Class.pm#GETTING_HELP/SUPPORT |
96 | |
ab340f7f |
97 | The DBIC team |
98 | |
99 | |
7159a456 |
100 | Reasons you received this message: |
ab340f7f |
101 | |
102 | EOE |
103 | |
7159a456 |
104 | foreach my $r (@fail_reasons) { |
105 | print STDERR " * $r\n"; |
106 | } |
107 | print STDERR "\n\n\n"; |
108 | |
ab340f7f |
109 | exit 1; |
110 | } |
111 | } |
112 | |
dc4600b2 |
113 | # Mimic $Module::Install::AUTHOR |
114 | sub is_author { |
115 | |
116 | my $root = _find_co_root() |
117 | or return undef; |
118 | |
119 | return ( |
120 | ( not -d $root->subdir ('inc') ) |
121 | or |
39c9c72d |
122 | ( -e $root->subdir ('inc')->subdir ($^O eq 'VMS' ? '_author' : '.author') ) |
dc4600b2 |
123 | ); |
124 | } |
125 | |
39c9c72d |
126 | sub is_smoker { |
127 | return ( $ENV{AUTOMATED_TESTING} && ! $ENV{PERL5_CPANM_IS_RUNNING} && ! $ENV{RELEASE_TESTING} ) |
128 | } |
129 | |
130 | sub is_plain { |
131 | return (! __PACKAGE__->is_smoker && ! __PACKAGE__->is_author && ! $ENV{RELEASE_TESTING} ) |
132 | } |
133 | |
ab340f7f |
134 | # Try to determine the root of a checkout/untar if possible |
135 | # or return undef |
136 | sub _find_co_root { |
137 | |
138 | my @mod_parts = split /::/, (__PACKAGE__ . '.pm'); |
fd3d890d |
139 | my $rel_path = join ('/', @mod_parts); # %INC stores paths with / regardless of OS |
ab340f7f |
140 | |
141 | return undef unless ($INC{$rel_path}); |
142 | |
143 | # a bit convoluted, but what we do here essentially is: |
144 | # - get the file name of this particular module |
145 | # - do 'cd ..' as many times as necessary to get to t/lib/../.. |
146 | |
147 | my $root = dir ($INC{$rel_path}); |
fd3d890d |
148 | for (1 .. @mod_parts + 2) { |
ab340f7f |
149 | $root = $root->parent; |
150 | } |
151 | |
152 | return (-f $root->file ('Makefile.PL') ) |
153 | ? $root |
154 | : undef |
155 | ; |
156 | } |
157 | |
158 | 1; |