Sub::Install - install subroutines into packages easily
version 0.01
$Id: /my/rjbs/subinst/lib/Sub/Install.pm 16598 2005-11-22T03:30:52.663848Z rjbs $
use Sub::Install; Sub::Install::install_sub({ code => sub { ... }, into => $package, as => $subname });
This module makes it easy to install subroutines into packages without the unslightly mess of no strict or typeglobs lying about where just anyone can see them.
no strict
install_sub
Sub::Install::install_sub({ code => \&subroutine, into => "Finance::Shady", as => 'launder', });
This routine installs a given code reference into a package as a normal subroutine. The above is equivalent to:
no strict 'refs'; *{"Finance::Shady" . '::' . "launder"} = \&subroutine;
If into is not given, the sub is installed into the calling package.
into
If code is not a code reference, it is looked for as an existing sub in the package named in the from parameter. If from is not given, it will look in the calling package.
code
from
If as is not given, and if code is a name, as will default to code. If as is not given, but if code is a code ref, Sub::Install will try to find the name of the given code ref and use that as as.
as
That means that this code:
Sub::Install::install_sub({ code => 'twitch', from => 'Person::InPain', into => 'Person::Teenager', as => 'dance', });
is the same as:
package Person::Teenager; Sub::Install::install_sub({ code => Person::InPain->can('twitch'), as => 'dance', });
reinstall_sub
This routine behaves exactly like "install_sub", but does not emit a warning if warnings are on and the destination is already defined.
"install_sub"
Ricardo Signes, <rjbs@cpan.org>
<rjbs@cpan.org>
This module is (obviously) a reaction to Sub::Installer, which does the same thing, but does it by getting its greasy fingers all over UNIVERSAL.
This module needs more tests.
Please report any bugs or feature requests to bug-sub-install@rt.cpan.org, or through the web interface at http://rt.cpan.org. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
bug-sub-install@rt.cpan.org
Copyright 2005 Ricardo Signes, All Rights Reserved.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
To install Sub::Install, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Sub::Install
CPAN shell
perl -MCPAN -e shell install Sub::Install
For more information on module installation, please visit the detailed CPAN module installation guide.