1 BEGIN { do "./t/lib/ANFANG.pm" or die ( $@ || $! ) }
6 # Pre-5.10 perls pollute %INC on unsuccesfull module
7 # require, making it appear as if the module is already
8 # loaded on subsequent require()s
9 # Can't seem to find the exact RT/perldelta entry
11 # The reason we can't just use a sane, clean loader, is because
12 # if a Module require()s another module the %INC will still
13 # get filled with crap and we are back to square one. A global
14 # fix is really the only way for this test, as we try to load
15 # each available module separately, and have no control (nor
16 # knowledge) over their common dependencies.
18 # we want to do this here, in the very beginning, before even
19 # warnings/strict are loaded
22 require DBICTest::Util::OverrideRequire;
24 DBICTest::Util::OverrideRequire::override_global_require( sub {
25 my $res = eval { $_[0]->() };
38 # FIXME This is a crock of shit, needs to go away
39 # currently here to work around https://rt.cpan.org/Ticket/Display.html?id=74151
40 # kill with fire when PS::XS / RT#74151 is *finally* fixed
45 require Package::Stash::PP;
46 $PS_provider = 'Package::Stash::PP';
49 require Package::Stash;
50 $PS_provider = 'Package::Stash';
52 eval <<"EOS" or die $@;
55 $PS_provider->new(\$_[0]);
66 use B qw/svref_2object/;
68 # makes sure we can load at least something
70 use DBIx::Class::Carp;
73 my ($mod) = $_ =~ /(.+)/;
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 'SQL::Translator::Producer::DBIx::Class::File', # too crufty to touch
92 # not sure how to handle type libraries
93 'DBIx::Class::Storage::DBI::Replicated::Types',
94 'DBIx::Class::Admin::Types',
96 # G::L::D is unclean, but we never inherit from it
97 'DBIx::Class::Admin::Descriptive',
98 'DBIx::Class::Admin::Usage',
100 # this subclass is expected to inherit whatever crap comes
102 'DBIx::Class::ResultSet::Pager',
104 # utility classes, not part of the inheritance chain
105 'DBIx::Class::Optional::Dependencies',
106 'DBIx::Class::ResultSource::RowParser::Util',
107 'DBIx::Class::_Util',
110 my $has_moose = eval { require Moose::Util };
112 Sub::Defer::undefer_all();
114 my $seen; #inheritance means we will see the same method multiple times
116 for my $mod (@modules) {
118 skip "$mod exempt from namespace checks",1 if $skip_idx->{$mod};
120 my %all_method_like = (map
121 { %{stash_for($_)->get_all_symbols('CODE')} }
122 (reverse @{mro::get_linear_isa($mod)})
125 my %parents = map { $_ => 1 } @{mro::get_linear_isa($mod)};
128 if ($has_moose and my $mc = Moose::Util::find_meta($mod)) {
129 if ($mc->can('calculate_all_roles_with_inheritance')) {
130 $roles{$_->name} = 1 for ($mc->calculate_all_roles_with_inheritance);
134 for my $name (keys %all_method_like) {
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;
142 is ($gv->NAME, $name, "Properly named $name method at $origin" . ($origin eq $mod
144 : " (inherited by $mod)"
147 next if $seen->{"${origin}:${name}"}++;
149 if ($origin eq $mod) {
150 pass ("$name is a native $mod method");
152 elsif ($roles{$origin}) {
153 pass ("${mod}::${name} came from consumption of role $origin");
155 elsif ($parents{$origin}) {
156 pass ("${mod}::${name} came from proper parent-class $origin");
160 for (reverse @{mro::get_linear_isa($mod)} ) {
161 if ( ($_->can($name)||'') eq $all_method_like{$name} ) {
169 ( $name eq 'import' and $via = 'Exporter' )
171 # jesus christ nobody had any idea how to design an interface back then
172 ( $name =~ /_trigger/ and $via = 'Class::Trigger' )
174 pass("${mod}::${name} is a valid uncleaned import from ${name}");
177 fail ("${mod}::${name} appears to have entered inheritance chain by import into "
178 . ($via || 'UNKNOWN')
184 # some common import names (these should never ever be methods)
185 for my $f (qw/carp carp_once carp_unique croak confess cluck try catch finally/) {
188 for (reverse @{mro::get_linear_isa($mod)} ) {
189 if ( ($_->can($f)||'') eq $all_method_like{$f} ) {
194 fail ("Import $f leaked into method list of ${mod}, appears to have entered inheritance chain at "
195 . ($via || 'UNKNOWN')
199 pass ("Import $f not leaked into method list of $mod");
212 s/^ (?: lib | blib . (?:lib|arch) ) . //x;
213 push @modules, join ('::', File::Spec->splitdir($_));
217 # find them in both lib and blib, duplicates are fine, since
218 # @INC is preadjusted for us by the harness
220 ( -e 'blib' ? 'blib' : () ),
223 return sort @modules;