V
valerian2
I have a program divided into 3 modules plus a main script, and some of
the modules call functions within other modules. Most of the time this
works fine, but occasionally I get an error like this:
functions of the other module. Hence, I don't understand the reason
behind this error. I can get it to work fine by just replacing the
DB_Disconnect() call in Misc.pm with &My::Misc:
B_Disconnect(), but
that seems like a kludge, and I'd like to get a better understanding of
what's going on.
Here's what happens when I run the program (under perl 5.6.1):
I isolated the problem to the "use My::SOAP;" line in DB.pm, but I need
it there because some of the DB functions operate on SOAP data. So I
left it there and poked around some more...
I then isolated the real problem to be the "use My::Misc;" line in
SOAP.pm, but again I need that line there, because the SOAP subs call
a general untainting function in Misc.pm before returning the data.
Here's the four files in question (I deleted everything but the bare
minimum to reproduce this behavior):
----- ~/test.pl ---------------------------------
#!/usr/bin/perl -w
use strict;
use My:
B;
use My::Misc;
my $dbh = DB_Connect();
SafeError($dbh, '/dev/null is full!');
----- ~/My/DB.pm --------------------------------
# Database functions
package My:
B;
use strict;
use Exporter;
use My::SOAP; # XXX this line causes the problem
use vars qw(@ISA @EXPORT);
@ISA = ('Exporter');
@EXPORT = qw(DB_Connect DB_Disconnect);
sub DB_Connect {
# stub function, always returns true
my $dbh = 1;
return ($dbh);
}
sub DB_Disconnect {
# stub function, always returns true
my ($dbh) = @_;
return (1);
}
1;
----- ~/My/Misc.pm ------------------------------
# Miscellaneous functions (error handling, logging, untainting, etc.)
package My::Misc;
use strict;
use Exporter;
use My:
B;
use vars qw(@ISA @EXPORT);
@ISA = ('Exporter');
@EXPORT = qw(SafeError);
sub SafeError {
my ($dbh, $msg) = @_;
print "Error: $msg\n";
if ($dbh) {
print "Disconnecting from DB...\n";
DB_Disconnect($dbh);
}
exit 1;
}
1;
----- ~/My/SOAP.pm ------------------------------
# SOAP functions, for exchanging data with remote site
package My::SOAP;
use strict;
use Exporter;
use My::Misc; # XXX this line causes the problem
use vars qw(@ISA @EXPORT);
@ISA = ('Exporter');
@EXPORT = qw(GetRemoteData);
sub GetRemoteData {
# stub function, always returns true
return (1);
}
1;
the modules call functions within other modules. Most of the time this
works fine, but occasionally I get an error like this:
even though I made sure the caller (here Misc.pm) had imported all theUndefined subroutine &My::Misc:B_Disconnect called at My/Misc.pm line 18.
functions of the other module. Hence, I don't understand the reason
behind this error. I can get it to work fine by just replacing the
DB_Disconnect() call in Misc.pm with &My::Misc:
that seems like a kludge, and I'd like to get a better understanding of
what's going on.
Here's what happens when I run the program (under perl 5.6.1):
$ ./test.pl
Error: /dev/null is full!
Disconnecting from DB...
Undefined subroutine &My::Misc:B_Disconnect called at My/Misc.pm line 18.
I isolated the problem to the "use My::SOAP;" line in DB.pm, but I need
it there because some of the DB functions operate on SOAP data. So I
left it there and poked around some more...
I then isolated the real problem to be the "use My::Misc;" line in
SOAP.pm, but again I need that line there, because the SOAP subs call
a general untainting function in Misc.pm before returning the data.
Here's the four files in question (I deleted everything but the bare
minimum to reproduce this behavior):
----- ~/test.pl ---------------------------------
#!/usr/bin/perl -w
use strict;
use My:
use My::Misc;
my $dbh = DB_Connect();
SafeError($dbh, '/dev/null is full!');
----- ~/My/DB.pm --------------------------------
# Database functions
package My:
use strict;
use Exporter;
use My::SOAP; # XXX this line causes the problem
use vars qw(@ISA @EXPORT);
@ISA = ('Exporter');
@EXPORT = qw(DB_Connect DB_Disconnect);
sub DB_Connect {
# stub function, always returns true
my $dbh = 1;
return ($dbh);
}
sub DB_Disconnect {
# stub function, always returns true
my ($dbh) = @_;
return (1);
}
1;
----- ~/My/Misc.pm ------------------------------
# Miscellaneous functions (error handling, logging, untainting, etc.)
package My::Misc;
use strict;
use Exporter;
use My:
use vars qw(@ISA @EXPORT);
@ISA = ('Exporter');
@EXPORT = qw(SafeError);
sub SafeError {
my ($dbh, $msg) = @_;
print "Error: $msg\n";
if ($dbh) {
print "Disconnecting from DB...\n";
DB_Disconnect($dbh);
}
exit 1;
}
1;
----- ~/My/SOAP.pm ------------------------------
# SOAP functions, for exchanging data with remote site
package My::SOAP;
use strict;
use Exporter;
use My::Misc; # XXX this line causes the problem
use vars qw(@ISA @EXPORT);
@ISA = ('Exporter');
@EXPORT = qw(GetRemoteData);
sub GetRemoteData {
# stub function, always returns true
return (1);
}
1;