in reply to Detecting broken modules

Overriding require seems to work:
# file TestModule.pm: package TestModule; die; 1; # file test.pl use strict; use warnings; use lib '.'; our %failed; BEGIN { *CORE::GLOBAL::require = sub { my $success = eval { CORE::require($_[0]) }; $failed{$_[0]} = 1 unless $success; return $success; }; } use TestModule; use CGI; use Data::Dumper; print Dumper \%failed;

In this case use Module will never fail, which is good for testing but bad in general, so you might want to croak $@ unless $success after marking the module load as failed.

Replies are listed 'Best First'.
Re^2: Detecting broken modules
by ELISHEVA (Prior) on Jun 29, 2009 at 20:43 UTC

    Thanks for the example. I'm leaning in this direction if no general solution exists. My main problem with the override approach is that it only really works with certainty if you have one and only one entry point to your code (e.g. the test script). Otherwise, the overridden require only takes effect after the module defining it is loaded. Anything before that will be loaded by normal require and won't show up in the broken hash.

    Best, beth