Fix erroneous use of multidimensional array emulation in 1fb834df
[dbsrgits/DBIx-Class.git] / t / lib / ANFANG.pm
CommitLineData
c0329273 1package # hide from pauses
2 ANFANG;
3
4# load-time critical
5BEGIN {
6 if ( $ENV{RELEASE_TESTING} ) {
7 require warnings and warnings->import;
8 require strict and strict->import;
9 }
c0329273 10}
11
26710bc9 12#
13# FROM THIS POINT ONWARD EVERYTHING HAPPENS LINEARLY AT RUNTIME
14#
15our $anfang_loaded;
16
17# this allows the obscure but possible call case to behave correctly:
18#
19# perl -Mt::lib::ANFANG -e 'do "./t/lib/ANFANG.pm" or die ( $@ || $! )'
20#
21return 1 if $anfang_loaded;
c0329273 22
26710bc9 23# cover even more bases
24$INC{$_} ||= __FILE__ for (qw( ANFANG.pm t/lib/ANFANG.pm ./t/lib/ANFANG.pm ));
25
26{
c0329273 27 # load-me-first sanity check
28 if (
29
30 # nobody shut us off
31 ! $ENV{DBICTEST_ANFANG_DEFANG}
32
33 and
34
26710bc9 35 # if these are set - all bets are off
36 ! (
37 $ENV{PERL5OPT}
38 or
39 scalar grep { $_ =~ m| \/ sitecustomize\.pl $ |x } keys %INC
40 )
c0329273 41
42 and
43
44 # -d:Confess / -d:TraceUse and the like
45 ! $^P
46
47 and
48
49 # just don't check anything under RELEASE_TESTING
50 # a naive approach would be to simply whitelist both
51 # strict and warnings, but pre 5.10 there were even
52 # more modules loaded by these two:
53 #
54 # perlbrew exec perl -Mstrict -Mwarnings -e 'warn join "\n", sort keys %INC'
55 #
56 ! $ENV{RELEASE_TESTING}
57
58 and
59
60 my @undesirables = grep {
61
62 ($INC{$_}||'') ne __FILE__
63
64 and
65
66 # allow direct loads via -M
67 $_ !~ m{^ DBICTest (?: /Schema )? \.pm $}x
68
69 } keys %INC
70
71 ) {
72
73 my ( $fr, @frame );
74 while (@frame = caller(++$fr)) {
75 last if $frame[1] !~ m{ (?: \A | [\/\\] ) t [\/\\] lib [\/\\] }x;
76 }
77
78 die __FILE__ . " must be loaded before any other module (i.e. @{[ join ', ', map { qq('$_') } sort @undesirables ]}) at $frame[1] line $frame[2]\n";
79 }
80
81
82 if ( $ENV{DBICTEST_VERSION_WARNS_INDISCRIMINATELY} ) {
83 my $ov = UNIVERSAL->can("VERSION");
84
85 require Carp;
86
87 # not loading warnings.pm
88 local $^W = 0;
89
90 *UNIVERSAL::VERSION = sub {
91 Carp::carp( 'Argument "blah bleh bloh" isn\'t numeric in subroutine entry' );
92 &$ov;
93 };
94 }
95
96
97 if (
98 $ENV{DBICTEST_ASSERT_NO_SPURIOUS_EXCEPTION_ACTION}
99 or
100 # keep it always on during CI
101 (
102 ($ENV{TRAVIS}||'') eq 'true'
103 and
104 ($ENV{TRAVIS_REPO_SLUG}||'') =~ m|\w+/dbix-class$|
105 )
106 ) {
107 require Try::Tiny;
108 my $orig = \&Try::Tiny::try;
109
110 # not loading warnings.pm
111 local $^W = 0;
112
113 *Try::Tiny::try = sub (&;@) {
114 my ($fr, $first_pkg) = 0;
115 while( $first_pkg = caller($fr++) ) {
116 last if $first_pkg !~ /^
117 __ANON__
118 |
119 \Q(eval)\E
120 $/x;
121 }
122
123 if ($first_pkg =~ /DBIx::Class/) {
124 require Test::Builder;
125 Test::Builder->new->ok(0,
126 'Using try{} within DBIC internals is a mistake - use dbic_internal_try{} instead'
127 );
128 }
129
130 goto $orig;
131 };
132 }
c0329273 133}
134
26710bc9 135
136require lib;
137lib->import('t/lib');
138
c0329273 139
e48635f7 140# everything expects this to be there
141! -d 't/var' and (
142 mkdir 't/var'
143 or
144 die "Unable to create 't/var': $!\n"
145);
146
26710bc9 147
7b87b77c 148# Back in ab340f7f ribasushi stupidly introduced a "did you check your deps"
149# verification tied very tightly to Module::Install. The check went away, and
150# so eventually will M::I, but bisecting can bring all of this back from the
151# dead. In order to reduce hair-pulling make sure that ./inc/ is always there
152-f 'Makefile.PL' and mkdir 'inc' and mkdir 'inc/.author';
153
26710bc9 154
155# make absolutely sure this is last
156$anfang_loaded = 1;