Hi.

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?

I'm currently doing this by wrapping the entire package in a BEGIN
block, and then adding on some tests in a CHECK block.  My current
package looks like:
#!/usr/bin/perl

BEGIN { ##### Compilation of packages before testing

package MyPackage;

use strict;
use warnings;
use Flakey;
.....
} ##### End of compilation of packages before testing

CHECK { ###### Testing of packages

package MyPackage::Test;
use MyPackage;

# Various tests to ensure compatibility
die "Flakey is not compatible" if ...
.....
} ##### End of testing of packages

1;
__END__

This works well in that any code using MyPackage will properly load
the package if Flakey is compatible and will die if Flakey is or
becomes not compatible.

However, some warnings are issued ("Subroutine foo redefined...")
because I "use MyPackage" in MyPackage::Test.  Is there a way to avoid
these warnings?  Or is there a way to suppress them?

Is there a better way to do this sort of thing?  Long term, I plan to
find a better module than Flakey or incorporate its compatible parts
into MyPackage to manage this problem, but I'm looking for a
short-term fix for now.

+ Richard J. Barbalace

Reply via email to