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]->() };
43 use DBIx::Class::_Util qw( get_subname describe_class_methods );
45 # makes sure we can load at least something
47 use DBIx::Class::Carp;
50 # FIXME: AS THIS IS CLEARLY A LACK OF DEFENSE IN describe_class_methods :FIXME
51 # FIXME !!! without this detaint I get the test into an infloop on 5.16.x
52 # (maybe other versions): https://travis-ci.org/ribasushi/dbix-class/jobs/144738784#L26762
56 # ~$ ulimit -v $(( 1024 * 256 )); perl -d:Confess -Ilib -Tl xt/extra/internals/namespaces_cleaned.t
58 # DBIx::Class::MethodAttributes::_attr_cache("DBIx::Class::Storage::DBI::ODBC::Firebird") called at lib/DBIx/Class/MethodAttributes.pm line 166
59 # DBIx::Class::MethodAttributes::_attr_cache("DBIx::Class::Storage::DBI::ODBC::Firebird") called at lib/DBIx/Class/MethodAttributes.pm line 166
60 # DBIx::Class::MethodAttributes::_attr_cache("DBIx::Class::Storage::DBI::ODBC::Firebird") called at lib/DBIx/Class/MethodAttributes.pm line 166
61 # DBIx::Class::MethodAttributes::_attr_cache("DBIx::Class::Storage::DBI::ODBC::Firebird") called at lib/DBIx/Class/MethodAttributes.pm line 154
62 # DBIx::Class::MethodAttributes::FETCH_CODE_ATTRIBUTES("DBIx::Class::Storage::DBI::ODBC::Firebird", CODE(0x42ac2b0)) called at /home/rabbit/perl5/perlbrew/perls/5.16.2/lib/5.16.2/x86_64-linux-thread-multi-ld/attributes.pm line 101
63 # attributes::get(CODE(0x42ac2b0)) called at lib/DBIx/Class/_Util.pm line 885
64 # eval {...} called at lib/DBIx/Class/_Util.pm line 885
65 # DBIx::Class::_Util::describe_class_methods("DBIx::Class::Storage::DBI::ODBC::Firebird") called at xt/extra/internals/namespaces_cleaned.t line 129
72 # FIXME: AS THIS IS CLEARLY A LACK OF DEFENSE IN describe_class_methods :FIXME
73 # Sweeping it under the rug for now as this is an xt/ test,
74 # but someone *must* find what is going on eventually
75 # FIXME: AS THIS IS CLEARLY A LACK OF DEFENSE IN describe_class_methods :FIXME
80 my ($mod) = $_ =~ /(.+)/;
82 # not all modules are loadable at all times
84 # trap deprecation warnings and whatnot
85 local $SIG{__WARN__} = sub {};
88 SKIP: { skip "Failed require of $mod: " . ($@ =~ /^(.+?)$/m)[0], 1 };
89 (); # empty RV for @modules
94 # have an exception table for old and/or weird code we are not sure
95 # we *want* to clean in the first place
96 my $skip_idx = { map { $_ => 1 } (
97 'SQL::Translator::Producer::DBIx::Class::File', # too crufty to touch
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::Optional::Dependencies',
113 'DBIx::Class::ResultSource::RowParser::Util',
114 'DBIx::Class::_Util',
117 my $has_moose = eval { require Moose::Util };
119 my $seen; #inheritance means we will see the same method multiple times
121 for my $mod (@modules) {
123 skip "$mod exempt from namespace checks",1 if $skip_idx->{$mod};
125 my %all_method_like =
127 { $_->[0]{name} => $mod->can( $_->[0]{name} ) }
129 { $_->[0]{via_class} ne 'UNIVERSAL' }
130 values %{ describe_class_methods($mod)->{methods} }
133 my %parents = map { $_ => 1 } @{mro::get_linear_isa($mod)};
136 if ($has_moose and my $mc = Moose::Util::find_meta($mod)) {
137 if ($mc->can('calculate_all_roles_with_inheritance')) {
138 $roles{$_->name} = 1 for ($mc->calculate_all_roles_with_inheritance);
142 for my $name (keys %all_method_like) {
144 # overload is a funky thing - it is not cleaned, and its imports are named funny
145 next if $name =~ /^\(/;
147 my ($origin, $cv_name) = get_subname($all_method_like{$name});
149 is ($cv_name, $name, "Properly named $name method at $origin" . ($origin eq $mod
151 : " (inherited by $mod)"
154 next if $seen->{"${origin}::${name}"}++;
156 if ($origin eq $mod) {
157 pass ("$name is a native $mod method");
159 elsif ($roles{$origin}) {
160 pass ("${mod}::${name} came from consumption of role $origin");
162 elsif ($parents{$origin}) {
163 pass ("${mod}::${name} came from proper parent-class $origin");
167 for (reverse @{mro::get_linear_isa($mod)} ) {
168 if ( ($_->can($name)||'') eq $all_method_like{$name} ) {
176 ( $name eq 'import' and $via = 'Exporter' )
178 # jesus christ nobody had any idea how to design an interface back then
179 ( $name =~ /_trigger/ and $via = 'Class::Trigger' )
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");
218 $_ =~ m|lib/DBIx/Class/_TempExtlib| and return;
220 s/^ (?: lib | blib . (?:lib|arch) ) . //x;
221 push @modules, join ('::', File::Spec->splitdir($_));
225 # find them in both lib and blib, duplicates are fine, since
226 # @INC is preadjusted for us by the harness
228 ( -e 'blib' ? 'blib' : () ),
231 return sort @modules;