- has keyword now takes a 'metaclass' option
to support custom attribute meta-classes
on a per-attribute basis
- - added tests for this
+ - added tests for this
+ - the 'has' keyword not accepts inherited slot
+ specifications (has '+foo'). This is still an
+ experimental feature and probably not finished
+ see t/038_attribute_inherited_slot_specs.t for
+ more details, or ask about it on #moose
* Moose::Role
- keywords are now exported with Sub::Exporter
* Moose::Meta::TypeConstraints
- added type constraint unions
- added tests for this
+ - reorganized the type constraint hierarchy, thanks
+ to nothingmuch for his help and advice on this
+ - added some tests for this
0.04 Sun. April 16th, 2006
* Moose::Role
my $inherited_attr = $meta->find_attribute_by_name($1);
(defined $inherited_attr)
|| confess "Could not find an attribute by the name of '$1' to inherit from";
- (scalar keys %options == 1 && exists $options{default})
- || confess "Inherited slot specifications can only alter the 'default' option";
+ #(scalar keys %options == 1 && exists $options{default})
+ # || confess "Inherited slot specifications can only alter the 'default' option";
my $new_attr = $inherited_attr->clone(%options);
$meta->add_attribute($new_attr);
}
string. The string can be either a class name, or a type defined using
Moose's type defintion features.
+=item I<coerce =E<gt> (1|0)>
+
+This will attempt to use coercion with the supplied type constraint to change
+the value passed into any accessors of constructors. You B<must> have supplied
+a type constraint in order for this to work. See L<Moose::Cookbook::Recipe5>
+for an example usage.
+
+=item I<does =E<gt> $role_name>
+
+This will accept the name of a role which the value stored in this attribute
+is expected to have consumed.
+
+=item I<required =E<gt> (1|0)>
+
+This marks the attribute as being required. This means a value must be supplied
+during class construction, and the attribute can never be set to C<undef> with
+an accessor.
+
+=item I<weak_ref =E<gt> (1|0)>
+
+This will tell the class to strore the value of this attribute as a weakened
+reference. If an attribute is a weakened reference, it can B<not> also be coerced.
+
+=item I<lazy =E<gt> (1|0)>
+
+This will tell the class to not create this slot until absolutely nessecary.
+If an attribute is marked as lazy it B<must> have a default supplied.
+
+=item I<trigger =E<gt> $code>
+
+The trigger option is a CODE reference which will be called after the value of
+the attribute is set. The CODE ref will be passed the instance itself, the
+updated value and the attribute meta-object (this is for more advanced fiddling
+and can typically be ignored in most cases).
+
=back
=item B<before $name|@names =E<gt> sub { ... }>
'weaken($_[0]->{$attr_name});'
: '')
. ($self->has_trigger ?
- '$self->trigger->($_[0], ' . $value_name . ');'
+ '$self->trigger->($_[0], ' . $value_name . ', $self);'
: '')
. ' }'
. ($self->is_lazy ?
'weaken($_[0]->{$attr_name});'
: '')
. ($self->has_trigger ?
- '$self->trigger->($_[0], ' . $value_name . ');'
+ '$self->trigger->($_[0], ' . $value_name . ', $self);'
: '')
. ' }';
my $sub = eval $code;
my $self = $class->SUPER::new_object(%params);
foreach my $attr ($class->compute_all_applicable_attributes()) {
next unless $params{$attr->name} && $attr->can('has_trigger') && $attr->has_trigger;
- $attr->trigger->($self, $params{$attr->name});
+ $attr->trigger->($self, $params{$attr->name}, $attr);
}
return $self;
}
use strict;
use warnings;
-use Test::More tests => 10;
+use Test::More tests => 12;
use Test::Exception;
BEGIN {
Bar->meta->get_attribute('bar'),
'... Foo and Bar have different copies of bar');
+ok(Bar->meta->get_attribute('bar')->has_type_constraint,
+ '... Bar::bar inherited the type constraint too');
-
-
-
-
-
+is(Bar->meta->get_attribute('bar')->type_constraint->name,
+ 'Str', '... Bar::bar inherited the right type constraint too');