Beefy Boxes and Bandwidth Generously Provided by pair Networks Frank
No such thing as a small change.
 
PerlMonks

Universally unimportant and overused

by tye (Archbishop)
 | Log in | Create a new user | The Monastery Gates | Super Search | 
 | Seekers of Perl Wisdom | Meditations | PerlMonks Discussion | 
 | Obfuscation | Reviews | Cool Uses For Perl | Perl News | Q&A | Tutorials | 
 | Poetry | Recent Threads | Newest Nodes | Donate | What's New | 

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

Login:
Password
remember me
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 perusing the Monastery: (16)
jdporter
holli
Gavin
CardinalNumber
kennethk
thezip
Eyck
NodeReaper
LanX
ssandv
je44ery
BenHopkins
MikeDexter
pmqs
Spakz
pramod8785
As of 2010-02-09 22:55 GMT
Sections?
The Monastery Gates
Seekers of Perl Wisdom
Meditations
PerlMonks Discussion
Categorized Q&A
Tutorials
Obfuscated Code
Perl Poetry
Cool Uses for Perl
Perl News
Information?
PerlMonks FAQ
Guide to the Monastery
What's New at PerlMonks
Voting/Experience System
Tutorials
Reviews
Library
Perl FAQs
Other Info Sources
Find Nodes?
Nodes You Wrote
Super Search
List Nodes By Users
Newest Nodes
Recently Active Threads
Selected Best Nodes
Best Nodes
Worst Nodes
Saints in our Book
Leftovers?
The St. Larry Wall Shrine
Offering Plate
Awards
Craft
Snippets Section
Code Catacombs
Quests
Editor Requests
Buy PerlMonks Gear
PerlMonks Merchandise
Planet Perl
Perlsphere
Use Perl
Perl.com
Perl 5 Wiki
Perl Jobs
Perl Mongers
Perl Directory
Perl documentation
CPAN
Random Node
Voting Booth?

What level of existential comfort do you require?

Palace
Executive suite at the best hotel
Regular hotel in a decent part of town
Motel
Boarding house
Sleeping Bag on Couch in Basement
Any port in a storm
Camping under the freeway overpass
Jail
Other

Results (283 votes), past polls