4 # Pre-5.10 perls pollute %INC on unsuccesfull module
5 # require, making it appear as if the module is already
6 # loaded on subsequent require()s
7 # Can't seem to find the exact RT/perldelta entry
9 # The reason we can't just use a sane, clean loader, is because
10 # if a Module require()s another module the %INC will still
11 # get filled with crap and we are back to square one. A global
12 # fix is really the only way for this test, as we try to load
13 # each available module separately, and have no control (nor
14 # knowledge) over their common dependencies.
16 # we want to do this here, in the very beginning, before even
17 # warnings/strict are loaded
19 unshift @INC, 't/lib';
20 require DBICTest::Util::OverrideRequire;
22 DBICTest::Util::OverrideRequire::override_global_require( sub {
23 my $res = eval { $_[0]->() };
43 use B qw/svref_2object/;
46 # makes sure we can load at least something
48 use DBIx::Class::Carp;
51 my ($mod) = $_ =~ /(.+)/;
53 # not all modules are loadable at all times
55 # trap deprecation warnings and whatnot
56 local $SIG{__WARN__} = sub {};
59 SKIP: { skip "Failed require of $mod: " . ($@ =~ /^(.+?)$/m)[0], 1 };
60 (); # empty RV for @modules
65 # have an exception table for old and/or weird code we are not sure
66 # we *want* to clean in the first place
67 my $skip_idx = { map { $_ => 1 } (
68 (grep { /^DBIx::Class::CDBICompat/ } @modules), # too crufty to touch
69 'SQL::Translator::Producer::DBIx::Class::File', # ditto
71 # not sure how to handle type libraries
72 'DBIx::Class::Storage::DBI::Replicated::Types',
73 'DBIx::Class::Admin::Types',
75 # G::L::D is unclean, but we never inherit from it
76 'DBIx::Class::Admin::Descriptive',
77 'DBIx::Class::Admin::Usage',
79 # this subclass is expected to inherit whatever crap comes
81 'DBIx::Class::ResultSet::Pager',
83 # utility classes, not part of the inheritance chain
84 'DBIx::Class::ResultSource::RowParser::Util',
88 my $has_cmop = eval { require Class::MOP };
90 # can't use Class::Inspector for the mundane parts as it does not
91 # distinguish imports from anything else, what a crock of...
92 # Class::MOP is not always available either - hence just do it ourselves
94 my $seen; #inheritance means we will see the same method multiple times
96 for my $mod (@modules) {
98 skip "$mod exempt from namespace checks",1 if $skip_idx->{$mod};
100 my %all_method_like = (map
101 { %{Package::Stash->new($_)->get_all_symbols('CODE')} }
102 (reverse @{mro::get_linear_isa($mod)})
105 my %parents = map { $_ => 1 } @{mro::get_linear_isa($mod)};
108 if ($has_cmop and my $mc = Class::MOP::class_of($mod)) {
109 if ($mc->can('calculate_all_roles_with_inheritance')) {
110 $roles{$_->name} = 1 for ($mc->calculate_all_roles_with_inheritance);
114 for my $name (keys %all_method_like) {
116 next if ( DBIx::Class::_ENV_::BROKEN_NAMESPACE_CLEAN and $name =~ /^carp(?:_unique|_once)?$/ );
118 # overload is a funky thing - it is not cleaned, and its imports are named funny
119 next if $name =~ /^\(/;
121 my $gv = svref_2object($all_method_like{$name})->GV;
122 my $origin = $gv->STASH->NAME;
124 is ($gv->NAME, $name, "Properly named $name method at $origin" . ($origin eq $mod
126 : " (inherited by $mod)"
129 next if $seen->{"${origin}:${name}"}++;
131 if ($origin eq $mod) {
132 pass ("$name is a native $mod method");
134 elsif ($roles{$origin}) {
135 pass ("${mod}::${name} came from consumption of role $origin");
137 elsif ($parents{$origin}) {
138 pass ("${mod}::${name} came from proper parent-class $origin");
142 for (reverse @{mro::get_linear_isa($mod)} ) {
143 if ( ($_->can($name)||'') eq $all_method_like{$name} ) {
148 fail ("${mod}::${name} appears to have entered inheritance chain by import into "
149 . ($via || 'UNKNOWN')
154 next if DBIx::Class::_ENV_::BROKEN_NAMESPACE_CLEAN;
156 # some common import names (these should never ever be methods)
157 for my $f (qw/carp carp_once carp_unique croak confess cluck try catch finally/) {
160 for (reverse @{mro::get_linear_isa($mod)} ) {
161 if ( ($_->can($f)||'') eq $all_method_like{$f} ) {
166 fail ("Import $f leaked into method list of ${mod}, appears to have entered inheritance chain at "
167 . ($via || 'UNKNOWN')
171 pass ("Import $f not leaked into method list of $mod");
184 s/^ (?: lib | blib . (?:lib|arch) ) . //x;
185 push @modules, join ('::', File::Spec->splitdir($_));
188 }, (-e 'blib' ? 'blib' : 'lib') );
190 return sort @modules;