Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: undefining one slot of a typeglob

by chromatic (Archbishop)
on Feb 24, 2004 at 00:02 UTC ( [id://331264]=note: print w/replies, xml ) Need Help??


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
    Cool, thanks much. I'll look into the Symbol package for my needs. The code you presented is very instructive though. As much as I'm not too concerned about the rest of the glob, i'd rather not risk killing things that i wasn't targeting, just in case it comes back to bite me in the future.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://331264]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (6)
As of 2024-04-19 04:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found