The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Xporter - an exporter with persistant defaults & auto-ISA

VERSION

Version "0.0.5"

SYNOPIS

In the "Exporting" module:

  { package module_adder; use warnings; use strict;
    use mem;
    our (@EXPORT, @EXPORT_OK);
    our $lastsum;
    our @lastargs;
    use Xporter(@EXPORT=qw(adder $lastsum @lastargs), 
                        @EXPORT_OK=qw(print_last_result));

    sub adder($$) {@lastargs=@_; $lastsum=$_[0]+$_[1]}
    sub print_last_result () {
      use P;    # using P allows answer printed or as string
      if (@lastargs && defined $lastsum){
        P "%s = %s\n", (join ' + ' , @lastargs), $lastsum;
      }
    }
  }

In using module (same or different file)

  package main;  use warnings; use strict;
  use module_adder qw(print_last_result);

  adder 4,5;

Printing output:

  print_last_result();

  #Result:
  
  4 + 5 = 9

(Or in a test:)

  ok(print_last_result eq "4 + 5 = 9", "a pod test");

DESCRIPTION

Xporter provides Export functionality similar to Exporter, with some different behaviors to simplify common cases.

One primary difference, in Xporter is that the default EXPORT list remains the default EXPORT list unless you specifically ask for it to not be included.

In Exporter, if you ask for an addition export from the EXPORT_OK list, you automatically lose your defaults. The theory here being that if you want something extra you shouldn't be required to lose your default list. The default list is easily enough NOT included by specifying '-' or '!' as the first parameter in the client's import list.

Example

Suppose your exporting function has exports:

  our (@EXPORT, @EXPORT_OK);
  use Xporter(@EXPORT=qw(one $two %three @four), 
              @EXPORT_OK=qw(&five));

In the using module, to only import symbols 'two' and 'five', one would use:

  use MODULENAME qw(! $two five);

That negates the default EXPORT list, and lets you selectively import the values you want from either the default or the OK list (modules in the default list don't need to be relisted in the OK list as it is presumed that they were OK to be exported or they would not have been defaults).

Other functions of Exporter are not currently implemented though may appear in later versions should those features be needed.

Listing the EXPORT and EXPORT_OK assignments as params to Xporter allow their types to be available to importing modules at compile time.