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
14 BEGIN { do "./t/lib/ANFANG.pm" or die ( $@ || $! ) }
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';
57 use ExtUtils::MakeMaker;
59 use DBICTest::RunMode;
60 use DBICTest::Util 'visit_namespaces';
61 use DBIx::Class::Optional::Dependencies;
65 config_key => 'sitearch',
68 config_key => 'sitelib',
71 config_key => 'sitelib_stem',
75 config_key => 'siteprefix',
79 config_key => 'vendorarch',
82 config_key => 'vendorlib',
85 config_key => 'vendorlib_stem',
89 config_key => 'vendorprefix',
93 config_key => 'archlib',
96 config_key => 'privlib',
99 config_key => 'prefix',
103 rel_path => './blib/arch',
104 skip_unversioned_modules => 1,
107 rel_path => './blib/lib',
108 skip_unversioned_modules => 1,
115 skip_unversioned_modules => 1,
119 skip_unversioned_modules => 1,
123 skip_unversioned_modules => 1,
130 abs_unix_path => abs_unix_path (
131 eval { require File::HomeDir and File::HomeDir->my_home }
142 for my $k (keys %$known_paths) {
143 my $v = $known_paths->{$k};
145 # never use home as a found-in-dir marker - it is too broad
146 # HOME is only used by the shortener
147 $v->{marker} = $k unless $k eq 'HOME';
149 unless ( $v->{abs_unix_path} ) {
150 if ( $v->{rel_path} ) {
151 $v->{abs_unix_path} = abs_unix_path( $v->{rel_path} );
153 elsif ( $Config{ $v->{config_key} || '' } ) {
154 $v->{abs_unix_path} = abs_unix_path (
155 $Config{"$v->{config_key}exp"} || $Config{$v->{config_key}}
160 delete $known_paths->{$k} unless $v->{abs_unix_path} and -d $v->{abs_unix_path};
162 my $seen_markers = {};
164 # first run through lib/ and *try* to load anything we can find
165 # within our own project
170 # can't just `require $fn`, as we need %INC to be
172 my ($mod) = $_ =~ /^ lib [\/\\] (.+) \.pm $/x
175 try_module_require(join ('::', File::Spec->splitdir($mod)) )
182 # now run through OptDeps and attempt loading everything else
184 # some things needs to be sorted before other things
185 # positive - load first
186 # negative - load last
188 # Make sure oracle is tried last - some clients (e.g. 10.2) have symbol
189 # clashes with libssl, and will segfault everything coming after them
190 "DBD::Oracle" => -999,
193 my @known_modules = sort
194 { ($load_weights->{$b}||0) <=> ($load_weights->{$a}||0) }
197 DBIx::Class::Optional::Dependencies->req_list_for([
199 # some DBDs are notoriously problematic to load
200 # hence only show stuff based on test_rdbms which will
201 # take into account necessary ENVs
202 { $_ !~ /^ (?: rdbms | dist )_ /x }
203 keys %{DBIx::Class::Optional::Dependencies->req_group_list}
208 try_module_require($_) for @known_modules;
210 my $has_versionpm = eval { require version };
213 # At this point we've loaded everything we ever could, but some modules
214 # (understandably) crapped out. For an even more thorough report, note
215 # everthing present in @INC we excplicitly know about (via OptDeps)
216 # *even though* it didn't load
217 my $known_failed_loads;
219 for my $mod (@known_modules) {
220 my $inc_key = module_notional_filename($mod);
221 next if defined $INC{$inc_key};
223 if (defined( my $idx = module_found_at_inc_index( $mod, \@INC ) ) ) {
224 $known_failed_loads->{$mod} = abs_unix_path( "$INC[$idx]/$inc_key" );
231 # This is a cool idea, but the line is too long even with shortening :(
233 #for my $i ( 1 .. $Config{config_argc} ) {
234 # my $conf_arg = $Config{"config_arg$i"};
238 # '=' . shorten_fn($1)
241 # $perl .= " $conf_arg";
244 my $interesting_modules = {
248 abs_unix_path => abs_unix_path($^X),
253 # drill through the *ENTIRE* symtable and build a map of interesting modules
254 visit_namespaces( action => sub {
258 # keep going, but nothing to see here
259 return 1 if $pkg eq 'main';
261 # private - not interested, including no further descent
262 return 0 if $pkg =~ / (?: ^ | :: ) _ /x;
264 my $inc_key = module_notional_filename($pkg);
266 my $abs_unix_path = (
273 abs_unix_path($INC{$inc_key})
276 # handle versions first (not interested in synthetic classes)
278 defined ${"${pkg}::VERSION"}
280 ${"${pkg}::VERSION"} !~ /\Qset by base.pm/
283 # make sure a version can be extracted, be noisy when it doesn't work
284 # do this even if we are throwing away the result below in lieu of EUMM
285 my $mod_ver = eval { $pkg->VERSION };
290 "Calling `$pkg->VERSION` resulted in an exception, which should never "
291 . "happen - please file a bug with the distribution containing $pkg. "
292 . "Complete exception text below:\n\n$err"
295 elsif( ! defined $mod_ver or ! length $mod_ver ) {
296 my $ret = defined $mod_ver
297 ? "the empty string ''"
302 "Calling `$pkg->VERSION` returned $ret, even though \$${pkg}::VERSION "
303 . "is defined, which should never happen - please file a bug with the "
304 . "distribution containing $pkg."
313 defined ( my $eumm_ver = eval { MM->parse_version( $abs_unix_path ) } )
316 # can only run the check reliably if v.pm is there
322 $eumm_ver ne $mod_ver
325 ( eval { version->parse( do { (my $v = $eumm_ver) =~ s/_//g; $v } ) } || 0 )
327 ( eval { version->parse( do { (my $v = $mod_ver) =~ s/_//g; $v } ) } || 0 )
331 "Mismatch of versions '$mod_ver' and '$eumm_ver', obtained respectively "
332 . "via `$pkg->VERSION` and parsing the version out of @{[ shorten_fn( $abs_unix_path ) ]} "
333 . "with ExtUtils::MakeMaker\@@{[ ExtUtils::MakeMaker->VERSION ]}. "
334 . "This should never happen - please check whether this is still present "
335 . "in the latest version, and then file a bug with the distribution "
340 $interesting_modules->{$pkg}{version} = $eumm_ver;
342 elsif( defined $mod_ver ) {
344 $interesting_modules->{$pkg}{version} = $mod_ver;
347 elsif ( $known_failed_loads->{$pkg} ) {
348 $abs_unix_path = $known_failed_loads->{$pkg};
349 $interesting_modules->{$pkg}{version} = '!! LOAD FAIL !!';
352 if ($abs_unix_path) {
353 my ($marker, $initial_inc_idx);
355 my $current_inc_idx = module_found_at_inc_index($pkg, \@INC);
356 my $p = subpath_of_known_path( $abs_unix_path );
359 defined $current_inc_idx
363 abs_unix_path($INC[$current_inc_idx]) eq $p->{abs_unix_path}
365 $marker = $p->{marker};
367 elsif (defined ( $initial_inc_idx = module_found_at_inc_index($pkg, \@initial_INC) ) ) {
368 $marker = "\$INC[$initial_inc_idx]";
371 # we are only interested if there was a declared version already above
372 # OR if the module came from somewhere other than skip_unversioned_modules
377 $interesting_modules->{$pkg}
379 !$p->{skip_unversioned_modules}
382 $interesting_modules->{$pkg}{source_marker} = $marker;
383 $seen_markers->{$marker} = 1;
386 # at this point only fill in the path (md5 calc) IFF it is interesting
388 $interesting_modules->{$pkg}{abs_unix_path} = $abs_unix_path
389 if $interesting_modules->{$pkg};
395 # compress identical versions sourced from ./blib, ./lib, ./t and ./xt
396 # as close to the root of a namespace as we can
397 purge_identically_versioned_submodules_with_markers([ map {
398 ( $_->{skip_unversioned_modules} && $_->{marker} ) || ()
399 } values %$known_paths ]);
401 ok 1, (scalar keys %$interesting_modules) . " distinctly versioned modules found";
403 # do not announce anything under ci - we are watching for STDERR silence
404 exit 0 if DBICTest::RunMode->is_ci;
407 # diag the result out
408 my $max_ver_len = max map
410 ( 'xxx.yyyzzz_bbb', map { $_->{version} || '' } values %$interesting_modules )
412 my $max_marker_len = max map { length $_ } ( '$INC[999]', keys %$seen_markers );
416 List of loadable modules within both the core and *OPTIONAL* dependency chains
417 present on this system (modules sourced from ./blib, ./lib, ./t, and ./xt
418 with versions identical to their parent namespace were omitted for brevity)
420 *** Note that *MANY* of these modules will *NEVER* be loaded ***
421 *** during normal operation of DBIx::Class ***
424 # pre-assemble everything and print it in one shot
425 # makes it less likely for parallel test execution to insert bogus lines
426 my $final_out = "\n$discl\n";
428 $final_out .= "\@INC at startup (does not reflect manipulation at runtime):\n";
431 for (0.. $#initial_INC) {
433 my $shortname = shorten_fn( $initial_INC[$_] );
435 # when *to* print a line of INC
437 ! $ENV{AUTOMATED_TESTING}
441 $seen_markers->{"\$INC[$_]"}
445 ! File::Spec->file_name_is_absolute($shortname)
448 $final_out .= sprintf ( "% 3s: %s\n",
453 elsif(! $in_inc_skip++) {
454 $final_out .= " ...\n";
460 if (my @seen_known_paths = grep { $known_paths->{$_} } keys %$seen_markers) {
462 $final_out .= join "\n", 'Sourcing markers:', (map
465 $max_marker_len => $_->{marker},
466 ($_->{config_key} ? "\$Config{$_->{config_key}}" : "$_->{rel_path}/" )
470 !!$b->{config_key} cmp !!$a->{config_key}
472 ( $a->{marker}||'') cmp ($b->{marker}||'')
474 @{$known_paths}{@seen_known_paths}
479 $final_out .= "=============================\n";
481 $final_out .= join "\n", (map
484 $max_marker_len => $interesting_modules->{$_}{source_marker} || '',
485 $max_ver_len => ( defined $interesting_modules->{$_}{version}
486 ? $interesting_modules->{$_}{version}
490 ($interesting_modules->{$_}{abs_unix_path}
491 ? " [ MD5: @{[ get_md5( $interesting_modules->{$_}{abs_unix_path} ) ]} ]"
492 : "! -f \$INC{'@{[ module_notional_filename($_) ]}'}"
495 sort { lc($a) cmp lc($b) } keys %$interesting_modules
498 $final_out .= "=============================\n$discl\n\n";
506 sub say_err { print STDERR "\n", @_, "\n\n" };
508 # do !!!NOT!!! use Module::Runtime's require_module - it breaks CORE::require
509 sub try_module_require {
510 # trap deprecation warnings and whatnot
511 local $SIG{__WARN__} = sub {};
513 eval "require $_[0]";
520 ( -e $_[0] or File::Spec->file_name_is_absolute($_[0]) )
523 # File::Spec's rel2abs does not resolve symlinks
524 # we *need* to look at the filesystem to be sure
525 my $abs_fn = abs_path($_[0]);
527 if ( $^O eq 'MSWin32' and $abs_fn ) {
529 # sometimes we can get a short/longname mix, normalize everything to longnames
530 $abs_fn = Win32::GetLongPathName($abs_fn);
532 # Fixup (native) slashes in Config not matching (unixy) slashes in INC
542 my $abs_fn = abs_unix_path($fn);
544 if (my $p = subpath_of_known_path( $fn ) ) {
545 $abs_fn =~ s| (?<! / ) $|/|x
548 if ($p->{rel_path}) {
549 $abs_fn =~ s!\Q$p->{abs_unix_path}!$p->{rel_path}!
552 elsif ($p->{config_key}) {
553 $abs_fn =~ s!\Q$p->{abs_unix_path}!<<$p->{marker}>>!
555 $seen_markers->{$p->{marker}} = 1
561 # we got so far - not a known path
562 # return the unixified version it if was absolute, leave as-is otherwise
563 my $rv = ( $abs_fn and File::Spec->file_name_is_absolute( $fn ) )
568 $rv = "( ! -e ) $rv" unless -e $rv;
573 sub subpath_of_known_path {
574 my $abs_fn = abs_unix_path( $_[0] )
579 length( $b->{abs_unix_path} ) <=> length( $a->{abs_unix_path} )
581 ( $a->{match_order} || 0 ) <=> ( $b->{match_order} || 0 )
585 # run through the matcher twice - first always append a /
587 # important to avoid false positives
588 for my $suff ( '/', '' ) {
589 return { %$p } if 0 == index( $abs_fn, "$p->{abs_unix_path}$suff" );
594 sub module_found_at_inc_index {
595 my ($mod, $inc_dirs) = @_;
597 return undef unless @$inc_dirs;
599 my $fn = module_notional_filename($mod);
601 for my $i ( 0 .. $#$inc_dirs ) {
603 # searching from here on out won't mean anything
604 # FIXME - there is actually a way to interrogate this safely, but
605 # that's a fight for another day
606 return undef if length ref $inc_dirs->[$i];
611 -f "$inc_dirs->[$i]/$fn"
613 -r "$inc_dirs->[$i]/$fn"
622 sub purge_identically_versioned_submodules_with_markers {
625 return unless @$markers;
627 for my $mod ( sort { length($b) <=> length($a) } keys %$interesting_modules ) {
629 next unless defined $interesting_modules->{$mod}{version};
631 my $marker = $interesting_modules->{$mod}{source_marker}
634 next unless grep { $marker eq $_ } @$markers;
638 while ( $parent =~ s/ :: (?: . (?! :: ) )+ $ //x ) {
639 $interesting_modules->{$parent}
641 ($interesting_modules->{$parent}{version}||'') eq $interesting_modules->{$mod}{version}
643 ($interesting_modules->{$parent}{source_marker}||'') eq $interesting_modules->{$mod}{source_marker}
645 delete $interesting_modules->{$mod}
652 sub module_notional_filename {
653 (my $fn = $_[0] . '.pm') =~ s|::|/|g;
658 # we already checked for -r/-f, just bail if can't open
659 open my $fh, '<:raw', $_[0] or return '';
660 Digest::MD5->new->addfile($fh)->hexdigest;