> On Mon, Jun 25, 2001 at 06:13:18PM -0400, Richard J. Barbalace wrote:
> 
> > I'm writing a package that uses another module. This latter module may
> > change somewhat erratically and unreliably, outside of my control.  As
> > a result, I want to have the package test itself and die if it notices
> > that the other module has changed in an incompatible way.  What's a
> > good way of doing this?

Paul Johnson writes:
> What's wrong with just sticking your test at the end of the module?  Any
> code found "lying around" in the module will be run as soon as the
> module is compiled.  This is useful for initialising the module, or
> possibly testing it ....

That works if you return to the same package.  For example, if I had a
main package and several sub-packages that inherited from it, the
following works without giving any warning:
     package MyPackage;
     use Flakey;
     .....
     package MyPackage::A;
     use vars qw( @ISA );
     @ISA = qw(MyPackage);
     .....
     package MyPackage::B;
     use vars qw( @ISA );
     @ISA = qw(MyPackage);
     .....
     package MyPackage::C;
     use vars qw( @ISA );
     @ISA = qw(MyPackage);
     .....
     package MyPackage;
     # Test if Flakey is compatible with MyPackage

This works fine if you only need to verify the main package.  (And
actually, in my current case I think I can get away with that.)  But
I'm also interested in the more general case of testing the
sub-packages as well.

Trying to do this gives a warning.  For example:
     package MyPackage;
     use Flakey;
     .....
     package MyPackage::A;
     .....
     package MyPackage::C;
     # Test if Flakey is compatible with MyPackage::C
     use MyPackage;  # Required since we're not in MyPackage

If I want to test each of the sub-packages, I have to "use MyPackage"
(or something equivalent).  Initially I thought the warnings might
result because "use" is really a BEGIN block, but replacing it with
"require" and "import" statements cause other problems.

+ Richard

Reply via email to