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);
7 require DBICTest::Util::OverrideRequire;
9 DBICTest::Util::OverrideRequire::override_global_require( sub {
18 do { @caller = caller($up++) } while (
20 # exclude our test suite, known "module require-rs" and eval frames
21 $caller[1] =~ /^ t [\/\\] /x
23 $caller[0] =~ /^ (?: base | parent | Class::C3::Componentised | Module::Inspector | Module::Runtime ) $/x
25 $caller[3] eq '(eval)',
29 push @{$require_sites->{$req}}, "$caller[1] line $caller[2]"
32 return $res if $req =~ /^DBIx::Class|^DBICTest::/;
34 # exclude everything where the current namespace does not match the called function
35 # (this works around very weird XS-induced require callstack corruption)
37 !$initial_inc_contents->{$req}
39 !$expected_dbic_deps->{$req}
43 $caller[0] =~ /^DBIx::Class/
45 (caller($up))[3] =~ /\Q$caller[0]/
47 CORE::require('Test/More.pm');
48 Test::More::fail ("Unexpected require of '$req' by $caller[0] ($caller[1] line $caller[2])");
50 CORE::require('DBICTest/Util.pm');
51 Test::More::diag( 'Require invoked' . DBICTest::Util::stacktrace() );
63 plan skip_all => 'A defined PERL5OPT may inject extra deps crashing this test'
66 plan skip_all => 'Presence of sitecustomize.pl may inject extra deps crashing this test'
67 if grep { $_ =~ m| \/ sitecustomize\.pl $ |x } keys %INC;
69 plan skip_all => 'Dependency load patterns are radically different before perl 5.10'
72 # these envvars *will* bring in more stuff than the baseline
76 DBICTEST_VIA_REPLICATED
77 DBICTEST_DEBUG_CONCURRENCY_LOCKS
80 $ENV{DBICTEST_ANFANG_DEFANG} = 1;
82 # make sure extras do not load even when this is set
83 $ENV{PERL_STRICTURES_EXTRA} = 1;
85 # add what we loaded so far
90 $initial_inc_contents->{$mod} = 1;
96 ### This is where the test starts
99 # checking base schema load, no storage no connection
101 register_lazy_loadable_requires(qw(
107 Devel::GlobalDestruction
121 Class::Accessor::Grouped
122 Class::C3::Componentised
126 require DBICTest::Schema;
127 assert_no_missing_expected_requires();
130 # check schema/storage instantiation with no connect
132 register_lazy_loadable_requires(qw(
135 Method::Generate::Accessor
136 Method::Generate::Constructor
140 my $s = DBICTest::Schema->connect('dbi:SQLite::memory:');
141 ok (! $s->storage->connected, 'no connection');
142 assert_no_missing_expected_requires();
145 # do something (deploy, insert)
147 register_lazy_loadable_requires(qw(
152 my $s = DBICTest::Schema->connect('dbi:SQLite::memory:');
153 $s->storage->dbh_do(sub {
154 $_[1]->do('CREATE TABLE artist (
155 "artistid" INTEGER PRIMARY KEY NOT NULL,
157 "rank" integer NOT NULL DEFAULT 13,
162 my $art = $s->resultset('Artist')->create({ name => \[ '?' => 'foo'], rank => 42 });
163 $art->discard_changes;
164 $art->update({ rank => 69, name => 'foo' });
165 assert_no_missing_expected_requires();
168 # and do full populate() as well, just in case - shouldn't add new stuff
170 local $ENV{DBICTEST_SQLITE_REVERSE_DEFAULT_ORDER};
172 # in general we do not want DBICTest to load before sqla, but it is
174 local $INC{'SQL/Abstract.pm'};
177 my $s = DBICTest->init_schema;
178 is ($s->resultset('Artist')->find(1)->name, 'Caterwauler McCrae');
179 assert_no_missing_expected_requires();
184 sub register_lazy_loadable_requires {
185 local $Test::Builder::Level = $Test::Builder::Level + 1;
188 (my $modfn = "$mod.pm") =~ s!::!\/!g;
190 "Module $mod already loaded by require site(s):",
191 (map { "\t$_" } @{$require_sites->{$mod}}),
193 ) if $INC{$modfn} and !$initial_inc_contents->{$mod};
195 $expected_dbic_deps->{$mod}++
199 # check if anything we were expecting didn't actually load
200 sub assert_no_missing_expected_requires {
202 for my $mod (keys %$expected_dbic_deps) {
203 (my $modfn = "$mod.pm") =~ s/::/\//g;
205 "Expected DBIC core dependency '%s' never loaded - %s needs adjustment",
208 ) unless $INC{$modfn};
210 pass(sprintf 'All modules expected at %s line %s loaded by DBIC: %s',
213 join (', ', sort keys %$expected_dbic_deps ),