Lazy-load as many of the non-essential modules as possible
[dbsrgits/DBIx-Class.git] / t / 53lean_startup.t
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
4
5 my $test_hook;
6 BEGIN {
7   $test_hook = sub {}; # noop at first
8   *CORE::GLOBAL::require = sub {
9     $test_hook->(@_);
10     CORE::require($_[0]);
11   };
12 }
13
14 use strict;
15 use warnings;
16 use Test::More;
17
18 use Carp;
19
20 BEGIN {
21   my $core_modules = { map { $_ => 1 } qw/
22     strict
23     warnings
24     vars
25
26     base
27     parent
28     mro
29     overload
30
31     B
32     locale
33
34     namespace::clean
35     Try::Tiny
36     Sub::Name
37
38     Scalar::Util
39     List::Util
40     Hash::Merge
41
42     DBI
43
44     Carp
45     Carp::Clan
46
47     Class::Accessor::Grouped
48     Class::C3::Componentised
49
50     SQL::Abstract
51   /, $] < 5.010 ? 'MRO::Compat' : () };
52
53   $test_hook = sub {
54
55     my $req = $_[0];
56     $req =~ s/\.pm$//;
57     $req =~ s/\//::/g;
58
59     return if $req =~ /^DBIx::Class|^DBICTest::Schema/;
60
61     my $up = 1;
62     my @caller;
63     do { @caller = caller($up++) } while (
64       @caller and (
65         $caller[0] =~ /^ (?: base | parent | Class::C3::Componentised | Module::Inspector) $/x
66           or
67         $caller[1] =~ / \( eval \s \d+ \) /x
68       )
69     );
70
71     if ( $caller[0] =~ /^DBIx::Class/) {
72       fail ("Unexpected require of '$req' by $caller[0] ($caller[1] line $caller[2])")
73         unless $core_modules->{$req};
74     }
75   };
76 }
77
78 use lib 't/lib';
79 use DBICTest;
80
81 # these envvars bring in more stuff
82 delete $ENV{$_} for qw/
83   DBICTEST_SQLT_DEPLOY
84   DBIC_TRACE
85 /;
86
87 my $schema = DBICTest->init_schema;
88 is ($schema->resultset('Artist')->next->name, 'Caterwauler McCrae');
89
90 done_testing;