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
10 # Pre-5.10 perls pollute %INC on unsuccesfull module
11 # require, making it appear as if the module is already
12 # loaded on subsequent require()s
13 # Can't seem to find the exact RT/perldelta entry
15 # The reason we can't just use a sane, clean loader, is because
16 # if a Module require()s another module the %INC will still
17 # get filled with crap and we are back to square one. A global
18 # fix is really the only way for this test, as we try to load
19 # each available module separately, and have no control (nor
20 # knowledge) over their common dependencies.
22 # we want to do this here, in the very beginning, before even
23 # warnings/strict are loaded
25 unshift @INC, 't/lib';
26 require DBICTest::Util::OverrideRequire;
28 DBICTest::Util::OverrideRequire::override_global_require( sub {
29 my $res = eval { $_[0]->() };
39 # Explicitly add 'lib' to the front of INC - this way we will
40 # know without ambiguity what was loaded from the local untar
41 # and what came from elsewhere
42 use lib qw(lib t/lib);
47 use Test::More 'no_plan';
49 use File::Find 'find';
50 use Module::Runtime 'module_notional_filename';
51 use List::Util qw(max min);
52 use ExtUtils::MakeMaker;
53 use DBICTest::Util 'visit_namespaces';
55 # load these two to pull in the t/lib armada
58 DBICTest->init_schema;
60 # do !!!NOT!!! use Module::Runtime's require_module - it breaks CORE::require
62 # trap deprecation warnings and whatnot
63 local $SIG{__WARN__} = sub {};
69 print STDERR "\n", @_, "\n";
74 return $_[0] unless ( $^O eq 'MSWin32' and $_[0] );
76 # sometimes we can get a short/longname mix, normalize everything to longnames
77 my $fn = Win32::GetLongPathName($_[0]);
79 # Fixup (native) slashes in Config not matching (unixy) slashes in INC
85 my @lib_display_order = qw(
96 ? ( $_ => fixup_path( $Config{"${_}exp"} || $Config{$_} ) )
102 # synthetic, for display
109 return '' if !defined $fn;
111 $fn = fixup_path( $fn );
113 $lib_paths->{$_} and $fn =~ s/^\Q$lib_paths->{$_}/<<$_>>/ and last
114 for @lib_display_order;
120 # we already checked for -r/-f, just bail if can't open
121 open my $fh, '<:raw', $_[0] or return '';
123 Digest::MD5->new->addfile($fh)->hexdigest;
126 # first run through lib and *try* to load anything we can find
127 # within our own project
132 # can't just `require $fn`, as we need %INC to be
134 my ($mod) = $_ =~ /^ lib [\/\\] (.+) \.pm $/x
137 req_mod join ('::', File::Spec->splitdir($mod));
142 # now run through OptDeps and attempt loading everything else
144 # some things needs to be sorted before other things
145 # positive - load first
146 # negative - load last
148 # Make sure oracle is tried last - some clients (e.g. 10.2) have symbol
149 # clashes with libssl, and will segfault everything coming after them
150 "DBD::Oracle" => -999,
157 { keys %{DBIx::Class::Optional::Dependencies->req_list_for($_)} }
160 keys %{DBIx::Class::Optional::Dependencies->req_group_list}
163 { ($load_weights->{$b}||0) <=> ($load_weights->{$a}||0) }
167 my $has_versionpm = eval { require version };
169 # at this point we've loaded everything we ever could, let's drill through
170 # the *ENTIRE* symtable and build a map of versions
171 my $version_list = { perl => $] };
172 visit_namespaces( action => sub {
176 # keep going, but nothing to see here
177 return 1 if $pkg eq 'main';
179 # private - not interested, including no further descent
180 return 0 if $pkg =~ / (?: ^ | :: ) _ /x;
182 # not interested in no-VERSION-containing modules, nor synthetic classes
184 ! defined ${"${pkg}::VERSION"}
186 ${"${pkg}::VERSION"} =~ /\Qset by base.pm/
189 # make sure a version can be extracted, be noisy when it doesn't work
190 # do this even if we are throwing away the result below in lieu of EUMM
191 my $mod_ver = eval { $pkg->VERSION };
195 "Calling `$pkg->VERSION` resulted in an exception, which should never "
196 . "happen - please file a bug with the distribution containing $pkg. "
197 . "Complete exception text below:\n\n$err"
200 elsif( ! defined $mod_ver or ! length $mod_ver ) {
201 my $ret = defined $mod_ver
202 ? "the empty string ''"
207 "Calling `$pkg->VERSION` returned $ret, even though \$${pkg}::VERSION "
208 . "is defined, which should never happen - please file a bug with the "
209 . "distribution containing $pkg."
215 # if this is a real file - extract the version via EUMM whenever possible
216 my $fn = $INC{module_notional_filename($pkg)};
225 eval { MM->parse_version( $fn ) }
235 $eumm_ver ne $mod_ver
238 ( eval { version->parse( do { (my $v = $eumm_ver) =~ s/_//g; $v } ) } || 0 )
240 ( eval { version->parse( do { (my $v = $mod_ver) =~ s/_//g; $v } ) } || 0 )
244 "Mismatch of versions '$mod_ver' and '$eumm_ver', obtained respectively "
245 . "via `$pkg->VERSION` and parsing the version out of @{[ describe_fn $fn ]} "
246 . "with ExtUtils::MakeMaker\@@{[ ExtUtils::MakeMaker->VERSION ]}. "
247 . "This should never happen - please check whether this is still present "
248 . "in the latest version, and then file a bug with the distribution "
253 if( defined $eumm_ver ) {
254 $version_list->{$pkg} = $eumm_ver;
256 elsif( defined $mod_ver ) {
257 $version_list->{$pkg} = $mod_ver;
263 # In retrospect it makes little sense to omit this information - just
264 # show everything at all times.
265 # Nevertheless leave the dead code, in case it turns out to be a bad idea...
267 #my $show_all = $ENV{PERL_DESCRIBE_ALL_DEPS} || !DBICTest::RunMode->is_plain;
269 # compress identical versions as close to the root as we can
270 # unless we are dealing with a smoker - in which case we want
271 # to see every MD5 there is
273 for my $mod ( sort { length($b) <=> length($a) } keys %$version_list ) {
276 while ( $parent =~ s/ :: (?: . (?! :: ) )+ $ //x ) {
277 $version_list->{$parent}
279 $version_list->{$parent} eq $version_list->{$mod}
281 ( ( delete $version_list->{$mod} ) or 1 )
288 ok 1, (scalar keys %$version_list) . " distinctly versioned modules";
290 exit if ($ENV{TRAVIS}||'') eq 'true';
292 # sort stuff into @INC segments
296 for my $mod ( sort { lc($a) cmp lc($b) } keys %$version_list ) {
297 my $fn = $INC{module_notional_filename($mod)};
299 my $tuple = [ $mod ];
301 if ( defined $fn && -f $fn && -r $fn ) {
302 push @$tuple, ( $fn = fixup_path($fn) );
304 for my $lib (@lib_display_order, './lib') {
305 if ( $lib_paths->{$lib} and index($fn, $lib_paths->{$lib}) == 0 ) {
306 push @{$segments->{$lib}}, $tuple;
312 # fallthrough for anything without a physical filename, or unknown lib
313 push @{$segments->{''}}, $tuple;
316 # diag the result out
317 my $max_ver_len = max map
319 ( values %$version_list, 'xxx.yyyzzz_bbb' )
321 my $max_mod_len = max map { length $_ } keys %$version_list;
325 Versions of all loadable modules within both the core and *OPTIONAL* dependency chains present on this system
326 Note that *MANY* of these modules will *NEVER* be loaded during normal operation of DBIx::Class
329 $discl .= "(modules with versions identical to their parent namespace were omitted - set PERL_DESCRIBE_ALL_DEPS to see them)\n"
336 for my $seg ( '', @lib_display_order, './lib' ) {
337 next unless $segments->{$seg};
339 diag sprintf "=== %s ===\n\n",
341 ? "Modules found in " . ( $Config{$seg} ? "\$Config{$seg}" : $seg )
347 $max_ver_len => $version_list->{$_->[0]},
348 -$max_mod_len => $_->[0],
350 ? ' ' x (80 - min(78, $max_mod_len)) . "[ MD5: @{[ md5_of_fn( $_->[1] ) ]} ]"
353 ) for @{$segments->{$seg}};