K
Klaus
Hi everybody,
I am trying to write a custom import routine for one of my modules,
but I am having trouble calling the standard Exporter::import routine
from inside my custom import routine.
here is my code:
==================
package XML::Reader;
use strict;
use warnings;
use Carp;
require Exporter;
our @ISA = qw(Exporter);
our %EXPORT_TAGS = ( all => [ qw(slurp_xml) ] );
our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
our @EXPORT = qw();
our $VERSION = '0.40';
my $use_module;
sub import {
my $calling_module = shift;
my @plist;
for my $sub (@_) {
if ($sub eq 'XML:
arser' or $sub eq 'XML:
arsepp') {
if (defined $use_module) {
die "Duplicate module ('$use_module' and '$sub')";
}
$use_module = $sub;
}
else {
push @plist, $sub;
}
}
unless (defined $use_module) {
$use_module = 'XML:
arser';
}
if ($use_module eq 'XML:
arser') {
require XML:
arser;
}
elsif ($use_module eq 'XML:
arsepp') {
require XML:
arsepp;
}
else {
die "Can't identify use_module = '$use_module'";
}
no strict 'refs';
my ($package, $file, $line) = caller;
for my $sub (@plist) {
my $found = 0;
for my $ex_ok (@EXPORT_OK) {
if ($sub eq $ex_ok) {
$found = 1;
last;
}
}
if ($found) {
*{$package."::$sub"} = \&$sub;
}
else {
die "Requested invalid subroutine '$sub'";
}
}
}
===============
My program basically works, but I am not happy about the following
code section
===============
no strict 'refs';
my ($package, $file, $line) = caller;
for my $sub (@plist) {
my $found = 0;
for my $ex_ok (@EXPORT_OK) {
if ($sub eq $ex_ok) {
$found = 1;
last;
}
}
if ($found) {
*{$package."::$sub"} = \&$sub;
}
else {
die "Requested invalid subroutine '$sub'";
}
}
===============
That part of the code should normally be handled by
Exoprter::import(), but how do I call it ?
I am trying to write a custom import routine for one of my modules,
but I am having trouble calling the standard Exporter::import routine
from inside my custom import routine.
here is my code:
==================
package XML::Reader;
use strict;
use warnings;
use Carp;
require Exporter;
our @ISA = qw(Exporter);
our %EXPORT_TAGS = ( all => [ qw(slurp_xml) ] );
our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
our @EXPORT = qw();
our $VERSION = '0.40';
my $use_module;
sub import {
my $calling_module = shift;
my @plist;
for my $sub (@_) {
if ($sub eq 'XML:
if (defined $use_module) {
die "Duplicate module ('$use_module' and '$sub')";
}
$use_module = $sub;
}
else {
push @plist, $sub;
}
}
unless (defined $use_module) {
$use_module = 'XML:
}
if ($use_module eq 'XML:
require XML:
}
elsif ($use_module eq 'XML:
require XML:
}
else {
die "Can't identify use_module = '$use_module'";
}
no strict 'refs';
my ($package, $file, $line) = caller;
for my $sub (@plist) {
my $found = 0;
for my $ex_ok (@EXPORT_OK) {
if ($sub eq $ex_ok) {
$found = 1;
last;
}
}
if ($found) {
*{$package."::$sub"} = \&$sub;
}
else {
die "Requested invalid subroutine '$sub'";
}
}
}
===============
My program basically works, but I am not happy about the following
code section
===============
no strict 'refs';
my ($package, $file, $line) = caller;
for my $sub (@plist) {
my $found = 0;
for my $ex_ok (@EXPORT_OK) {
if ($sub eq $ex_ok) {
$found = 1;
last;
}
}
if ($found) {
*{$package."::$sub"} = \&$sub;
}
else {
die "Requested invalid subroutine '$sub'";
}
}
===============
That part of the code should normally be handled by
Exoprter::import(), but how do I call it ?