August 1999 Perl Hardware Store Slide #17

Clone the Exporter

You don't need Exporter to export. If you want the simple features, it's easy to do it yourself.

         package Ziggurat;
         my @EXPORTS = qw(this that other);
         my %EXPORTED = map {$_ => 1} @EXPORTS;
         sub import {
           my $pack = shift;
           my $caller = caller;
           foreach $func (@_) {
             croak "`$func' not exported" 
             unless $EXPORTED{$func};
             *{$caller . '::' . $func} = \&$func;
           }
         }

As you can see, we didn't need 476 lines here.


Next Copyright © 1998 M-J. Dominus