in reply to Re: What is the correct way to clear package?
in thread What is the correct way to clear package?

Thanks! It works for me.

Update:

No, it doesn't.

It clears nested packages. It's not required behavior.

#!/usr/bin/env perl package Test1; package Test1::Nested; sub a { print "Test1::Nested::a\n"; } package main; use Symbol; # ok. eval "Test1::Nested::a()"; die $@ if $@; Symbol::delete_package( 'Test1' ); # fails. eval "Test1::Nested::a()"; die $@ if $@;

Replies are listed 'Best First'.
Re^3: What is the correct way to clear package?
by LanX (Saint) on May 06, 2011 at 10:02 UTC
    > It's not required behavior.

    Well, it's not our fault if you don't clarify your requirements... It was a struggle to find out what you exactly want.

    > It clears nested packages.

    2 Thoughts:

    1. Symbol::delete_package is plain perlcode, you could just adapt it to your needs.
    2. If you want to rely on Symbol been kept adapted to any future changes, why not just safe away the globs of nested packages, apply delete_package() and then reassign the globs? You already have the necessary code in the OP.

    Cheers Rolf