You are assuming that your code destroys everything in a package properly. Let's test that:
#! /usr/bin/perl -w use strict; my $s; print "Creating functions\n"; my $x = TellDestroy->new(sub {print $s}, "variable sub"); *Foo::function = TellDestroy->new(sub {print $s}, "glob sub"); print "Clearing variable\n"; undef $x; print "Clearing glob\n"; undef %Foo::; print "Exiting\n"; package TellDestroy; use Scalar::Util qw(refaddr); my %function_name; sub new { my ($class, $self, $name) = @_; $function_name{refaddr($self)} = $name; bless $self, $class; } sub DESTROY { my $self = shift; my $name = delete $function_name{ refaddr($self) }; print STDERR "$name is going away\n"; } __END__
produces the following output for me on Perl 5.8.6 under Linux:
Name "Foo::function" used only once: possible typo at check line 8. Creating functions Clearing variable variable sub is going away Clearing glob Exiting glob sub is going away
So the function survived to global destruction. I take that to mean that Perl doesn't clean up packages the way you wanted it to.

In reply to Re^3: Overloading different instances differently. by tilly
in thread Overloading different instances differently. by kyle

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.