Paranoid as I am, I am wondering whether the automatic loading of Foo::* modules isn't opening some serious security holes, because you can never know whether someone hasn't put a "Foo::Takeovereverything" module somewhere in @INC (especially with "." usually being part of @INC). Of course, this could be considered a feature as well.
Personally, I like the following idiom better for object oriented modules, as it makes it easier to use a lot of modules _and_ still keep a better overview:
use Foo qw(Bar Baz);
which would be equivalent to:
use Foo ();
use Foo::Bar ();
use Foo::Baz ();
Foo::import would look something like this:
my @module = qw(Bar Baz); # allowable modules
my %module = map {$_ => 1} @module; # easy lookup of modules
sub import {
my $class = shift;
return if $class ne 'Foo'; # allow import to be inherited by submo
+dules
my @require; # list of modules to be required
if (@_) {
foreach (@_) {
if ($_ eq ':all') {
@require = @module;
} elsif ($module{$_}) {
push @require,$_;
} else {
warn "Don't know how to load Foo::$_\n";
}
}
} else {
@require = @module;
}
foreach (@require) {
next if eval "require Foo::$_;"; # string eval for easiness
warn "Foo::$_: $@"; # could be die also if you prefer
}
} #import
With apologies to those for whom this would be bleedingly obvious.
Liz
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.