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 replace $req_override in a bit
7 $test_hook = sub {}; # noop at first
8 *CORE::GLOBAL::require = sub {
19 my $expected_core_modules;
22 $expected_core_modules = { map { $_ => 1 } qw/
47 Class::Accessor::Grouped
48 Class::C3::Componentised
49 /, $] < 5.010 ? ( 'Class::C3', 'MRO::Compat' ) : () }; # this is special-cased in DBIx/Class.pm
57 return if $req =~ /^DBIx::Class|^DBICTest::/;
61 do { @caller = caller($up++) } while (
63 # exclude our test suite, known "module require-rs" and eval frames
64 $caller[1] =~ /^ t [\/\\] /x
66 $caller[0] =~ /^ (?: base | parent | Class::C3::Componentised | Module::Inspector) $/x
68 $caller[3] eq '(eval)',
72 # exclude everything where the current namespace does not match the called function
73 # (this works around very weird XS-induced require callstack corruption)
75 !$expected_core_modules->{$req}
79 $caller[0] =~ /^DBIx::Class/
81 (caller($up))[3] =~ /\Q$caller[0]/
83 fail ("Unexpected require of '$req' by $caller[0] ($caller[1] line $caller[2])");
85 if ($ENV{TEST_VERBOSE}) {
87 while (my @f = caller($i++) ) {
99 # these envvars bring in more stuff
100 delete $ENV{$_} for qw/
105 my $schema = DBICTest->init_schema;
106 is ($schema->resultset('Artist')->next->name, 'Caterwauler McCrae');
108 # check if anything we were expecting didn't actually load
110 for (keys %$expected_core_modules) {
113 unless ($INC{$mod}) {
114 my $err = sprintf "Expected DBIC core module %s never loaded - %s needs adjustment", $_, __FILE__;
115 if (DBICTest::RunMode->is_smoker) {
119 diag "\n" unless $nl++;