[Moose-commits] r7689 - Moose/trunk/lib/Moose/Manual
autarch at code2.0beta.co.uk
autarch at code2.0beta.co.uk
Sat Feb 14 17:57:40 GMT 2009
Author: autarch
Date: 2009-02-14 09:57:40 -0800 (Sat, 14 Feb 2009)
New Revision: 7689
Modified:
Moose/trunk/lib/Moose/Manual/Attributes.pod
Log:
Make a bunch of example attributes read-only
Modified: Moose/trunk/lib/Moose/Manual/Attributes.pod
===================================================================
--- Moose/trunk/lib/Moose/Manual/Attributes.pod 2009-02-14 17:55:33 UTC (rev 7688)
+++ Moose/trunk/lib/Moose/Manual/Attributes.pod 2009-02-14 17:57:40 UTC (rev 7689)
@@ -152,7 +152,7 @@
required, simply set the C<required> option to true:
has 'name' => (
- is => 'rw',
+ is => 'ro',
required => 1,
);
@@ -181,7 +181,7 @@
for the C<default> option:
has 'size' => (
- is => 'rw',
+ is => 'ro',
default => 'medium',
predicate => 'has_size',
);
@@ -197,7 +197,7 @@
reference will be called as a method on the object.
has 'size' => (
- is => 'rw',
+ is => 'ro',
default =>
sub { ( 'small', 'medium', 'large' )[ int( rand 3 ) ] },
predicate => 'has_size',
@@ -210,7 +210,7 @@
method on the object, with no additional parameters:
has 'size' => (
- is => 'rw',
+ is => 'ro',
default => sub {
my $self = shift;
@@ -229,7 +229,7 @@
shared by all objects:
has 'mapping' => (
- is => 'rw',
+ is => 'ro',
default => {}, # wrong!
);
@@ -241,7 +241,7 @@
reference:
has 'mapping' => (
- is => 'rw',
+ is => 'ro',
default => sub { {} }, # right!
);
@@ -251,7 +251,7 @@
supply a C<builder> method for your attribute:
has 'size' => (
- is => 'rw',
+ is => 'ro',
builder => '_build_size',
predicate => 'has_size',
);
@@ -317,7 +317,7 @@
C<lazy>:
has 'size' => (
- is => 'rw',
+ is => 'ro',
lazy => 1,
builder => '_build_size',
);
@@ -344,14 +344,14 @@
option. This bundles up a number of options together:
has 'size' => (
- is => 'rw',
+ is => 'ro',
lazy_build => 1,
);
This is the same as specifying all of these options:
has 'size' => (
- is => 'rw',
+ is => 'ro',
lazy => 1,
builder => '_build_size',
clearer => 'clear_size',
@@ -362,14 +362,14 @@
and predicate will as well:
has '_size' => (
- is => 'rw',
+ is => 'ro',
lazy_build => 1,
);
becomes:
has '_size' => (
- is => 'rw',
+ is => 'ro',
lazy => 1,
builder => '_build__size',
clearer => '_clear_size',
@@ -384,7 +384,7 @@
always provide your own:
has 'size' => (
- is => 'rw',
+ is => 'ro',
lazy_build => 1,
clearer => '_clear_size',
);
@@ -402,7 +402,7 @@
Both of these goals can be accomplished with the C<init_arg> option:
has 'bigness' => (
- is => 'rw',
+ is => 'ro',
init_arg => 'size',
);
@@ -413,7 +413,7 @@
the constructor. This is particularly handy for private attributes:
has '_genetic_code' => (
- is => 'rw',
+ is => 'ro',
lazy_build => 1,
init_arg => undef,
);
@@ -471,7 +471,7 @@
Attributes can be restricted to only accept certain types:
has 'first_name' => (
- is => 'rw',
+ is => 'ro',
isa => 'Str',
);
@@ -493,7 +493,7 @@
Attributes can define methods which simply delegate to their values:
has 'hair_color' => (
- is => 'rw',
+ is => 'ro',
isa => 'Graphics::Color::RGB',
handles => { hair_color_hex => 'as_hex_string' },
);
@@ -529,7 +529,7 @@
use MooseX::MetaDescription;
has 'size' => (
- is => 'rw',
+ is => 'ro',
traits => ['MooseX::MetaDescription::Meta::Trait'],
description => {
html_widget => 'text_input',
More information about the Moose-commits
mailing list