#!/usr/bin/perl -w use strict; # Undefine a subroutine safely, by name. # From a method described by chromatic. sub undefSub { no strict 'refs'; my $name = shift; # save the glob... local *old = *{$name}; # and restore everything else local *new; foreach my $type (qw(HASH IO FORMAT SCALAR ARRAY)) { my $elem = *old{$type}; next if !defined($elem); *new = $elem; } *{$name} = *new; } package A; sub A { print "A::A $_[0]\n" } package B; @B::ISA = 'A'; $B::A = "i'm \$B::A\n\n"; package main; A->A; B->A; # calls A::A print $B::A; *{B::A} = sub { print "B::A $_[0]\n" }; A->A; B->A; # now calls B::A eval 'print $B::A'; undefSub('B::A'); A->A; B->A; # now calls A::A eval 'print $B::A'; # still intact!
In reply to Re: Undefining subroutines and inheritance
by bikeNomad
in thread Undefining subroutines and inheritance
by bikeNomad
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |