develooper Front page | perl.perl5.porters | Postings from April 2011

cool use for GLOBAL_PHASE

Thread Next
Tom Christiansen
April 24, 2011 19:18
cool use for GLOBAL_PHASE
Message ID:
Here's a work-around for the problem that you can't use fatal
warnings because they abort the compiler too early.

    use v5.14;
    use warnings; # FATAL => all
    # this works around the bug of fatal warnings screwing
    # up your compilation
    BEGIN {
	use Carp qw<cluck confess>;
	my $forewarned = 0;
	$SIG{__WARN__} = sub {
	    if (${^GLOBAL_PHASE} eq "START") { $forewarned++; warn      @_  }
	    else                             { confess "Deadly warning: @_" }
	INIT { die "Can't continue with compilation warnings" if $forewarned }
    $SIG{__DIE__} = sub { confess "Uncaught exception: $@" unless $^S };

It seems to work well.  Can anyone see any problems with it?


Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About