1Sub::Install(3) User Contributed Perl Documentation Sub::Install(3)
2
3
4
6 Sub::Install - install subroutines into packages easily
7
9 version 0.924
10
11 $Id: /my/cs/projects/subinst/trunk/lib/Sub/Install.pm 27898 2006-11-13T15:29:46.377747Z rjbs $
12
14 use Sub::Install;
15
16 Sub::Install::install_sub({
17 code => sub { ... },
18 into => $package,
19 as => $subname
20 });
21
23 This module makes it easy to install subroutines into packages without
24 the unslightly mess of "no strict" or typeglobs lying about where just
25 anyone can see them.
26
28 install_sub
29
30 Sub::Install::install_sub({
31 code => \&subroutine,
32 into => "Finance::Shady",
33 as => 'launder',
34 });
35
36 This routine installs a given code reference into a package as a normal
37 subroutine. The above is equivalent to:
38
39 no strict 'refs';
40 *{"Finance::Shady" . '::' . "launder"} = \&subroutine;
41
42 If "into" is not given, the sub is installed into the calling package.
43
44 If "code" is not a code reference, it is looked for as an existing sub
45 in the package named in the "from" parameter. If "from" is not given,
46 it will look in the calling package.
47
48 If "as" is not given, and if "code" is a name, "as" will default to
49 "code". If "as" is not given, but if "code" is a code ref,
50 Sub::Install will try to find the name of the given code ref and use
51 that as "as".
52
53 That means that this code:
54
55 Sub::Install::install_sub({
56 code => 'twitch',
57 from => 'Person::InPain',
58 into => 'Person::Teenager',
59 as => 'dance',
60 });
61
62 is the same as:
63
64 package Person::Teenager;
65
66 Sub::Install::install_sub({
67 code => Person::InPain->can('twitch'),
68 as => 'dance',
69 });
70
71 reinstall_sub
72
73 This routine behaves exactly like ""install_sub"", but does not emit a
74 warning if warnings are on and the destination is already defined.
75
76 install_installers
77
78 This routine is provided to allow Sub::Install compatibility with
79 Sub::Installer. It installs "install_sub" and "reinstall_sub" methods
80 into the package named by its argument.
81
82 Sub::Install::install_installers('Code::Builder'); # just for us, please
83 Code::Builder->install_sub({ name => $code_ref });
84
85 Sub::Install::install_installers('UNIVERSAL'); # feeling lucky, punk?
86 Anything::At::All->install_sub({ name => $code_ref });
87
88 The installed installers are similar, but not identical, to those pro‐
89 vided by Sub::Installer. They accept a single hash as an argument.
90 The key/value pairs are used as the "as" and "code" parameters to the
91 "install_sub" routine detailed above. The package name on which the
92 method is called is used as the "into" parameter.
93
94 Unlike Sub::Installer's "install_sub" will not eval strings into code,
95 but will look for named code in the calling package.
96
98 Sub::Install exports "install_sub" and "reinstall_sub" only if they are
99 requested.
100
101 exporter
102
103 Sub::Install has a never-exported subroutine called "exporter", which
104 is used to implement its "import" routine. It takes a hashref of named
105 arguments, only one of which is currently recognize: "exports". This
106 must be an arrayref of subroutines to offer for export.
107
108 This routine is mainly for Sub::Install's own consumption. Instead,
109 consider Sub::Exporter.
110
112 Sub::Installer
113 This module is (obviously) a reaction to Damian Conway's Sub::In‐
114 staller, which does the same thing, but does it by getting its
115 greasy fingers all over UNIVERSAL. I was really happy about the
116 idea of making the installation of coderefs less ugly, but I
117 couldn't bring myself to replace the ugliness of typeglobs and
118 loosened strictures with the ugliness of UNIVERSAL methods.
119
120 Sub::Exporter
121 This is a complete Exporter.pm replacement, built atop
122 Sub::Install.
123
125 Ricardo Signes, "<rjbs@cpan.org>"
126
127 Several of the tests are adapted from tests that shipped with Damian
128 Conway's Sub-Installer distribution.
129
131 Please report any bugs or feature requests to
132 "bug-sub-install@rt.cpan.org", or through the web interface at
133 <http://rt.cpan.org>. I will be notified, and then you'll automati‐
134 cally be notified of progress on your bug as I make changes.
135
137 Copyright 2005-2006 Ricardo Signes, All Rights Reserved.
138
139 This program is free software; you can redistribute it and/or modify it
140 under the same terms as Perl itself.
141
142
143
144perl v5.8.8 2006-11-13 Sub::Install(3)