NAME

Sub::Delete

NAME

Sub::Delete - Perl module enabling one to delete subroutines

VERSION

This document describes version 1.000021 of Sub::Delete (from Perl distribution Alt-Sub-Delete-NewPackageSeparator), released on 2023-12-01.

VERSION

1.00002

SYNOPSIS

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

DESCRIPTION

This module provides one function, delete_sub, that deletes the subroutine whose name is passed to it. (To load the module without importing the function, write use Sub::Delete();.)

This does more than simply undefine the subroutine in the manner of undef &foo, which leaves a stub that can trigger AUTOLOAD (and, consequently, won't work for deleting methods). The subroutine is completely obliterated from the symbol table (though there may be references to it elsewhere, including in compiled code).

PREREQUISITES

This module requires perl 5.8.3 or higher.

LIMITATIONS

If you take a reference to a glob containing a subroutine, and then delete the subroutine with delete_sub, you will find that the glob you referenced still has a subroutine in it. This is because delete_sub removes a glob, replaces it with another, and then copies the contents of the old glob into the new one, except for the CODE slot. (This is nearly impossible to fix without breaking constant::lexical.)

FUNCTIONS

* delete_sub

* strict_eval

HOMEPAGE

Please visit the project's homepage at https://metacpan.org/release/Alt-Sub-Delete-NewPackageSeparator.

SOURCE

Source repository is at https://github.com/perlancar/perl-Alt-Sub-Delete-NewPackageSeparator.

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 I 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).

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.

AUTHOR

perlancar <perlancar@cpan.org>

CONTRIBUTING

To contribute, you can send patches by email/via RT, or send pull requests on GitHub.

Most of the time, you don't need to build the distribution yourself. You can simply modify the code, then test via:

% prove -l

If you want to build the distribution (e.g. to try to install it locally on your system), you can install Dist::Zilla, Dist::Zilla::PluginBundle::Author::PERLANCAR, Pod::Weaver::PluginBundle::Author::PERLANCAR, and sometimes one or two other Dist::Zilla- and/or Pod::Weaver plugins. Any additional steps required beyond that are considered a bug and can be reported to me.

COPYRIGHT AND LICENSE

This software is copyright (c) 2023 by perlancar <perlancar@cpan.org>.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.

BUGS

If you find any bugs, please report them to the author via e-mail.

BUGS

Please report any bugs or feature requests on the bugtracker website https://rt.cpan.org/Public/Dist/Display.html?Name=Alt-Sub-Delete-NewPackageSeparator

When submitting a bug or request, please include a test-file or a patch to an existing test-file that illustrates the bug or desired feature.