1 .\" Automatically generated by Pod::Man 2.22 (Pod::Simple 3.10)
4 .\" ========================================================================
5 .de Sp \" Vertical space (when we can't use .PP)
9 .de Vb \" Begin verbatim text
14 .de Ve \" End verbatim text
18 .\" Set up some character translations and predefined strings. \*(-- will
19 .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left
20 .\" double quote, and \*(R" will give a right double quote. \*(C+ will
21 .\" give a nicer C++. Capital omega is used to do unbreakable dashes and
22 .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff,
23 .\" nothing in troff, for use with C<>.
25 .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p'
29 . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch
30 . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch
43 .\" Escape single quotes in literal strings from groff's Unicode transform.
47 .\" If the F register is turned on, we'll generate index entries on stderr for
48 .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index
49 .\" entries marked with X<> in POD. Of course, you'll have to process the
50 .\" output yourself in some meaningful fashion.
53 . tm Index:\\$1\t\\n%\t"\\$2"
63 .\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2).
64 .\" Fear. Run. Save yourself. No user-serviceable parts.
65 . \" fudge factors for nroff and troff
74 . ds #H ((1u-(\\\\n(.fu%2u))*.13m)
80 . \" simple accents for nroff and troff
90 . ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u"
91 . ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u'
92 . ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u'
93 . ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u'
94 . ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u'
95 . ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u'
97 . \" troff and (daisy-wheel) nroff accents
98 .ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V'
99 .ds 8 \h'\*(#H'\(*b\h'-\*(#H'
100 .ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#]
101 .ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H'
102 .ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u'
103 .ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#]
104 .ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#]
105 .ds ae a\h'-(\w'a'u*4/10)'e
106 .ds Ae A\h'-(\w'A'u*4/10)'E
107 . \" corrections for vroff
108 .if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u'
109 .if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u'
110 . \" for low resolution devices (crt and lpr)
111 .if \n(.H>23 .if \n(.V>19 \
124 .\" ========================================================================
126 .IX Title "MooseX::Declare 3"
127 .TH MooseX::Declare 3 "2010-02-04" "perl v5.8.8" "User Contributed Perl Documentation"
128 .\" For nroff, turn off justification. Always turn off hyphenation; it makes
129 .\" way too many mistakes in technical documents.
133 MooseX::Declare \- Declarative syntax for Moose
135 .IX Header "SYNOPSIS"
137 \& use MooseX::Declare;
139 \& class BankAccount {
140 \& has \*(Aqbalance\*(Aq => ( isa => \*(AqNum\*(Aq, is => \*(Aqrw\*(Aq, default => 0 );
142 \& method deposit (Num $amount) {
143 \& $self\->balance( $self\->balance + $amount );
146 \& method withdraw (Num $amount) {
147 \& my $current_balance = $self\->balance();
148 \& ( $current_balance >= $amount )
149 \& || confess "Account overdrawn";
150 \& $self\->balance( $current_balance \- $amount );
154 \& class CheckingAccount extends BankAccount {
155 \& has \*(Aqoverdraft_account\*(Aq => ( isa => \*(AqBankAccount\*(Aq, is => \*(Aqrw\*(Aq );
157 \& before withdraw (Num $amount) {
158 \& my $overdraft_amount = $amount \- $self\->balance();
159 \& if ( $self\->overdraft_account && $overdraft_amount > 0 ) {
160 \& $self\->overdraft_account\->withdraw($overdraft_amount);
161 \& $self\->deposit($overdraft_amount);
167 .IX Header "DESCRIPTION"
168 This module provides syntactic sugar for Moose, the postmodern object system
169 for Perl 5. When used, it sets up the \f(CW\*(C`class\*(C'\fR and \f(CW\*(C`role\*(C'\fR keywords.
171 .IX Header "KEYWORDS"
173 .IX Subsection "class"
177 \& my $anon_class = class { ... };
180 Declares a new class. The class can be either named or anonymous, depending on
181 whether or not a classname is given. Within the class definition Moose and
182 MooseX::Method::Signatures are set up automatically in addition to the other
183 keywords described in this document. At the end of the definition the class
184 will be made immutable. namespace::autoclean is injected to clean up Moose and
185 other imports for you.
187 Because of the way the options are parsed, you cannot have a class named \*(L"is\*(R",
188 \&\*(L"with\*(R" or \*(L"extends\*(R".
190 It's possible to specify options for classes:
194 \& class Foo extends Bar { ... }
197 Sets a superclass for the class being declared.
201 \& class Foo with Role { ... }
202 \& class Foo with Role1 with Role2 { ... }
203 \& class Foo with (Role1, Role2) { ... }
206 Applies a role or roles to the class being declared.
208 .IX Item "is mutable"
210 \& class Foo is mutable { ... }
213 Causes the class not to be made immutable after its definition.
215 Options can also be provided for anonymous classes using the same syntax:
218 \& my $meta_class = class with Role;
221 .IX Subsection "role"
225 \& my $anon_role = role { ... };
228 Declares a new role. The role can be either named or anonymous, depending on
229 whether or not a name is given. Within the role definition Moose::Role and
230 MooseX::Method::Signatures are set up automatically in addition to the other
231 keywords described in this document. Again, namespace::autoclean is injected to
232 clean up Moose::Role and other imports for you.
234 It's possible to specify options for roles:
238 \& role Foo with Bar { ... }
241 Applies a role to the role being declared.
242 .SS "before / after / around / override / augment"
243 .IX Subsection "before / after / around / override / augment"
245 \& before foo ($x, $y, $z) { ... }
246 \& after bar ($x, $y, $z) { ... }
247 \& around baz ($x, $y, $z) { ... }
248 \& override moo ($x, $y, $z) { ... }
249 \& augment kuh ($x, $y, $z) { ... }
252 Add a method modifier. Those work like documented in Moose, except for
253 the slightly nicer syntax and the method signatures, which work like documented
254 in MooseX::Method::Signatures.
256 For the \f(CW\*(C`around\*(C'\fR modifier an additional argument called \f(CW$orig\fR is
257 automatically set up as the invocant for the method.
259 .IX Subsection "clean"
260 Sometimes you don't want the automatic cleaning the \f(CW\*(C`class\*(C'\fR and \f(CW\*(C`role\*(C'\fR
261 keywords provide using namespace::autoclean. In those cases you can specify the
262 \&\f(CW\*(C`dirty\*(C'\fR trait for your class or role:
265 \& use MooseX::Declare;
266 \& class Foo is dirty { ... }
269 This will prevent cleaning of your namespace, except for the keywords imported
270 from \f(CW\*(C`Moose\*(C'\fR or \f(CW\*(C`Moose::Role\*(C'\fR. Additionally, a \f(CW\*(C`clean\*(C'\fR keyword is provided,
271 which allows you to explicitly clean all functions that were defined prior to
272 calling \f(CW\*(C`clean\*(C'\fR. Here's an example:
275 \& use MooseX::Declare;
276 \& class Foo is dirty {
277 \& sub helper_function { ... }
279 \& method foo ($stuff) { ...; return helper_function($stuff); }
283 With that, the helper function won't be available as a method to a user of your
284 class, but you're still able to use it inside your class.
285 .SH "NOTE ON IMPORTS"
286 .IX Header "NOTE ON IMPORTS"
287 When creating a class with MooseX::Declare like:
290 \& use MooseX::Declare;
294 What actually happens is something like this:
300 \& use namespace::autoclean;
302 \& _\|_PACKAGE_\|_\->meta\->make_immutable;
306 So if you declare imports outside the class, the symbols get imported into the
307 \&\f(CW\*(C`main::\*(C'\fR namespace, not the class' namespace. The symbols then cannot be called
308 from within the class:
311 \& use MooseX::Declare;
312 \& use Data::Dump qw/dump/;
314 \& method dump($value) { return dump($value) } # Data::Dump::dump IS NOT in Foo::
315 \& method pp($value) { $self\->dump($value) } # an alias for our dump method
319 To solve this, only import MooseX::Declare outside the class definition
320 (because you have to). Make all other imports inside the class definition.
323 \& use MooseX::Declare;
325 \& use Data::Dump qw/dump/;
326 \& method dump($value) { return dump($value) } # Data::Dump::dump IS in Foo::
327 \& method pp($value) { $self\->dump($value) } # an alias for our dump method
330 \& Foo\->new\->dump($some_value);
331 \& Foo\->new\->pp($some_value);
334 \&\fB\s-1NOTE\s0\fR that the import \f(CW\*(C`Data::Dump::dump()\*(C'\fR and the method \f(CW\*(C`Foo::dump()\*(C'\fR,
335 although having the same name, do not conflict with each other, because the
336 imported \f(CW\*(C`dump\*(C'\fR function will be cleaned during compile time, so only the
337 method remains there at run time. If you want to do more esoteric things with
338 imports, have a look at the \f(CW\*(C`clean\*(C'\fR keyword and the \f(CW\*(C`dirty\*(C'\fR trait.
340 .IX Header "SEE ALSO"
345 MooseX::Method::Signatures
349 vim syntax: <http://www.vim.org/scripts/script.php?script_id=2526>
351 emacs syntax: <http://github.com/jrockway/cperl\-mode>
353 Geany syntax + notes: <http://www.cattlegrid.info/blog/2009/09/moosex\-declare\-geany\-syntax.html>
356 Florian Ragwitz <rafl@debian.org>
358 With contributions from:
359 .IP "Ash Berlin <ash@cpan.org>" 4
360 .IX Item "Ash Berlin <ash@cpan.org>"
362 .IP "Chas. J. Owens \s-1IV\s0 <chas.owens@gmail.com>" 4
363 .IX Item "Chas. J. Owens IV <chas.owens@gmail.com>"
364 .IP "Chris Prather <chris@prather.org>" 4
365 .IX Item "Chris Prather <chris@prather.org>"
366 .IP "Dave Rolsky <autarch@urth.org>" 4
367 .IX Item "Dave Rolsky <autarch@urth.org>"
368 .IP "Devin Austin <dhoss@cpan.org>" 4
369 .IX Item "Devin Austin <dhoss@cpan.org>"
370 .IP "Hans Dieter Pearcey <hdp@cpan.org>" 4
371 .IX Item "Hans Dieter Pearcey <hdp@cpan.org>"
372 .IP "Justin Hunter <justin.d.hunter@gmail.com>" 4
373 .IX Item "Justin Hunter <justin.d.hunter@gmail.com>"
374 .IP "Matt Kraai <kraai@ftbfs.org>" 4
375 .IX Item "Matt Kraai <kraai@ftbfs.org>"
376 .IP "Michele Beltrame <arthas@cpan.org>" 4
377 .IX Item "Michele Beltrame <arthas@cpan.org>"
378 .IP "Nelo Onyiah <nelo.onyiah@gmail.com>" 4
379 .IX Item "Nelo Onyiah <nelo.onyiah@gmail.com>"
380 .IP "nperez <nperez@cpan.org>" 4
381 .IX Item "nperez <nperez@cpan.org>"
382 .IP "Piers Cawley <pdcawley@bofh.org.uk>" 4
383 .IX Item "Piers Cawley <pdcawley@bofh.org.uk>"
384 .IP "Rafael Kitover <rkitover@io.com>" 4
385 .IX Item "Rafael Kitover <rkitover@io.com>"
386 .IP "Robert a\*^XXphaylona\*^XX Sedlacek <rs@474.at>" 4
387 .IX Item "Robert a^XXphaylona^XX Sedlacek <rs@474.at>"
388 .IP "Stevan Little <stevan.little@iinteractive.com>" 4
389 .IX Item "Stevan Little <stevan.little@iinteractive.com>"
390 .IP "Tomas Doran <bobtfish@bobtfish.net>" 4
391 .IX Item "Tomas Doran <bobtfish@bobtfish.net>"
392 .IP "Yanick Champoux <yanick@babyl.dyndns.org>" 4
393 .IX Item "Yanick Champoux <yanick@babyl.dyndns.org>"
395 .SH "COPYRIGHT AND LICENSE"
396 .IX Header "COPYRIGHT AND LICENSE"
397 Copyright (c) 2008, 2009 Florian Ragwitz
399 Licensed under the same terms as perl itself.