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]->() };
36 # FIXME This is a crock of shit, needs to go away
37 # currently here to work around https://rt.cpan.org/Ticket/Display.html?id=74151
38 # kill with fire when PS::XS / RT#74151 is *finally* fixed
43 require Package::Stash::PP;
44 $PS_provider = 'Package::Stash::PP';
47 require Package::Stash;
48 $PS_provider = 'Package::Stash';
50 eval <<"EOS" or die $@;
53 $PS_provider->new(\$_[0]);
64 require DBICTest::RunMode;
65 plan( skip_all => "Skipping test on plain module install" )
66 if DBICTest::RunMode->is_plain;
72 use B qw/svref_2object/;
74 # makes sure we can load at least something
76 use DBIx::Class::Carp;
79 my ($mod) = $_ =~ /(.+)/;
81 # not all modules are loadable at all times
83 # trap deprecation warnings and whatnot
84 local $SIG{__WARN__} = sub {};
87 SKIP: { skip "Failed require of $mod: " . ($@ =~ /^(.+?)$/m)[0], 1 };
88 (); # empty RV for @modules
93 # have an exception table for old and/or weird code we are not sure
94 # we *want* to clean in the first place
95 my $skip_idx = { map { $_ => 1 } (
96 (grep { /^DBIx::Class::CDBICompat/ } @modules), # too crufty to touch
97 'SQL::Translator::Producer::DBIx::Class::File', # ditto
99 # not sure how to handle type libraries
100 'DBIx::Class::Storage::DBI::Replicated::Types',
101 'DBIx::Class::Admin::Types',
103 # G::L::D is unclean, but we never inherit from it
104 'DBIx::Class::Admin::Descriptive',
105 'DBIx::Class::Admin::Usage',
107 # this subclass is expected to inherit whatever crap comes
109 'DBIx::Class::ResultSet::Pager',
111 # utility classes, not part of the inheritance chain
112 'DBIx::Class::ResultSource::RowParser::Util',
113 'DBIx::Class::_Util',
116 my $has_moose = eval { require Moose::Util };
118 Sub::Defer::undefer_all();
120 # can't use Class::Inspector for the mundane parts as it does not
121 # distinguish imports from anything else, what a crock of...
122 # Moose is not always available either - hence just do it ourselves
124 my $seen; #inheritance means we will see the same method multiple times
126 for my $mod (@modules) {
128 skip "$mod exempt from namespace checks",1 if $skip_idx->{$mod};
130 my %all_method_like = (map
131 { %{stash_for($_)->get_all_symbols('CODE')} }
132 (reverse @{mro::get_linear_isa($mod)})
135 my %parents = map { $_ => 1 } @{mro::get_linear_isa($mod)};
138 if ($has_moose and my $mc = Moose::Util::find_meta($mod)) {
139 if ($mc->can('calculate_all_roles_with_inheritance')) {
140 $roles{$_->name} = 1 for ($mc->calculate_all_roles_with_inheritance);
144 for my $name (keys %all_method_like) {
146 # overload is a funky thing - it is not cleaned, and its imports are named funny
147 next if $name =~ /^\(/;
149 my $gv = svref_2object($all_method_like{$name})->GV;
150 my $origin = $gv->STASH->NAME;
152 is ($gv->NAME, $name, "Properly named $name method at $origin" . ($origin eq $mod
154 : " (inherited by $mod)"
157 next if $seen->{"${origin}:${name}"}++;
159 if ($origin eq $mod) {
160 pass ("$name is a native $mod method");
162 elsif ($roles{$origin}) {
163 pass ("${mod}::${name} came from consumption of role $origin");
165 elsif ($parents{$origin}) {
166 pass ("${mod}::${name} came from proper parent-class $origin");
170 for (reverse @{mro::get_linear_isa($mod)} ) {
171 if ( ($_->can($name)||'') eq $all_method_like{$name} ) {
179 ( $name eq 'import' and $via = 'Exporter' )
181 pass("${mod}::${name} is a valid uncleaned import from ${name}");
184 fail ("${mod}::${name} appears to have entered inheritance chain by import into "
185 . ($via || 'UNKNOWN')
191 # some common import names (these should never ever be methods)
192 for my $f (qw/carp carp_once carp_unique croak confess cluck try catch finally/) {
195 for (reverse @{mro::get_linear_isa($mod)} ) {
196 if ( ($_->can($f)||'') eq $all_method_like{$f} ) {
201 fail ("Import $f leaked into method list of ${mod}, appears to have entered inheritance chain at "
202 . ($via || 'UNKNOWN')
206 pass ("Import $f not leaked into method list of $mod");
219 s/^ (?: lib | blib . (?:lib|arch) ) . //x;
220 push @modules, join ('::', File::Spec->splitdir($_));
224 # find them in both lib and blib, duplicates are fine, since
225 # @INC is preadjusted for us by the harness
227 ( -e 'blib' ? 'blib' : () ),
230 return sort @modules;