View on
MetaCPAN is shutting down
For details read Perl NOC. After June 25th this page will redirect to
Linda A Walsh > Xporter-0.0.11 > Xporter



Annotate this POD


Open  0
View/Report Bugs
Module Version: 0.0.11   Source   Latest Release: Xporter-0.1.2


Xporter - Alternative Exporter with persistant defaults & auto-ISA


Version "0.0.11"


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), 

    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:


  4 + 5 = 9

(Or in a test:)

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


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.


Suppose your exporting function has exports:

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

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.

syntax highlighting: