duane_ellis has asked for the wisdom of the Perl Monks concerning the following question:
I've got a dozen or so of modules in a directory - (ie: FOO_X.pm, FOO_Y.pm, etc..) And a some scripts (ie: A.pl, B.pl, C.pl, etc) that make use of them. The size/scope of the modules is too large to puthere (and they require access to a database to work) Creating tiny test examples work fine. I have not got a small reproducable example yet. The modules are collections of like minded routines. ie: Report.pm, Schedule.pm, Tasks.pm, Orders.pm. The scripts live in a "bin" directory, and the modules live in a "lib" directory.
For some reason, I seem to have random "undefined subroutine" problems that I cannot explain.
BEGIN SHORT DESCRIPTION: The problem is like this:
If I execute script A, which uses Module X - which then uses module Y - then Z... it works.
If I execute script B, which begins with a different module, which - uses modules just like A, andin the end - uses Y, and Module Z... it does not.
The path that script B takes causes causes Y's references to Z to fail as undefined subroutines.
The only known work around I have is to fully qualify every access to Z's functions. (ie: In the form: ModName::FuncName) I should not have to do that.
END SHORT DESCRIPTION
Longer description graphically - its like this:
By that, I mean: script A uses Module X directly. Module X uses Y, Module Y - then uses Module Z. My script does not reference Z it directlyA -> use FOO_ModuleX; -> use FOO_Module_Y; -> use FOO_Module_Z
Script B, enters the maze from a different location, somewhere along the way - something it uses Y, which uses Z... and that is the problem.
The scripts start with the same boilerplate, and look like this:
#! /usr/bin/perl use strict; use warnings; # Std Perl Modules use Carp; use File::Copy; ... actual list varies depends on script ... # Our modules. use FOO_X; ... actual list varies depends on script ... #======================= # Code begins... # A trivial example my $msg = foo_x_function( "hello" ); print "$msg\n" exit 0;
NOTE: I do not know if this matters: I do not "use *.pm" (ie: a "use" statement for every one of my modules in every one of my modules.... However but the "use" hierachy is not purely recursive, the modules are 'mutually recursive'. Huh? you ask... I am not using recursion... I'm describing the 'use Name;' relationship between *MY* modules.., like this:
The problem seems to be related to the 'use relationship path' or it is a namespace/scoping problem.
I've read - quite a number of things - with no luck For example:
To answer some questions I've seen asked before:================================ PERL Version: (host RH EL4 - intel) This is perl, v5.8.5 built for i386-linux-thread-multi ================================ ====================================== The style/format of my modules are like this: (From: http://perldoc.perl.org/perlmod.html example) ====================================== #! /usr/bin/perl package NameX; use strict; use warnings use NameY; use NameZ; BEGIN { use Exporter (); our ($VERSION, @ISA, @EXPORT, @EXPORT_OK, %EXPORT_TAGS ); $VERSION = 1.00; @ISA = qw( Exporter ); @EXPORT = qw ( &func1 &func2 ); %EXPORT_TAGS = (); @EXPORT_OK = qw(); } sub func1 { } sub func2 { } ======================
At this point, I'm at a loss to figure this out. When I have problems like this in C code, I resort to the preprocessor output and other things like that... I don't know how to do things like that with perl. For example: Is there a means to have perl explain what it is doing During a use statement... perhaps something like this would help me:
Thanks, --Duane.use Works_First; TURN_ON_MAGIC_HERE; use ProblemModule; TURN_OFF_MAGIC_HERE; use OtherModules;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Module Undefined Subroutines, works one way - not another
by ikegami (Patriarch) on Jan 11, 2007 at 17:53 UTC | |
by duane_ellis (Initiate) on Jan 11, 2007 at 22:24 UTC | |
by ikegami (Patriarch) on Jan 11, 2007 at 22:52 UTC | |
|
Re: Module Undefined Subroutines, works one way - not another
by almut (Canon) on Jan 11, 2007 at 18:58 UTC | |
|
Re: Module Undefined Subroutines, works one way - not another
by ysth (Canon) on Jan 12, 2007 at 08:01 UTC |