* Moose
- keywords are now exported with Sub::Exporter
thanks to chansen for this commit
+ - has keyword now takes a 'metaclass' option
+ to support custom attribute meta-classes
+ on a per-attribute basis
+ - added tests for this
* Moose::Role
- keywords are now exported with Sub::Exporter
$meta = $class->meta();
(blessed($meta) && $meta->isa('Moose::Meta::Class'))
|| confess "Whoops, not møøsey enough";
+ ($meta->attribute_metaclass->isa('Moose::Meta::Attribute'))
+ || confess "Attribute metaclass must be a subclass of Moose::Meta::Attribute";
}
else {
- $meta = Moose::Meta::Class->initialize($class => (
- ':attribute_metaclass' => 'Moose::Meta::Attribute'
- ));
+ $meta = Moose::Meta::Class->initialize($class);
$meta->add_method('meta' => sub {
# re-initialize so it inherits properly
- Moose::Meta::Class->initialize($class => (
- ':attribute_metaclass' => 'Moose::Meta::Attribute'
- ));
+ Moose::Meta::Class->initialize($class);
})
}
return subname 'Moose::has' => sub {
my ($name, %options) = @_;
if ($options{metaclass}) {
+ _load_all_classes($options{metaclass});
+ ($options{metaclass}->isa('Moose::Meta::Attribute'))
+ || confess "Custom attribute metaclass must be a subclass of Moose::Meta::Attribute";
$meta->add_attribute($options{metaclass}->new($name, %options));
}
else {
default => sub { [] }
));
+sub initialize {
+ my $class = shift;
+ my $pkg = shift;
+ $class->SUPER::initialize($pkg,
+ ':attribute_metaclass' => 'Moose::Meta::Attribute',
+ @_);
+}
+
sub add_role {
my ($self, $role) = @_;
(blessed($role) && $role->isa('Moose::Meta::Role'))
=over 4
+=item B<initialize>
+
=item B<new_object>
We override this method to support the C<trigger> attribute option.
use strict;
use warnings;
-use Test::More tests => 10;
+use Test::More tests => 11;
use Test::Exception;
BEGIN {
use_ok('Moose');
}
-{
+{
package Foo::Meta::Attribute;
use strict;
use warnings;
is($foo_attr_type_constraint->name, 'Foo', '... got the right type constraint name');
is($foo_attr_type_constraint->parent->name, 'Object', '... got the right type constraint parent name');
+
+{
+ package Bar::Meta::Attribute;
+ use strict;
+ use warnings;
+
+ use base 'Class::MOP::Attribute';
+
+ package Bar;
+ use strict;
+ use warnings;
+ use Moose;
+
+ ::dies_ok {
+ has 'bar' => (metaclass => 'Bar::Meta::Attribute');
+ } '... the attribute metaclass must be a subclass of Moose::Meta::Attribute';
+}
+