2 ### This version is rather 5.8-centric, because DBIC itself is 5.8
3 ### It certainly can be rewritten to degrade well on 5.6
6 # Very important to grab the snapshot early, as we will be reporting
7 # the INC indices from the POV of whoever ran the script, *NOT* from
8 # the POV of the internals
15 unshift @INC, 't/lib';
19 # Pre-5.10 perls pollute %INC on unsuccesfull module
20 # require, making it appear as if the module is already
21 # loaded on subsequent require()s
22 # Can't seem to find the exact RT/perldelta entry
24 # The reason we can't just use a sane, clean loader, is because
25 # if a Module require()s another module the %INC will still
26 # get filled with crap and we are back to square one. A global
27 # fix is really the only way for this test, as we try to load
28 # each available module separately, and have no control (nor
29 # knowledge) over their common dependencies.
31 # we want to do this here, in the very beginning, before even
32 # warnings/strict are loaded
34 require DBICTest::Util::OverrideRequire;
36 DBICTest::Util::OverrideRequire::override_global_require( sub {
37 my $res = eval { $_[0]->() };
50 use Test::More 'no_plan';
52 use File::Find 'find';
56 use ExtUtils::MakeMaker;
57 use DBICTest::Util 'visit_namespaces';
59 # load these two to pull in the t/lib armada
63 my $known_libpaths = {
65 config_key => 'sitearch',
68 config_key => 'sitelib',
71 config_key => 'vendorarch',
74 config_key => 'vendorlib',
77 config_key => 'archlib',
80 config_key => 'privlib',
93 full_path => full_path (
94 eval { require File::HomeDir and File::HomeDir->my_home }
103 for my $k (keys %$known_libpaths) {
104 my $v = $known_libpaths->{$k};
106 # never use home as a found-in-dir marker - it is too broad
107 # HOME is only used by the shortener
108 $v->{marker} = $k unless $k eq 'HOME';
110 unless ( $v->{full_path} ) {
111 if ( $v->{relpath} ) {
112 $v->{full_path} = full_path( $v->{relpath} );
114 elsif ( $Config{ $v->{config_key} || '' } ) {
115 $v->{full_path} = full_path (
116 $Config{"$v->{config_key}exp"} || $Config{$v->{config_key}}
121 delete $known_libpaths->{$k} unless $v->{full_path} and -d $v->{full_path};
123 my $seen_known_markers;
125 # first run through lib/ and *try* to load anything we can find
126 # within our own project
131 # can't just `require $fn`, as we need %INC to be
133 my ($mod) = $_ =~ /^ lib [\/\\] (.+) \.pm $/x
136 try_module_require(join ('::', File::Spec->splitdir($mod)) )
143 # now run through OptDeps and attempt loading everything else
145 # some things needs to be sorted before other things
146 # positive - load first
147 # negative - load last
149 # Make sure oracle is tried last - some clients (e.g. 10.2) have symbol
150 # clashes with libssl, and will segfault everything coming after them
151 "DBD::Oracle" => -999,
154 my @known_modules = sort
155 { ($load_weights->{$b}||0) <=> ($load_weights->{$a}||0) }
157 DBIx::Class::Optional::Dependencies->req_list_for([
159 # some DBDs are notoriously problematic to load
160 # hence only show stuff based on test_rdbms which will
161 # take into account necessary ENVs
162 { $_ !~ /^ (?: rdbms | dist )_ /x }
163 keys %{DBIx::Class::Optional::Dependencies->req_group_list}
168 try_module_require($_) for @known_modules;
170 my $has_versionpm = eval { require version };
173 # At this point we've loaded everything we ever could, but some modules
174 # (understandably) crapped out. For an even more thorough report, note
175 # everthing present in @INC we excplicitly know about (via OptDeps)
176 # *even though* it didn't load
177 my $known_failed_loads;
179 for my $mod (@known_modules) {
180 my $inc_key = module_notional_filename($mod);
181 next if defined $INC{$inc_key};
183 if (defined( my $idx = module_found_at_inc_index( $mod, \@INC ) ) ) {
184 $known_failed_loads->{$mod} = full_path( "$INC[$idx]/$inc_key" );
191 # This is a cool idea, but the line is too long even with shortening :(
193 #for my $i ( 1 .. $Config{config_argc} ) {
194 # my $conf_arg = $Config{"config_arg$i"};
198 # '=' . shorten_fn(full_path($1) )
201 # $perl .= " $conf_arg";
204 my $interesting_modules = {
213 # drill through the *ENTIRE* symtable and build a map of intereseting modules
214 visit_namespaces( action => sub {
218 # keep going, but nothing to see here
219 return 1 if $pkg eq 'main';
221 # private - not interested, including no further descent
222 return 0 if $pkg =~ / (?: ^ | :: ) _ /x;
224 my $inc_key = module_notional_filename($pkg);
233 full_path($INC{$inc_key})
236 # handle versions first (not interested in synthetic classes)
238 defined ${"${pkg}::VERSION"}
240 ${"${pkg}::VERSION"} !~ /\Qset by base.pm/
243 # make sure a version can be extracted, be noisy when it doesn't work
244 # do this even if we are throwing away the result below in lieu of EUMM
245 my $mod_ver = eval { $pkg->VERSION };
250 "Calling `$pkg->VERSION` resulted in an exception, which should never "
251 . "happen - please file a bug with the distribution containing $pkg. "
252 . "Complete exception text below:\n\n$err"
255 elsif( ! defined $mod_ver or ! length $mod_ver ) {
256 my $ret = defined $mod_ver
257 ? "the empty string ''"
262 "Calling `$pkg->VERSION` returned $ret, even though \$${pkg}::VERSION "
263 . "is defined, which should never happen - please file a bug with the "
264 . "distribution containing $pkg."
273 defined ( my $eumm_ver = eval { MM->parse_version( $full_path ) } )
276 # can only run the check reliably if v.pm is there
282 $eumm_ver ne $mod_ver
285 ( eval { version->parse( do { (my $v = $eumm_ver) =~ s/_//g; $v } ) } || 0 )
287 ( eval { version->parse( do { (my $v = $mod_ver) =~ s/_//g; $v } ) } || 0 )
291 "Mismatch of versions '$mod_ver' and '$eumm_ver', obtained respectively "
292 . "via `$pkg->VERSION` and parsing the version out of @{[ shorten_fn( $full_path ) ]} "
293 . "with ExtUtils::MakeMaker\@@{[ ExtUtils::MakeMaker->VERSION ]}. "
294 . "This should never happen - please check whether this is still present "
295 . "in the latest version, and then file a bug with the distribution "
300 $interesting_modules->{$pkg}{version} = $eumm_ver;
302 elsif( defined $mod_ver ) {
304 $interesting_modules->{$pkg}{version} = $mod_ver;
307 elsif ( $full_path = $known_failed_loads->{$pkg} ) {
308 $interesting_modules->{$pkg}{version} = '!! LOAD FAILED !!';
313 if (my $m = ( matching_known_lib( $full_path ) || {} )->{marker} ) {
316 elsif (defined ( my $idx = module_found_at_inc_index($pkg, \@initial_INC) ) ) {
317 $marker = sprintf '$INC[%d]', $idx;
320 # we are only interested if there was a declared version already above
321 # OR if the module came from somewhere other than T or LIB
326 $interesting_modules->{$pkg}
328 $marker !~ /^ (?: T | LIB ) $/x
331 $interesting_modules->{$pkg}{source_marker} = $marker;
332 $seen_known_markers->{$marker} = 1
333 if $known_libpaths->{$marker};
336 # at this point only fill in the path (md5 calc) IFF it is interesting
338 $interesting_modules->{$pkg}{full_path} = $full_path
339 if $interesting_modules->{$pkg};
345 # compress identical versions sourced from ./lib and ./t as close to the root
346 # of a namespace as we can
347 purge_identically_versioned_submodules_with_markers([qw( LIB T )]);
349 ok 1, (scalar keys %$interesting_modules) . " distinctly versioned modules found";
351 # do not announce anything under ci - we are watching for STDERR silence
352 exit 0 if DBICTest::RunMode->is_ci;
355 # diag the result out
356 my $max_ver_len = max map
358 ( 'xxx.yyyzzz_bbb', map { $_->{version} || '' } values %$interesting_modules )
360 my $max_marker_len = max map { length $_ } ( '$INC[99]', keys %{ $seen_known_markers || {} } );
364 List of loadable modules within both the core and *OPTIONAL* dependency chains present on this system
365 Note that *MANY* of these modules will *NEVER* be loaded during normal operation of DBIx::Class
366 (modules sourced from ./lib and ./t with versions identical to their parent namespace were omitted for brevity)
369 # pre-assemble everything and print it in one shot
370 # makes it less likely for parallel test execution to insert bogus lines
371 my $final_out = "\n$discl\n";
374 if ($seen_known_markers) {
376 $final_out .= join "\n", 'Sourcing markers:', (map
379 $max_marker_len => $_->{marker},
380 ($_->{config_key} ? "\$Config{$_->{config_key}}" : "$_->{relpath}/*" )
384 !!$b->{config_key} cmp !!$a->{config_key}
386 ( $a->{marker}||'') cmp ($b->{marker}||'')
388 @{$known_libpaths}{keys %$seen_known_markers}
393 $final_out .= "=============================\n";
395 $final_out .= join "\n", (map
398 $max_marker_len => $interesting_modules->{$_}{source_marker} || '',
399 $max_ver_len => ( defined $interesting_modules->{$_}{version}
400 ? $interesting_modules->{$_}{version}
404 ($interesting_modules->{$_}{full_path}
405 ? " [ MD5: @{[ get_md5( $interesting_modules->{$_}{full_path} ) ]} ]"
406 : "not -f \$INC{'@{[ module_notional_filename($_) ]}'}"
409 sort { lc($a) cmp lc($b) } keys %$interesting_modules
412 $final_out .= "=============================\n$discl\n\n";
420 sub say_err { print STDERR @_, "\n\n" };
422 # do !!!NOT!!! use Module::Runtime's require_module - it breaks CORE::require
423 sub try_module_require {
424 # trap deprecation warnings and whatnot
425 local $SIG{__WARN__} = sub {};
427 eval "require $_[0]";
431 return '' unless ( defined $_[0] and -e $_[0] );
433 # File::Spec's rel2abs does not resolve symlinks
434 # we *need* to look at the filesystem to be sure
435 my $fn = abs_path($_[0]);
437 if ( $^O eq 'MSWin32' and $fn ) {
439 # sometimes we can get a short/longname mix, normalize everything to longnames
440 $fn = Win32::GetLongPathName($fn);
442 # Fixup (native) slashes in Config not matching (unixy) slashes in INC
452 my $l = matching_known_lib( $fn )
456 $fn =~ s!\Q$l->{full_path}!$l->{relpath}!;
458 elsif ($l->{config_key}) {
459 $fn =~ s!\Q$l->{full_path}!<<$l->{marker}>>!
461 $seen_known_markers->{$l->{marker}} = 1;
467 sub matching_known_lib {
468 my $fn = full_path( $_[0] )
472 sort { length( $b->{full_path} ) <=> length( $a->{full_path} ) }
473 values %$known_libpaths
475 # run through the matcher twice - first always append a /
477 # important to avoid false positives
478 for my $suff ( '/', '' ) {
479 return { %$l } if 0 == index( $fn, "$l->{full_path}$suff" );
484 sub module_found_at_inc_index {
485 my ($mod, $dirs) = @_;
487 my $fn = module_notional_filename($mod);
489 for my $i ( 0 .. $#$dirs ) {
490 # searching from here on out won't mean anything
491 return undef if length ref $dirs->[$i];
507 sub purge_identically_versioned_submodules_with_markers {
510 return unless @$markers;
512 for my $mod ( sort { length($b) <=> length($a) } keys %$interesting_modules ) {
514 next unless defined $interesting_modules->{$mod}{version};
516 my $marker = $interesting_modules->{$mod}{source_marker}
519 next unless grep { $marker eq $_ } @$markers;
523 while ( $parent =~ s/ :: (?: . (?! :: ) )+ $ //x ) {
524 $interesting_modules->{$parent}
526 ($interesting_modules->{$parent}{version}||'') eq $interesting_modules->{$mod}{version}
528 ($interesting_modules->{$parent}{source_marker}||'') eq $interesting_modules->{$mod}{source_marker}
530 delete $interesting_modules->{$mod}
537 sub module_notional_filename {
538 (my $fn = $_[0] . '.pm') =~ s|::|/|g;
543 # we already checked for -r/-f, just bail if can't open
544 open my $fh, '<:raw', $_[0] or return '';
545 Digest::MD5->new->addfile($fh)->hexdigest;