1 # Pre-5.10 perls pollute %INC on unsuccesfull module
2 # require, making it appear as if the module is already
3 # loaded on subsequent require()s
4 # Can't seem to find the exact RT/perldelta entry
6 # we want to do this here, in the very beginning, before even
7 # warnings/strict are loaded
11 # All of this almost verbatim copied from Lexical::SealRequireHints
14 # a potential caller() in $next_require must see the correct
15 # immediate frame caller
16 my $caller = caller(0);
18 our $next_require = defined(&CORE::GLOBAL::require)
19 ? \&CORE::GLOBAL::require
23 # The shenanigans with $CORE::GLOBAL::{require}
24 # are required because if there's a
25 # &CORE::GLOBAL::require when the eval is
26 # executed then the CORE::require in there is
27 # interpreted as plain require on some Perl
28 # versions, leading to recursion.
29 my $grequire = delete $CORE::GLOBAL::{require};
31 my $result = eval sprintf '
33 $CORE::GLOBAL::{require} = $grequire;
43 *CORE::GLOBAL::require = sub {
44 die "wrong number of arguments to require\n"
47 my $res = eval "package $caller; \$next_require->(\@_)";
65 use B qw/svref_2object/;
68 # makes sure we can load at least something
70 use DBIx::Class::Carp;
75 # not all modules are loadable at all times
77 # trap deprecation warnings and whatnot
78 local $SIG{__WARN__} = sub {};
81 SKIP: { skip "Failed require of $mod: " . ($@ =~ /^(.+?)$/m)[0], 1 };
82 (); # empty RV for @modules
87 # have an exception table for old and/or weird code we are not sure
88 # we *want* to clean in the first place
89 my $skip_idx = { map { $_ => 1 } (
90 (grep { /^DBIx::Class::CDBICompat/ } @modules), # too crufty to touch
91 'SQL::Translator::Producer::DBIx::Class::File', # ditto
93 # not sure how to handle type libraries
94 'DBIx::Class::Storage::DBI::Replicated::Types',
95 'DBIx::Class::Admin::Types',
97 # G::L::D is unclean, but we never inherit from it
98 'DBIx::Class::Admin::Descriptive',
99 'DBIx::Class::Admin::Usage',
101 # this subclass is expected to inherit whatever crap comes
103 'DBIx::Class::ResultSet::Pager',
106 my $has_cmop = eval { require Class::MOP };
108 # can't use Class::Inspector for the mundane parts as it does not
109 # distinguish imports from anything else, what a crock of...
110 # Class::MOP is not always available either - hence just do it ourselves
112 my $seen; #inheritance means we will see the same method multiple times
114 for my $mod (@modules) {
116 skip "$mod exempt from namespace checks",1 if $skip_idx->{$mod};
118 my %all_method_like = (map
119 { %{Package::Stash->new($_)->get_all_symbols('CODE')} }
120 (reverse @{mro::get_linear_isa($mod)})
123 my %parents = map { $_ => 1 } @{mro::get_linear_isa($mod)};
126 if ($has_cmop and my $mc = Class::MOP::class_of($mod)) {
127 if ($mc->can('calculate_all_roles_with_inheritance')) {
128 $roles{$_->name} = 1 for ($mc->calculate_all_roles_with_inheritance);
132 for my $name (keys %all_method_like) {
134 next if ( DBIx::Class::_ENV_::BROKEN_NAMESPACE_CLEAN() and $name =~ /^carp(?:_unique|_once)?$/ );
136 # overload is a funky thing - it is not cleaned, and its imports are named funny
137 next if $name =~ /^\(/;
139 my $gv = svref_2object($all_method_like{$name})->GV;
140 my $origin = $gv->STASH->NAME;
143 local $TODO = 'CAG does not clean its BEGIN constants' if $name =~ /^__CAG_/;
144 is ($gv->NAME, $name, "Properly named $name method at $origin" . ($origin eq $mod
146 : " (inherited by $mod)"
150 next if $seen->{"${origin}:${name}"}++;
152 if ($origin eq $mod) {
153 pass ("$name is a native $mod method");
155 elsif ($roles{$origin}) {
156 pass ("${mod}::${name} came from consumption of role $origin");
158 elsif ($parents{$origin}) {
159 pass ("${mod}::${name} came from proper parent-class $origin");
163 for (reverse @{mro::get_linear_isa($mod)} ) {
164 if ( ($_->can($name)||'') eq $all_method_like{$name} ) {
169 fail ("${mod}::${name} appears to have entered inheritance chain by import into "
170 . ($via || 'UNKNOWN')
175 next if DBIx::Class::_ENV_::BROKEN_NAMESPACE_CLEAN();
177 # some common import names (these should never ever be methods)
178 for my $f (qw/carp carp_once carp_unique croak confess cluck try catch finally/) {
181 for (reverse @{mro::get_linear_isa($mod)} ) {
182 if ( ($_->can($f)||'') eq $all_method_like{$f} ) {
187 fail ("Import $f leaked into method list of ${mod}, appears to have entered inheritance chain at "
188 . ($via || 'UNKNOWN')
192 pass ("Import $f not leaked into method list of $mod");
205 s/^ (?: lib | blib . (?:lib|arch) ) . //x;
206 push @modules, join ('::', File::Spec->splitdir($_));
209 }, (-e 'blib' ? 'blib' : 'lib') );
211 return sort @modules;