Sub::Delete(3pm)
π 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: writeuse Sub::Delete();β the empty parens load the module without bringingdelete_subalong 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. π§
π AUTHOR & COPYRIGHT π
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 hasdelete &sublisted as a possible future feature πSymbol::GlobandSymbol::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
- ubuntu resolute: libsub-delete-perl 1.00003-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libsub-delete-perl 1.00003-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms