Ovid has asked for the wisdom of the Perl Monks concerning the following question:

I've inherited some of Simon Cozen's modules and the first thing I want to do is update the distributions to a more modern format and move the test.pl files to a .t file and add more tests. Then I ran into a wee bit of a problem.

Class::Dynamic allows you to add code refs to the @ISA array to dynamically determine base classes -- even changing them randomly at runtime, if you're crazy. Unfortunately, as soon as I move test.pl to the t/10dynamic.t and run make test, I get the following warnings:

Can't locate package CODE(0x89c17e8) for @C::ISA at t/test.t line 22. Can't locate package CODE(0x89c17e8) for @C::ISA at t/test.t line 22.

The tests still pass but try as I might, I can't suppress that warning. Any suggestions? Solutions involving $SIG{__WARN__} do not seem appropriate as I don't want to step on other's code.

Update: I can use -X on the command line, but I don't want to disable all warnings. I'm now looking to see if I can use the warnings pragma to customize existing warnings.

Cheers,
Ovid

New address of my CGI Course.

Replies are listed 'Best First'.
Re: Can't suppress missing package warning
by tachyon (Chancellor) on Oct 09, 2004 at 22:26 UTC

    The reason for the appearance of the warning is that the test code does not use warnings. test.pl is run without warnings, whereas t/blah.t is run with warnings enabled. If you add use warnings to test.pl you get the same issue. It seem to me anyone that uses this module with warnings enabled is going to get this warning unless they also supress it or don't use warnings. All you need to make it go away is simple no warnings before setting @ISA for package C. This is valid as the Module requires 5.6+ For package D the second argument of @ISA is obviously not evaluated as it does not generate a warning.

    use Test; BEGIN { plan tests => 3 }; use Class::Dynamic; use warnings; # added to show point ok(1); our $testval = time & 1; package A; sub number { return 12 } package B; sub number { return 42 } package C; no warnings; @ISA = ( sub { $main::testval ? "A" : "B" } ); package D; @ISA = ( "A", sub { $main::testval ? "A" : "B" } ); package main; ok (C->number == ($testval ? 12 : 42)); ok (D->number == 12);

    cheers

    tachyon

Re: Can't suppress missing package warning
by stvn (Monsignor) on Oct 09, 2004 at 22:15 UTC

    It seems that Simon didn't use warnings anywhere, and I am guessing that the top of your .t file might have #!/usr/bin/perl -w or similiar. You will likely need to surpress the warnings within the module itself with a no warnings right after the no strict in UNIVERSAL::AUTOLOAD (although I have not tested this myself). This will at least just disable them for the scope of UNIVERSAL::AUTOLOAD. However if you wanted to get specific, you could figure out which sub-warning this comes from and do use warnings 'something', so that you were not supressing any other valid warnings.

    My guess is that those warnings maybe didn't show up in the version of perl that Simon used to write this (what was in common usage in mid. 2002?).

    -stvn