Next | Tricks of the Wizards | 19 |
Here's a slightly more full-featured exporter.
package Rings; use Carp;
%exports = map {$_ => 1} qw(Narya Nenya Vilya);
sub import { my $caller = caller; my $package = shift; for my $name (@_) { unless ($exports{$name}) { croak("Module $package does not export &$name; aborting"); } *{$caller . '::' . $name} = \&{'Rings::' . $name}; } }
sub Narya { ... } sub Nenya { ... } sub Vilya { ... }
In the main program, calls like this:
use Rings qw(Narya Nenya Fred);
Turn into this:
Rings->import(qw(Narya Nenya Fred));
Next | Copyright © 2003 M. J. Dominus |