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

cool use for GLOBAL_PHASE

Thread Next
From:
Tom Christiansen
Date:
April 24, 2011 19:18
Subject:
cool use for GLOBAL_PHASE
Message ID:
22669.1303697894@chthon
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?

--tom

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About