Add built local::lib
[catagits/Gitalist.git] / local-lib5 / man / man3 / Moose::Exporter.3pm
CommitLineData
3fea05b9 1.\" Automatically generated by Pod::Man v1.37, Pod::Parser v1.3
2.\"
3.\" Standard preamble:
4.\" ========================================================================
5.de Sh \" Subsection heading
6.br
7.if t .Sp
8.ne 5
9.PP
10\fB\\$1\fR
11.PP
12..
13.de Sp \" Vertical space (when we can't use .PP)
14.if t .sp .5v
15.if n .sp
16..
17.de Vb \" Begin verbatim text
18.ft CW
19.nf
20.ne \\$1
21..
22.de Ve \" End verbatim text
23.ft R
24.fi
25..
26.\" Set up some character translations and predefined strings. \*(-- will
27.\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left
28.\" double quote, and \*(R" will give a right double quote. | will give a
29.\" real vertical bar. \*(C+ will give a nicer C++. Capital omega is used to
30.\" do unbreakable dashes and therefore won't be available. \*(C` and \*(C'
31.\" expand to `' in nroff, nothing in troff, for use with C<>.
32.tr \(*W-|\(bv\*(Tr
33.ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p'
34.ie n \{\
35. ds -- \(*W-
36. ds PI pi
37. if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch
38. if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch
39. ds L" ""
40. ds R" ""
41. ds C` ""
42. ds C' ""
43'br\}
44.el\{\
45. ds -- \|\(em\|
46. ds PI \(*p
47. ds L" ``
48. ds R" ''
49'br\}
50.\"
51.\" If the F register is turned on, we'll generate index entries on stderr for
52.\" titles (.TH), headers (.SH), subsections (.Sh), items (.Ip), and index
53.\" entries marked with X<> in POD. Of course, you'll have to process the
54.\" output yourself in some meaningful fashion.
55.if \nF \{\
56. de IX
57. tm Index:\\$1\t\\n%\t"\\$2"
58..
59. nr % 0
60. rr F
61.\}
62.\"
63.\" For nroff, turn off justification. Always turn off hyphenation; it makes
64.\" way too many mistakes in technical documents.
65.hy 0
66.if n .na
67.\"
68.\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2).
69.\" Fear. Run. Save yourself. No user-serviceable parts.
70. \" fudge factors for nroff and troff
71.if n \{\
72. ds #H 0
73. ds #V .8m
74. ds #F .3m
75. ds #[ \f1
76. ds #] \fP
77.\}
78.if t \{\
79. ds #H ((1u-(\\\\n(.fu%2u))*.13m)
80. ds #V .6m
81. ds #F 0
82. ds #[ \&
83. ds #] \&
84.\}
85. \" simple accents for nroff and troff
86.if n \{\
87. ds ' \&
88. ds ` \&
89. ds ^ \&
90. ds , \&
91. ds ~ ~
92. ds /
93.\}
94.if t \{\
95. ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u"
96. ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u'
97. ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u'
98. ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u'
99. ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u'
100. ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u'
101.\}
102. \" troff and (daisy-wheel) nroff accents
103.ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V'
104.ds 8 \h'\*(#H'\(*b\h'-\*(#H'
105.ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#]
106.ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H'
107.ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u'
108.ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#]
109.ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#]
110.ds ae a\h'-(\w'a'u*4/10)'e
111.ds Ae A\h'-(\w'A'u*4/10)'E
112. \" corrections for vroff
113.if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u'
114.if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u'
115. \" for low resolution devices (crt and lpr)
116.if \n(.H>23 .if \n(.V>19 \
117\{\
118. ds : e
119. ds 8 ss
120. ds o a
121. ds d- d\h'-1'\(ga
122. ds D- D\h'-1'\(hy
123. ds th \o'bp'
124. ds Th \o'LP'
125. ds ae ae
126. ds Ae AE
127.\}
128.rm #[ #] #H #V #F C
129.\" ========================================================================
130.\"
131.IX Title "Moose::Exporter 3"
132.TH Moose::Exporter 3 "2009-11-19" "perl v5.8.7" "User Contributed Perl Documentation"
133.SH "NAME"
134Moose::Exporter \- make an import() and unimport() just like Moose.pm
135.SH "SYNOPSIS"
136.IX Header "SYNOPSIS"
137.Vb 1
138\& package MyApp::Moose;
139.Ve
140.PP
141.Vb 2
142\& use Moose ();
143\& use Moose::Exporter;
144.Ve
145.PP
146.Vb 5
147\& Moose::Exporter\->setup_import_methods(
148\& with_meta => [ 'has_rw', 'sugar2' ],
149\& as_is => [ 'sugar3', \e&Some::Random::thing ],
150\& also => 'Moose',
151\& );
152.Ve
153.PP
154.Vb 8
155\& sub has_rw {
156\& my ( $meta, $name, %options ) = @_;
157\& $meta\->add_attribute(
158\& $name,
159\& is => 'rw',
160\& %options,
161\& );
162\& }
163.Ve
164.PP
165.Vb 2
166\& # then later ...
167\& package MyApp::User;
168.Ve
169.PP
170.Vb 1
171\& use MyApp::Moose;
172.Ve
173.PP
174.Vb 3
175\& has 'name';
176\& has_rw 'size';
177\& thing;
178.Ve
179.PP
180.Vb 1
181\& no MyApp::Moose;
182.Ve
183.SH "DESCRIPTION"
184.IX Header "DESCRIPTION"
185This module encapsulates the exporting of sugar functions in a
186\&\f(CW\*(C`Moose.pm\*(C'\fR\-like manner. It does this by building custom \f(CW\*(C`import\*(C'\fR,
187\&\f(CW\*(C`unimport\*(C'\fR, and \f(CW\*(C`init_meta\*(C'\fR methods for your module, based on a spec you
188provide.
189.PP
190It also lets you \*(L"stack\*(R" Moose-alike modules so you can export Moose's sugar
191as well as your own, along with sugar from any random \f(CW\*(C`MooseX\*(C'\fR module, as
192long as they all use \f(CW\*(C`Moose::Exporter\*(C'\fR. This feature exists to let you bundle
193a set of MooseX modules into a policy module that developers can use directly
194instead of using Moose itself.
195.PP
196To simplify writing exporter modules, \f(CW\*(C`Moose::Exporter\*(C'\fR also imports
197\&\f(CW\*(C`strict\*(C'\fR and \f(CW\*(C`warnings\*(C'\fR into your exporter module, as well as into
198modules that use it.
199.SH "METHODS"
200.IX Header "METHODS"
201This module provides two public methods:
202.IP "\fBMoose::Exporter\->setup_import_methods(...)\fR" 4
203.IX Item "Moose::Exporter->setup_import_methods(...)"
204When you call this method, \f(CW\*(C`Moose::Exporter\*(C'\fR builds custom \f(CW\*(C`import\*(C'\fR,
205\&\f(CW\*(C`unimport\*(C'\fR, and \f(CW\*(C`init_meta\*(C'\fR methods for your module. The \f(CW\*(C`import\*(C'\fR method
206will export the functions you specify, and can also re-export functions
207exported by some other module (like \f(CW\*(C`Moose.pm\*(C'\fR).
208.Sp
209The \f(CW\*(C`unimport\*(C'\fR method cleans the caller's namespace of all the exported
210functions.
211.Sp
212If you pass any parameters for Moose::Util::MetaRole, this method will
213generate an \f(CW\*(C`init_meta\*(C'\fR for you as well (see below for details). This
214\&\f(CW\*(C`init_meta\*(C'\fR will call \f(CW\*(C`Moose::Util::MetaRole::apply_metaclass_roles\*(C'\fR and
215\&\f(CW\*(C`Moose::Util::MetaRole::apply_base_class_roles\*(C'\fR as needed.
216.Sp
217Note that if any of these methods already exist, they will not be
218overridden, you will have to use \f(CW\*(C`build_import_methods\*(C'\fR to get the
219coderef that would be installed.
220.Sp
221This method accepts the following parameters:
222.RS 4
223.IP "* with_meta => [ ... ]" 8
224.IX Item "with_meta => [ ... ]"
225This list of function \fInames only\fR will be wrapped and then exported. The
226wrapper will pass the metaclass object for the caller as its first argument.
227.Sp
228Many sugar functions will need to use this metaclass object to do something to
229the calling package.
230.IP "* as_is => [ ... ]" 8
231.IX Item "as_is => [ ... ]"
232This list of function names or sub references will be exported as\-is. You can
233identify a subroutine by reference, which is handy to re-export some other
234module's functions directly by reference (\f(CW\*(C`\e&Some::Package::function\*(C'\fR).
235.Sp
236If you do export some other package's function, this function will never be
237removed by the \f(CW\*(C`unimport\*(C'\fR method. The reason for this is we cannot know if
238the caller \fIalso\fR explicitly imported the sub themselves, and therefore wants
239to keep it.
240.ie n .IP "* also => $name or \e@names" 8
241.el .IP "* also => \f(CW$name\fR or \e@names" 8
242.IX Item "also => $name or @names"
243This is a list of modules which contain functions that the caller
244wants to export. These modules must also use \f(CW\*(C`Moose::Exporter\*(C'\fR. The
245most common use case will be to export the functions from \f(CW\*(C`Moose.pm\*(C'\fR.
246Functions specified by \f(CW\*(C`with_meta\*(C'\fR or \f(CW\*(C`as_is\*(C'\fR take precedence over
247functions exported by modules specified by \f(CW\*(C`also\*(C'\fR, so that a module
248can selectively override functions exported by another module.
249.Sp
250\&\f(CW\*(C`Moose::Exporter\*(C'\fR also makes sure all these functions get removed
251when \f(CW\*(C`unimport\*(C'\fR is called.
252.RE
253.RS 4
254.Sp
255Any of the \f(CW*_roles\fR options for
256\&\f(CW\*(C`Moose::Util::MetaRole::apply_metaclass_roles\*(C'\fR and
257\&\f(CW\*(C`Moose::Util::MetaRole::base_class_roles\*(C'\fR are also acceptable.
258.RE
259.IP "\fBMoose::Exporter\->build_import_methods(...)\fR" 4
260.IX Item "Moose::Exporter->build_import_methods(...)"
261Returns two or three code refs, one for \f(CW\*(C`import\*(C'\fR, one for
262\&\f(CW\*(C`unimport\*(C'\fR, and optionally one for \f(CW\*(C`init_meta\*(C'\fR, if the appropriate
263options are passed in.
264.Sp
265Accepts the additional \f(CW\*(C`install\*(C'\fR option, which accepts an arrayref of method
266names to install into your exporting package. The valid options are \f(CW\*(C`import\*(C'\fR,
267\&\f(CW\*(C`unimport\*(C'\fR, and \f(CW\*(C`init_meta\*(C'\fR. Calling \f(CW\*(C`setup_import_methods\*(C'\fR is equivalent
268to calling \f(CW\*(C`build_import_methods\*(C'\fR with \f(CW\*(C`install => [qw(import unimport
269init_meta)]\*(C'\fR except that it doesn't also return the methods.
270.Sp
271Used by \f(CW\*(C`setup_import_methods\*(C'\fR.
272.SH "IMPORTING AND init_meta"
273.IX Header "IMPORTING AND init_meta"
274If you want to set an alternative base object class or metaclass class, see
275above for details on how this module can call Moose::Util::MetaRole for
276you.
277.PP
278If you want to do something that is not supported by this module, simply
279define an \f(CW\*(C`init_meta\*(C'\fR method in your class. The \f(CW\*(C`import\*(C'\fR method that
280\&\f(CW\*(C`Moose::Exporter\*(C'\fR generates for you will call this method (if it exists). It
281will always pass the caller to this method via the \f(CW\*(C`for_class\*(C'\fR parameter.
282.PP
283Most of the time, your \f(CW\*(C`init_meta\*(C'\fR method will probably just call \f(CW\*(C`Moose\->init_meta\*(C'\fR to do the real work:
284.PP
285.Vb 4
286\& sub init_meta {
287\& shift; # our class name
288\& return Moose\->init_meta( @_, metaclass => 'My::Metaclass' );
289\& }
290.Ve
291.PP
292Keep in mind that \f(CW\*(C`build_import_methods\*(C'\fR will return an \f(CW\*(C`init_meta\*(C'\fR
293method for you, which you can also call from within your custom
294\&\f(CW\*(C`init_meta\*(C'\fR:
295.PP
296.Vb 2
297\& my ( $import, $unimport, $init_meta ) =
298\& Moose::Exporter\->build_import_methods( ... );
299.Ve
300.PP
301.Vb 2
302\& sub import {
303\& my $class = shift;
304.Ve
305.PP
306.Vb 1
307\& ...
308.Ve
309.PP
310.Vb 1
311\& $class\->$import(...);
312.Ve
313.PP
314.Vb 2
315\& ...
316\& }
317.Ve
318.PP
319.Vb 1
320\& sub unimport { goto &$unimport }
321.Ve
322.PP
323.Vb 2
324\& sub init_meta {
325\& my $class = shift;
326.Ve
327.PP
328.Vb 1
329\& ...
330.Ve
331.PP
332.Vb 1
333\& $class\->$init_meta(...);
334.Ve
335.PP
336.Vb 2
337\& ...
338\& }
339.Ve
340.SH "METACLASS TRAITS"
341.IX Header "METACLASS TRAITS"
342The \f(CW\*(C`import\*(C'\fR method generated by \f(CW\*(C`Moose::Exporter\*(C'\fR will allow the
343user of your module to specify metaclass traits in a \f(CW\*(C`\-traits\*(C'\fR
344parameter passed as part of the import:
345.PP
346.Vb 1
347\& use Moose \-traits => 'My::Meta::Trait';
348.Ve
349.PP
350.Vb 1
351\& use Moose \-traits => [ 'My::Meta::Trait', 'My::Other::Trait' ];
352.Ve
353.PP
354These traits will be applied to the caller's metaclass
355instance. Providing traits for an exporting class that does not create
356a metaclass for the caller is an error.
357.SH "AUTHOR"
358.IX Header "AUTHOR"
359Dave Rolsky <autarch@urth.org>
360.PP
361This is largely a reworking of code in Moose.pm originally written by
362Stevan Little and others.
363.SH "COPYRIGHT AND LICENSE"
364.IX Header "COPYRIGHT AND LICENSE"
365Copyright 2009 by Infinity Interactive, Inc.
366.PP
367<http://www.iinteractive.com>
368.PP
369This library is free software; you can redistribute it and/or modify
370it under the same terms as Perl itself.