develooper Front page | perl.perl6.language | Postings from December 2001

Re: Perl 6's Exporter

Thread Previous | Thread Next
Uri Guttman
December 22, 2001 09:41
Re: Perl 6's Exporter
Message ID:
>>>>> "BD" == Brent Dax <> writes:

  BD> # > 	1. Choosing where to export to:
  BD> # > 		use Data::Dumper 'Dumper' => 'dumpvar';
  BD> # > 		#exports Data::Dumper::Dumper to Main::dumpvar
  BD> # (or whatever)
  BD> #
  BD> # Where to import to.  It's probably not a good idea to export
  BD> # into someone
  BD> # else's namespace.  (Pull vs Push).

  BD> Ack, I hate terminology bugs.  Import to.  As for someone else's
  BD> namespace, under the current implementation (*bursts out
  BD> laughing*) that don't work too well anyway.

i already support that type of customized import in a trace/debug
module. in the use line i pass in an option key/value pair of sub =>
name and the sub is imported with that name. as the sub is a closure and
can be one of several calling styles (selected by another option), you
can import it multiple times (with multiple use statements) and get
different imported subs.

it looks like this:

use Debug sub => 'foo', style => 'text_args', level => 5 ;
use Debug sub => 'bar', style => 'key_value', level => 3 ;

	foo 'send text only to debug system' ;

	bar 'text' => 'send this text, override the level', level => 4 ;

this is all done by a single import sub in that module. in fact it is
the only sub in that module.

generalizing this to be used in Exporter would not be easy as it creates
closures (e.g. storing the debug level) and can even select the code ref
to use. you would have to pass too much info to Exporter to make this


Uri Guttman  ------  --------
-- Stem is an Open Source Network Development Toolkit and Application Suite -
----- Stem and Perl Development, Systems Architecture, Design and Coding ----
Search or Offer Perl Jobs  ----------------------------

Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About