>>>>> "FP" == Frédéric Perrin <[email protected]> writes:
FP> Hello list,
FP> I use() a module and explicitly put some of its functions into the main
FP> namespace so that I can use them without giving the full package name.
FP> However, when the same module is used by another module, then if I
FP> use() the modules in some order, it works, if I use() them in another,
FP> it fails as if perl couldn't see the function.
>>>>> essai.pl <<<<
FP> #!/usr/bin/perl
FP> -w use
FP> strict; use
FP> warnings;
FP> # This works
FP> # use FRED1 qw/ fred1a /;
FP> # use FRED2;
you don't need to use FRED2 in the main program. only FRED1 needs to use it.
FP> # This fails with:
FP> # Bareword "fred2a" not allowed while "strict subs" in use at FRED1.pm
FP> line 14. use FRED2;
be careful with pasting the error AND the source code like that.
FP> use FRED1 qw/ fred1a /;
FP> fred1a;
>>>>> FRED1.pm <<<<
FP> use strict;
FP> use warnings;
FP> package FRED1;
FP> require Exporter;
FP> our @ISA = qw/ Exporter /;
those two lines can be replaced with the simpler:
use base 'Exporter' ;
FP> our @EXPORT_OK = qw/ fred1a /;
FP> use FRED2 qw/ fred2a /;
that tries to call FRED2->import() which doesn't exist since you don't
have a FRED2 package name
FP> sub fred1a {
FP> print "This is fred1a, I call fred2a\n";
FP> fred2a;
FP> }
FP> 1;
>>>>> FRED2.pm <<<<
FP> use strict;
FP> use warnings;
i can't say for sure why this happens but you don't have a package name
in FRED2.pm. so any subs it has are in package main::. so when you have
the FRED1/FRED2 order, it seems to find fred2a in main:: but in the
other order it won't. i can fathom the exact reason but the problem is
likely just a missing package FRED2 line.
FP> require Exporter;
FP> our @ISA = qw/ Exporter /;
FP> our @EXPORT_OK = qw/ fred2a fred2b /;
FP> sub fred2a {
FP> print "This is fred2a\n";
FP> }
FP> sub fred2b {
FP> print "This is fred2b\n";
FP> }
FP> 1;
uri
--
Uri Guttman ------ [email protected] -------- http://www.sysarch.com --
----- Perl Code Review , Architecture, Development, Training, Support ------
--------- Gourmet Hot Cocoa Mix ---- http://bestfriendscocoa.com ---------
--
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
http://learn.perl.org/