NAME
Sub::Install - install subroutines into packages easily
VERSION
version 0.02
$Id: /my/rjbs/subinst/trunk/lib/Sub/Install.pm 16619 2005-11-22T16:34:02.590722Z rjbs $
SYNOPSIS
use Sub::Install;
Sub::Install::install_sub({
code => sub { ... },
into => $package,
as => $subname
});
DESCRIPTION
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.
FUNCTIONS
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.
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.
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
.
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.
AUTHOR
Ricardo Signes, <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.
TODO
This module needs more tests.
BUGS
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.
COPYRIGHT
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.