Sub::Delete(3pm)

πŸ“¦
version 1.00003 Β· 4 versions
, in ubuntu resolute, ubuntu stonking

πŸ’– Sub::Delete πŸ’–

okay bestie, so Sub::Delete is a Perl module that lets you literally delete subroutines from existence. yes, actually delete them. not the fake "undef" kind. the real deal. πŸ’…

(this is the Sub::Delete(3pm) page from the User Contributed Perl Documentation, if you're keeping receipts πŸ“)


✨ VERSION ✨

1.00003


🌸 SYNOPSIS 🌸

use Sub::Delete;
sub foo {}
delete_sub 'foo';
eval 'foo();1' or die; # dies

that's it. that's the whole vibe. foo is gone, foo() throws hands, die does its thing. 🫢


πŸ¦‹ DESCRIPTION πŸ¦‹

This module gives you exactly one function, delete_sub, and it deletes the subroutine whose name you hand it. so simple, so clean.

side note for the girlies who don't want the function imported: write use Sub::Delete(); β€” the empty parens load the module without bringing delete_sub along for the ride. ✨

Now here's the tea β˜• β€” this does more than just undefine the sub the way undef &foo does. Because undef &foo? it leaves a little stub behind, and that stub can trigger AUTOLOAD (which, consequently, means it won't work for deleting methods πŸ™ˆ). not it.

delete_sub instead completely obliterates the subroutine from the symbol table. gone. deleted. no stub, no leftovers in the symbol table.

though heads up πŸ‘‘ β€” there may still be references to it elsewhere, including in compiled code. so it's obliterated from the symbol table, not from the entire universe.

πŸŽ€ PREREQUISITES πŸŽ€

This module requires perl 5.8.3 or higher. no dusty old perls allowed, sorry babes πŸ’…


🧚 LIMITATIONS 🧚

okay so this one's a lil cursed, listen up:

If you take a reference to a glob that contains a subroutine, and then you delete the subroutine with delete_sub, you'll find that the glob you referenced still has a subroutine in it. 😭

why? because delete_sub does this whole routine: it removes a glob, replaces it with another one, and then copies the contents of the old glob into the new one β€” except for the CODE slot.

and it's nearly impossible to fix without breaking constant::lexical. so like, that's the situation. we live here now. πŸ’€

🌈 BUGS 🌈

If you find any bugs, please report them to the author via e-mail. fr fr, they want to know. πŸ“§


Copyright (C) 2008-10 Father Chrysostomos (sprout at, um, cpan dot org)

This program is free software; you may redistribute or modify it (or both) under the same terms as perl. so go off, remix it, slay. πŸ’–


πŸ”₯ SEE ALSO πŸ”₯

  • perltodo β€” which has delete &sub listed as a possible future feature πŸ‘€
  • Symbol::Glob and Symbol::Util β€” both of which predate this module (but the author only discovered them recently πŸ™ˆ), and which allow one to delete any arbitrary slot from a glob. Neither of them takes perl 5.10 constants into account, however. They also both differ from this module, in that a subroutine referenced in compiled code can no longer be called if deleted from its glob. The entire glob must be replaced (which this module does). ✨

and that's the whole page bestie!! this one's perl v5.40.1, dated 2025-09-28, brought to you by the Sub::Delete(3pm) girlies πŸ’…πŸŽ€ mwah, go delete a subroutine, you've earned it πŸ«ΆπŸ’–

πŸ“¦ where this page comes from