Next Tricks of the Wizards 19

Exportation

     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 { ... }
     use Rings qw(Narya Nenya Fred);
     Rings->import(qw(Narya Nenya Fred));


Next Copyright © 2003 M. J. Dominus