in reply to undefining one slot of a typeglob
Here's some test code I threw together. If you want to preserve the other slots, you'll likely have to use Symbol's gensym to make a new typeglob and assign all of the other slots to it, then use it to replace the old symbol. If you're comfortable with the following code, there you go:
#!/usr/bin/perl -w use strict; package destination; package main; use Test::More 'no_plan'; { no strict 'refs'; *{'destination::foo'} = sub { 'foo' }; } is( destination::foo(), 'foo', 'install a sub' ); { no strict 'refs'; my $d = *{ 'main::destination::' }; delete $d->{foo}; } ok( ! destination->can( 'foo' ), '... now remove it' );
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: undefining one slot of a typeglob
by AidanLee (Chaplain) on Feb 24, 2004 at 00:11 UTC |