in reply to Die On Warnings

I use a technique somewhat similar as a test harness when I first get a script. I created a module that actually will force the importing module to use strict and warnings as well as install confess as the default die and warning handler. I use this only for testing purposes and never production code.

package WarningsStrictAndCarpOhMy; # worst name ever, I know use 5.006_001; use Carp; use strict; use warnings; sub import { my %config; undef @config{@_}; $^H |= strict->import unless exists $config{'no_strict'}; ${^WARNING_BITS} |= warnings->import; $SIG{__DIE__} = \&wasnt_me; $SIG{__WARN__} = \&wasnt_me; } sub wasnt_me { Carp::confess($_[0]); } 1;

Just thought someone else might be able to get some use out of it

antirice    
The first rule of Perl club is - use Perl
The
ith rule of Perl club is - follow rule i - 1 for i > 1

Replies are listed 'Best First'.
Re: Re: Die On Warnings
by rkg (Hermit) on Sep 05, 2003 at 17:50 UTC
    Can you explain the 1st two lines? They look like magic to me.
    undef @config{@_}; $^H |= strict->import unless exists $config{'no_strict'};
    Thanks --
    rkg

      The first two lines declare a hash and fill the hash with the elements of @_ as keys with each pointing to undef. The third line of the sub does a bitwise-or on $^H with the return of the default strict import unless "no_strict" was in @_. The first two lines are just a quick way of telling whether or not "no_strict" was present in the import list.

      In other words you control what operation gets performed from the import list. For more information I offer the following reading material: perldsc, use, Exporter, perlvar and perlmod.

      Hope this helps.

      antirice    
      The first rule of Perl club is - use Perl
      The
      ith rule of Perl club is - follow rule i - 1 for i > 1