From: Dave Rolsky Date: Mon, 14 Sep 2009 15:49:26 +0000 (-0500) Subject: Add some docs on shortcuts for declaring multiple attributes X-Git-Tag: 0.90~14 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=01fd70ed5d41bcfa561c198b172c594bc3256760;p=gitmo%2FMoose.git Add some docs on shortcuts for declaring multiple attributes --- diff --git a/lib/Moose/Manual/Attributes.pod b/lib/Moose/Manual/Attributes.pod index 35bcaed..9381a69 100644 --- a/lib/Moose/Manual/Attributes.pod +++ b/lib/Moose/Manual/Attributes.pod @@ -617,6 +617,24 @@ to C<'Bill'>. We recommend that you exercise caution when changing the type (C) of an inherited attribute. +=head1 MULTIPLE ATTRIBUTE SHORTCUTS + +If you have a number of attributes that differ only be name, you can declare +them all at once: + + package Point; + + use Moose; + + has [ 'x', 'y' ] => ( is => 'ro', isa => 'Int' ); + +Also, because C is just a function call, you can call it in a loop: + + for my $name ( qw( x y ) ) { + my $builder = '_build_' . $name; + has $name => ( is => 'ro', isa => 'Int', builder => $builder ); + } + =head1 MORE ON ATTRIBUTES Moose attributes are a big topic, and this document glosses over a few