Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options

Universally unimportant and overused

by tye (Sage)
on Mar 23, 2001 at 11:48 UTC ( #66587=snippet: print w/replies, xml ) Need Help??
Description: This is a small modification for for Win32 (or any other operating system that supports file systems where the letter case of file names is ignored) that detects when you get the letter case of a module name incorrect.

If you put this code in place of 3 lines of your perl/lib/ file (the three lines that nearly match the first three lines of this code) and then do "SET PERL5OPT=-mUNIVERSAL" in your AUTOEXEC.BAT file (or use some other method to get that environment variable set) then writing use Strict; becomes a fatal error instead of a silent and useless mistake.

If you are feeling particularly obsessive/compulsive, you can also set PERL5OPT="-MUNIVERSAL=overused,unimportant". The "overused" part will generate a warning if you use a module that you might as well have just required. The "unimportant" part will prevent Exporter::import() from being called when you use a module that didn't actually arrange for that to happen (currently, Exporter::import() is called whenever you use a module that doesn't define any import method at all, even it that module doesn't even mention Exporter -- this will probably be "fixed" at some point but with this you can "fix" it now and see if you are using any modules that depend on this "bug").

Just to be nice (or perverse), case is ignored for all of these options so you can use "PERL5OPT=-MUniversal=overUse,unImport" (the "d" in "overused" and the "ant" in "unimportant" are also optional).

require Exporter;
#*import = \&Exporter::import;
@EXPORT_OK = qw(isa can);
my( $overused, $unimportant );
sub import {
    my( $pack )= @_;
    if(  $pack =~ /^UNIVERSAL$/i  ) {
        @_= grep { not /^overused?$/i ? ( $overused= 1 )
                     : /^unimport(ant)?$/i ? ( $unimportant= 1 ) : 0 }
+ @_;
        goto &Exporter::import;
    } elsif(  keys %{$pack."::"} <= 1  ) {
        my @matches= ( "::" );
        foreach my $file (  split /::/, $pack  ) {
            @matches= map {
                my $match= $_;
                my @files= grep /^\Q$file\E::$/i, keys %{$match};
                map { $match.$_ } @files;
            } @matches;
        @matches= grep { s/^:://; s/::$//; $_ ne $pack } @matches;
        die "$pack->import() called for empty package!\nPerhaps you ne
+ed to use ",
            1 == @matches ? "C<use @matches> instead.\n"
            : @matches ? "one of these (@matches).\n"
            : "different upper/lower case in C<use $pack>.\n";
    } else {
        warn "C<use $pack> but no $pack\::import().\n"
          if  $overused;
        goto &Exporter::import
          unless  $unimportant;
Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: snippet [id://66587]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (2)
As of 2017-07-22 23:18 GMT
Find Nodes?
    Voting Booth?
    I came, I saw, I ...

    Results (342 votes). Check out past polls.