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
4 my ($initial_inc_contents, $expected_dbic_deps, $require_sites);
6 # these envvars *will* bring in more stuff than the baseline
7 delete @ENV{qw(DBICTEST_SQLT_DEPLOY DBIC_TRACE)};
10 require DBICTest::Util::OverrideRequire;
12 DBICTest::Util::OverrideRequire::override_global_require( sub {
21 do { @caller = caller($up++) } while (
23 # exclude our test suite, known "module require-rs" and eval frames
24 $caller[1] =~ /^ t [\/\\] /x
26 $caller[0] =~ /^ (?: base | parent | Class::C3::Componentised | Module::Inspector | Module::Runtime ) $/x
28 $caller[3] eq '(eval)',
32 push @{$require_sites->{$req}}, "$caller[1] line $caller[2]"
35 return $res if $req =~ /^DBIx::Class|^DBICTest::/;
37 # exclude everything where the current namespace does not match the called function
38 # (this works around very weird XS-induced require callstack corruption)
40 !$initial_inc_contents->{$req}
42 !$expected_dbic_deps->{$req}
46 $caller[0] =~ /^DBIx::Class/
48 (caller($up))[3] =~ /\Q$caller[0]/
50 CORE::require('Test/More.pm');
51 Test::More::fail ("Unexpected require of '$req' by $caller[0] ($caller[1] line $caller[2])");
53 if ($ENV{TEST_VERBOSE}) {
54 CORE::require('DBICTest/Util.pm');
55 Test::More::diag( 'Require invoked' . DBICTest::Util::stacktrace() );
68 plan skip_all => 'A defined PERL5OPT may inject extra deps crashing this test'
71 plan skip_all => 'Dependency load patterns are radically different before perl 5.10'
74 # add what we loaded so far
79 $initial_inc_contents->{$mod} = 1;
84 ### This is where the test starts
87 # checking base schema load, no storage no connection
89 register_lazy_loadable_requires(qw(
95 Devel::GlobalDestruction
107 Class::Accessor::Grouped
108 Class::C3::Componentised
111 require DBICTest::Schema;
112 assert_no_missing_expected_requires();
115 # check schema/storage instantiation with no connect
117 register_lazy_loadable_requires(qw(
123 my $s = DBICTest::Schema->connect('dbi:SQLite::memory:');
124 ok (! $s->storage->connected, 'no connection');
125 assert_no_missing_expected_requires();
128 # do something (deploy, insert)
130 register_lazy_loadable_requires(qw(
136 my $s = DBICTest::Schema->connect('dbi:SQLite::memory:');
137 $s->storage->dbh_do(sub {
138 $_[1]->do('CREATE TABLE artist (
139 "artistid" INTEGER PRIMARY KEY NOT NULL,
141 "rank" integer NOT NULL DEFAULT 13,
146 my $art = $s->resultset('Artist')->create({ name => \[ '?' => 'foo'], rank => 42 });
147 $art->discard_changes;
148 $art->update({ rank => 69, name => 'foo' });
149 assert_no_missing_expected_requires();
152 # and do full populate() as well, just in case - shouldn't add new stuff
154 local $ENV{DBICTEST_SQLITE_REVERSE_DEFAULT_ORDER};
156 # in general we do not want DBICTest to load before sqla, but it is
158 local $INC{'SQL/Abstract.pm'};
161 my $s = DBICTest->init_schema;
162 is ($s->resultset('Artist')->find(1)->name, 'Caterwauler McCrae');
163 assert_no_missing_expected_requires();
168 sub register_lazy_loadable_requires {
169 local $Test::Builder::Level = $Test::Builder::Level + 1;
172 (my $modfn = "$mod.pm") =~ s!::!\/!g;
174 "Module $mod already loaded by require site(s):",
175 (map { "\t$_" } @{$require_sites->{$mod}}),
177 ) if $INC{$modfn} and !$initial_inc_contents->{$mod};
179 $expected_dbic_deps->{$mod}++
183 # check if anything we were expecting didn't actually load
184 sub assert_no_missing_expected_requires {
186 for my $mod (keys %$expected_dbic_deps) {
187 (my $modfn = "$mod.pm") =~ s/::/\//g;
188 unless ($INC{$modfn}) {
189 my $err = sprintf "Expected DBIC core dependency '%s' never loaded - %s needs adjustment", $mod, __FILE__;
190 if (DBICTest::RunMode->is_smoker or DBICTest::RunMode->is_author) {
194 diag "\n" unless $nl->{$mod}++;
199 pass(sprintf 'All modules expected at %s line %s loaded by DBIC: %s',
202 join (', ', sort keys %$expected_dbic_deps ),