Next Tricks of the Wizards 196

Exportation (Inheritable Method)

        package Rings;
        use Carp;
        %exports = map {$_ => 1} qw(Narya Nenya Vilya);
        sub import {
          my $caller = caller;
          my $package = shift;
            my $exported = \%{$package . '::exports'};
          for my $name (@_) {
              unless ($exported->{$name}) {
              croak("Module $package does not export &$name; aborting");
            }
              *{$caller . '::' . $name} = \&{$package . '::' . $name};
          }
        }


Next Copyright © 2003 M. J. Dominus