1Sub::Install(3)       User Contributed Perl Documentation      Sub::Install(3)
2
3
4

NAME

6       Sub::Install - install subroutines into packages easily
7

VERSION

9       version 0.929
10

SYNOPSIS

12         use Sub::Install;
13
14         Sub::Install::install_sub({
15           code => sub { ... },
16           into => $package,
17           as   => $subname
18         });
19

DESCRIPTION

21       This module makes it easy to install subroutines into packages without
22       the unsightly mess of "no strict" or typeglobs lying about where just
23       anyone can see them.
24

PERL VERSION

26       This library should run on perls released even an extremely long time
27       ago.  It should work on any version of perl released in the last ten
28       years.
29
30       Although it may work on older versions of perl, no guarantee is made
31       that the minimum required version will not be increased.  The version
32       may be increased for any reason, and there is no promise that patches
33       will be accepted to lower the minimum required perl.
34

FUNCTIONS

36   install_sub
37         Sub::Install::install_sub({
38          code => \&subroutine,
39          into => "Finance::Shady",
40          as   => 'launder',
41         });
42
43       This routine installs a given code reference into a package as a normal
44       subroutine.  The above is equivalent to:
45
46         no strict 'refs';
47         *{"Finance::Shady" . '::' . "launder"} = \&subroutine;
48
49       If "into" is not given, the sub is installed into the calling package.
50
51       If "code" is not a code reference, it is looked for as an existing sub
52       in the package named in the "from" parameter.  If "from" is not given,
53       it will look in the calling package.
54
55       If "as" is not given, and if "code" is a name, "as" will default to
56       "code".  If "as" is not given, but if "code" is a code ref,
57       Sub::Install will try to find the name of the given code ref and use
58       that as "as".
59
60       That means that this code:
61
62         Sub::Install::install_sub({
63           code => 'twitch',
64           from => 'Person::InPain',
65           into => 'Person::Teenager',
66           as   => 'dance',
67         });
68
69       is the same as:
70
71         package Person::Teenager;
72
73         Sub::Install::install_sub({
74           code => Person::InPain->can('twitch'),
75           as   => 'dance',
76         });
77
78   reinstall_sub
79       This routine behaves exactly like "install_sub", but does not emit a
80       warning if warnings are on and the destination is already defined.
81
82   install_installers
83       This routine is provided to allow Sub::Install compatibility with
84       Sub::Installer.  It installs "install_sub" and "reinstall_sub" methods
85       into the package named by its argument.
86
87        Sub::Install::install_installers('Code::Builder'); # just for us, please
88        Code::Builder->install_sub({ name => $code_ref });
89
90        Sub::Install::install_installers('UNIVERSAL'); # feeling lucky, punk?
91        Anything::At::All->install_sub({ name => $code_ref });
92
93       The installed installers are similar, but not identical, to those
94       provided by Sub::Installer.  They accept a single hash as an argument.
95       The key/value pairs are used as the "as" and "code" parameters to the
96       "install_sub" routine detailed above.  The package name on which the
97       method is called is used as the "into" parameter.
98
99       Unlike Sub::Installer's "install_sub" will not eval strings into code,
100       but will look for named code in the calling package.
101

EXPORTS

103       Sub::Install exports "install_sub" and "reinstall_sub" only if they are
104       requested.
105
106   exporter
107       Sub::Install has a never-exported subroutine called "exporter", which
108       is used to implement its "import" routine.  It takes a hashref of named
109       arguments, only one of which is currently recognize: "exports".  This
110       must be an arrayref of subroutines to offer for export.
111
112       This routine is mainly for Sub::Install's own consumption.  Instead,
113       consider Sub::Exporter.
114

SEE ALSO

116       Sub::Installer
117           This module is (obviously) a reaction to Damian Conway's
118           Sub::Installer, which does the same thing, but does it by getting
119           its greasy fingers all over UNIVERSAL.  I was really happy about
120           the idea of making the installation of coderefs less ugly, but I
121           couldn't bring myself to replace the ugliness of typeglobs and
122           loosened strictures with the ugliness of UNIVERSAL methods.
123
124       Sub::Exporter
125           This is a complete Exporter.pm replacement, built atop
126           Sub::Install.
127

EXTRA CREDITS

129       Several of the tests are adapted from tests that shipped with Damian
130       Conway's Sub-Installer distribution.
131

AUTHOR

133       Ricardo SIGNES <cpan@semiotic.systems>
134

CONTRIBUTORS

136       •   Chad Granum <chad.granum@dreamhost.com>
137
138       •   David Steinbrunner <dsteinbrunner@pobox.com>
139
140       •   Ricardo SIGNES <rjbs@codesimply.com>
141
142       •   Ricardo Signes <rjbs@semiotic.systems>
143
145       This software is copyright (c) 2005 by Ricardo SIGNES.
146
147       This is free software; you can redistribute it and/or modify it under
148       the same terms as the Perl 5 programming language system itself.
149
150
151
152perl v5.36.0                      2023-01-20                   Sub::Install(3)
Impressum