Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Universally unimportant and overused

by tye (Cardinal)
on Mar 23, 2001 at 11:48 UTC ( #66587=snippet: print w/ replies, xml ) Need Help??

Description: This is a small modification for UNIVERSAL.pm 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/UNIVERSAL.pm 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;
    }
}
Comment on Universally unimportant and overused
Download Code

Back to Snippets Section

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: snippet [id://66587]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (13)
As of 2014-09-18 10:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (111 votes), past polls