in reply to DWIM: autoloading classes
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:
which would be equivalent to:use Foo qw(Bar Baz);
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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: DWIM: autoloading classes
by tsee (Curate) on Sep 17, 2003 at 23:26 UTC | |
by liz (Monsignor) on Sep 18, 2003 at 07:00 UTC | |
by tsee (Curate) on Sep 18, 2003 at 16:59 UTC |