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]->() };
42 use DBIx::Class::_Util qw( get_subname describe_class_methods );
44 # makes sure we can load at least something
46 use DBIx::Class::Carp;
51 # not all modules are loadable at all times
53 # trap deprecation warnings and whatnot
54 local $SIG{__WARN__} = sub {};
57 SKIP: { skip "Failed require of $mod: " . ($@ =~ /^(.+?)$/m)[0], 1 };
58 (); # empty RV for @modules
63 # have an exception table for old and/or weird code we are not sure
64 # we *want* to clean in the first place
65 my $skip_idx = { map { $_ => 1 } (
66 'SQL::Translator::Producer::DBIx::Class::File', # too crufty to touch
68 # not sure how to handle type libraries
69 'DBIx::Class::Storage::DBI::Replicated::Types',
70 'DBIx::Class::Admin::Types',
72 # G::L::D is unclean, but we never inherit from it
73 'DBIx::Class::Admin::Descriptive',
74 'DBIx::Class::Admin::Usage',
76 # this subclass is expected to inherit whatever crap comes
78 'DBIx::Class::ResultSet::Pager',
80 # utility classes, not part of the inheritance chain
81 'DBIx::Class::Optional::Dependencies',
82 'DBIx::Class::ResultSource::RowParser::Util',
86 my $has_moose = eval { require Moose::Util };
88 my $seen; #inheritance means we will see the same method multiple times
90 for my $mod (@modules) {
92 skip "$mod exempt from namespace checks",1 if $skip_idx->{$mod};
96 { $_->[0]{name} => $mod->can( $_->[0]{name} ) }
98 { $_->[0]{via_class} ne 'UNIVERSAL' }
99 values %{ describe_class_methods($mod)->{methods} }
102 my %parents = map { $_ => 1 } @{mro::get_linear_isa($mod)};
105 if ($has_moose and my $mc = Moose::Util::find_meta($mod)) {
106 if ($mc->can('calculate_all_roles_with_inheritance')) {
107 $roles{$_->name} = 1 for ($mc->calculate_all_roles_with_inheritance);
111 for my $name (keys %all_method_like) {
113 # overload is a funky thing - it is not cleaned, and its imports are named funny
114 next if $name =~ /^\(/;
116 my ($origin, $cv_name) = get_subname($all_method_like{$name});
118 is ($cv_name, $name, "Properly named $name method at $origin" . ($origin eq $mod
120 : " (inherited by $mod)"
123 next if $seen->{"${origin}::${name}"}++;
125 if ($origin eq $mod) {
126 pass ("$name is a native $mod method");
128 elsif ($roles{$origin}) {
129 pass ("${mod}::${name} came from consumption of role $origin");
131 elsif ($parents{$origin}) {
132 pass ("${mod}::${name} came from proper parent-class $origin");
136 for (reverse @{mro::get_linear_isa($mod)} ) {
137 if ( ($_->can($name)||'') eq $all_method_like{$name} ) {
145 ( $name eq 'import' and $via = 'Exporter' )
147 # jesus christ nobody had any idea how to design an interface back then
148 ( $name =~ /_trigger/ and $via = 'Class::Trigger' )
150 pass("${mod}::${name} is a valid uncleaned import from ${name}");
153 fail ("${mod}::${name} appears to have entered inheritance chain by import into "
154 . ($via || 'UNKNOWN')
160 # some common import names (these should never ever be methods)
161 for my $f (qw/carp carp_once carp_unique croak confess cluck try catch finally/) {
164 for (reverse @{mro::get_linear_isa($mod)} ) {
165 if ( ($_->can($f)||'') eq $all_method_like{$f} ) {
170 fail ("Import $f leaked into method list of ${mod}, appears to have entered inheritance chain at "
171 . ($via || 'UNKNOWN')
175 pass ("Import $f not leaked into method list of $mod");
187 $_ =~ m|lib/DBIx/Class/_TempExtlib| and return;
189 s/^ (?: lib | blib . (?:lib|arch) ) . //x;
191 push @modules, ( $_ =~ /(.+)/ );
195 # find them in both lib and blib, duplicates are fine, since
196 # @INC is preadjusted for us by the harness
198 ( -e 'blib' ? 'blib' : () ),
201 return sort @modules;