1 # Use a require override instead of @INC munging (less common)
2 # Do the override as early as possible so that CORE::require doesn't get compiled away
3 # We will add the hook in a bit, got to load some regular stuff
8 require DBICTest::Util::OverrideRequire;
10 DBICTest::Util::OverrideRequire::override_global_require( sub {
12 $test_hook->($_[1]) if $test_hook;
20 use DBICTest::Util 'stacktrace';
22 # Package::Stash::XS is silly and fails if a require hook contains regular
23 # expressions on perl < 5.8.7. Load the damned thing if the case
25 require Package::Stash if $] < 5.008007;
28 my $expected_core_modules;
31 $expected_core_modules = { map { $_ => 1 } qw/
41 Devel::GlobalDestruction
53 DBI::Const::GetInfoType
58 Class::Accessor::Grouped
59 Class::C3::Componentised
62 /, $] < 5.010 ? ( 'Class::C3', 'MRO::Compat' ) : () }; # this is special-cased in DBIx/Class.pm
70 return if $req =~ /^DBIx::Class|^DBICTest::/;
74 do { @caller = caller($up++) } while (
76 # exclude our test suite, known "module require-rs" and eval frames
77 $caller[1] =~ /^ t [\/\\] /x
79 $caller[0] =~ /^ (?: base | parent | Class::C3::Componentised | Module::Inspector) $/x
81 $caller[3] eq '(eval)',
85 # exclude everything where the current namespace does not match the called function
86 # (this works around very weird XS-induced require callstack corruption)
88 !$expected_core_modules->{$req}
92 $caller[0] =~ /^DBIx::Class/
94 (caller($up))[3] =~ /\Q$caller[0]/
96 fail ("Unexpected require of '$req' by $caller[0] ($caller[1] line $caller[2])");
98 diag( 'Require invoked' . stacktrace() ) if $ENV{TEST_VERBOSE};
106 # these envvars bring in more stuff
107 delete $ENV{$_} for qw/
112 my $schema = DBICTest->init_schema;
113 is ($schema->resultset('Artist')->next->name, 'Caterwauler McCrae');
115 # check if anything we were expecting didn't actually load
117 for (keys %$expected_core_modules) {
120 unless ($INC{$mod}) {
121 my $err = sprintf "Expected DBIC core module %s never loaded - %s needs adjustment", $_, __FILE__;
122 if (DBICTest::RunMode->is_smoker or DBICTest::RunMode->is_author) {
126 diag "\n" unless $nl++;