Shmuel Fomberg wrote:
> How about importing mysub from Foo::Bar to Foo, and let Exporter to deal
> with the next step?
> package Foo;
> use Foo::Bar qw{mysub};
> our @EXPORT = qw{ mysub };
> should work.

I was wondering about that idea, but was doubtful.  Let's try it:

2011-01-16 13:47:47 dpchrist@p43400e ~
$ cat foo-bar-mysub.pl
#!/usr/bin/perl

package Foo::Bar;
require Exporter;
our @ISA = qw( Exporter );
our %EXPORT_TAGS = ( 'all' => [qw( mysub )]);
our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
our @EXPORT = ();
sub mysub { print "hello, world!\n" }

package Foo;
our @ISA = qw( Exporter );
Foo::Bar->import qw( mysub );
require Exporter;
our %EXPORT_TAGS = ( 'all' => [qw( mysub )] );
our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
our @EXPORT = ();

package main;
use strict;
use warnings;
Foo->import qw(mysub);
mysub();

2011-01-16 13:48:50 dpchrist@p43400e ~
$ perl -c foo-bar-mysub.pl
foo-bar-mysub.pl syntax OK

2011-01-16 13:48:52 dpchrist@p43400e ~
$ perl foo-bar-mysub.pl
hello, world!


It seems to work for this simple case...


Are there other ways?


David

Reply via email to