Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > How to call the standard Exporter::import routine

Reply
Thread Tools

How to call the standard Exporter::import routine

 
 
Klaus
Guest
Posts: n/a
 
      06-24-2012
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 ?
 
Reply With Quote
 
 
 
 
Klaus
Guest
Posts: n/a
 
      06-25-2012
On 24 juin, 21:03, Ben Morrow <(E-Mail Removed)> wrote:
> Quoth Klaus <(E-Mail Removed)>:
>
> > 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.

>
> See Exporter->export_to_level.


Thanks, works perfectly.

-- Klaus
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
Call Java routine in ASP.NET sweetpotatop@yahoo.com ASP .Net 2 05-14-2007 01:46 PM
Common Routine To Call (Almost) Identical Functions gamename C Programming 5 05-03-2007 08:51 PM
call a routine from Javascript RicercatoreSbadato ASP .Net 1 09-11-2006 09:57 AM
How to call a javascript routine to stream an audio file KiwiBrian HTML 3 11-30-2005 05:40 PM



Advertisments