tvakah has asked for the wisdom of the Perl Monks concerning the following question:

I am writing a module that looks like this:
package foo; require Exporter; @ISA = qw(Exporter); use CGI qw(header); @EXPORT = qw(header); 1;
And then in another file:
use foo; print header();
This worked before I installed perl 5.6.0. Now it tells me that &main::header is undefined. I have tryed rewriting the module in various different ways. Why doesn't this work?

Replies are listed 'Best First'.
RE: Exporter 5.6.0
by mwp (Hermit) on Jul 31, 2000 at 22:14 UTC

    Apparently 5.6.0 added some layer of foolproofing. ;-)

    I see a couple problems here. First of all, you're doing a 'require Exporter' instead of 'use Exporter'. Also, it may not like the double-export of header from CGI. Try this:

    package foo; BEGIN { use Exporter; our(@ISA, @EXPORT); # use vars has been depreciated @ISA = qw(Exporter); @EXPORT = qw(header); } sub header { use CGI; # using OO-syntax for CGI.pm allows you the greatest flexibility my $cgi = new CGI; return $cgi->header; } 1;

    Your other file should remain unchanged.

    If you're creating a package like this, I would suggest reading the following manpages:

    • perlmod (writing Perl modules)
    • perlmodlib (writing Perl modules as public libraries)
    • perltoot (Tom's Object-Oriented Tutorial)
    I've also found Damian Conway's Object Oriented Perl to be an excellent read. The first four chapters will give you a crash course in strict Perl syntax, and give you all you need to know to get started with object orientedness in Perl. The rest of the book will help you streamline and `nicefy' your application.

    Alakaboo
    I am the lurker that spams in the night.

Re: Exporter 5.6.0
by redmist (Deacon) on Jul 31, 2000 at 23:52 UTC
Re: Exporter 5.6.0
by jlistf (Monk) on Jul 31, 2000 at 21:18 UTC


    i have no problems with that code. i see nothing wrong.
    is everything in the right folders/directories? are you using strict and warnings?

    Update: there will be a performance hit with this implementation. i don't know the full situation and you might decide to go through with this anyway... just be careful. it seems like this could be a dangerous technique if its just to reduce typing.
      Basically it is to make an API like module that will pull in functions from various modules. That way I can simply say use foo; instead of pulling in and instantiating many modules.