BEGIN { if ( $] < 5.009004 ) { my $src = <<'UNITCHECK'; print "Inventing UNITCHECK for $]\n"; require B; # This is a stub function. It exists just to capture the block that will # follow it as a parameter. Magic will find this later and call its argument. sub UNITCHECK (&) {} CHECK { # Read all the values in the main_cv's PADLIST. This probably doesn't work # for files that aren't the "main" script. for my $cv ( B::main_cv->PADLIST->ARRAY->ARRAY ) { # Find all anonymous subroutines. next unless $cv->isa( 'B::CV' ); # Hey! I'm missing the check to see that I'm in a UNITCHECK block! # WTF!? Was the author on crack?! This is promiscuous as hell! # Call the anonymous function. my $sub = $cv->object_2svref; $sub->(); } } 1; UNITCHECK eval $src or die "$@\n$src"; } } UNITCHECK { print "Ok!\n"; }