How to call the standard Exporter::import routine


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::parser' or $sub eq 'XML::parsepp') {
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::parser';
}

if ($use_module eq 'XML::parser') {
require XML::parser;
}
elsif ($use_module eq 'XML::parsepp') {
require XML::parsepp;
}
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 ?
 
Ad

Advertisements


Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top