in reply to Re-using/changing a class

This is the original poster; got an account

Thanks for all the help, it works great! But there is a little catch (as there is always a little catch): because I used the -w option, it gives me a redefinition warning for each method in that class. I deleted the old class from @INC, and re 'required' it again, as mentioned above, so wouldn't all of the old sub's in that class get deleted as well? (Hence, not stating a redefinition of its subs.)

I could use the $^W = 0; trick inside of the class, but most of my program is made up of classes, and I don't want to disable warnings.

Replies are listed 'Best First'.
(tye)Re: Re-using/changing a class
by tye (Sage) on Feb 10, 2001 at 02:35 UTC

    You can also eliminate the warning by doing:

    undef \&flipBits if defined \&flipBits;

    You could either put this in the module (in which case you'd put it inside a BEGIN block before the subroutine(s) in question) or you could even loop over the symbol table of the module... If you import subroutines, I think you'll also get warnings for re-importing them.

    Note also that the module needs to be aware that it might be "reused" so that it initializes properly in that case. Many modules won't have a problem here, but some will.

            - tye (but my friends call me "Tye")
Re: Re: Re-using/changing a class
by repson (Chaplain) on Feb 10, 2001 at 08:36 UTC
    Have a look at the the delete_package('Foo::Bar') function in the standard module Symbol. That way you can clear the module from memory before telling perl that it isn't loaded.