NAME
Xporter - Alternative Exporter with persistant defaults & auto-ISA
VERSION
Version "0.0.12"
SYNOPIS
In the "Exporting" module:
{ package module_adder [optional version];
use warnings; use strict;
use mem; # to allow using module in same file
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 use
-ing 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 module 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.
Version Strings
Version strings in the form of a decimal fraction, (0.001001), a V-String (v1.2.1 with no quotes), or a version string ('1.1.1' or 'v1.1.1') are supported, though note, versions in different formats are not interchangeable. The format used in a modules documentation should be used.