unexpected error with Exporter

D

Daniel

I've got quite a large programme that's working just fine except for a
few minor bugs and several design flaws. So I've decided to clean it up
a bit. It uses several self-written objects and modules, so I thought a
good way to start would be to put them in a sub directory. But I get an
error: "Undefined subroutine &main::d1 called at a.pl...". I've reduced
everything down to this:

#### main programme (./a.pl)
#!perl
use strict;
use warnings;
use bb;
use cc::dd;
b1();
d1();

#### module bb (./bb.pm)
package bb;
use strict;
use warnings;
use Exporter;
our @ISA = qw(Exporter);
our @EXPORT = qw(b1);

sub b1 { print "b1\n" }
1;

#### module dd in local sub directory cc (./cc/dd.pm)
package dd;
use strict;
use warnings;
use Exporter;
our @ISA = qw(Exporter);
our @EXPORT = qw(d1);

sub d1 { print "d1\n" }
1;


"b1" get's printed. But if I move the same code to the sub directory
and just alter the use statement (in my example as dd and d1) I get the
above error message.

The module dd does get loaded: the original file had an END block that
does get executed after the error message.

This is Windows XP SP2 with ActiveState 5.8.8

What did I do wrong? I thought moving the packages to a different place
would only need a alteration of the use statement. But it seems that is
not so. Any ideas?

Regards
Daniel Cutter
 
A

anno4000

Daniel said:
I've got quite a large programme that's working just fine except for a
few minor bugs and several design flaws. So I've decided to clean it up
a bit. It uses several self-written objects and modules, so I thought a
good way to start would be to put them in a sub directory. But I get an
error: "Undefined subroutine &main::d1 called at a.pl...". I've reduced
everything down to this:

#### main programme (./a.pl)
#!perl
use strict;
use warnings;
use bb;
use cc::dd;

This tries to import functions from cc::dd. Since there
is no such package, nothing is imported.
b1();
d1();

#### module bb (./bb.pm)
package bb;
use strict;
use warnings;
use Exporter;
our @ISA = qw(Exporter);
our @EXPORT = qw(b1);

sub b1 { print "b1\n" }
1;

#### module dd in local sub directory cc (./cc/dd.pm)
package dd;

Change this to

package cc::dd;
use strict;
use warnings;
use Exporter;
our @ISA = qw(Exporter);
our @EXPORT = qw(d1);

sub d1 { print "d1\n" }
1;

[snip]

Anno
 

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

Members online

Forum statistics

Threads
473,982
Messages
2,570,186
Members
46,742
Latest member
AshliMayer

Latest Threads

Top