Also see Moose::Manual::Delta for more details of, and workarounds
for, noteworthy changes.
+0.XX
+ * Moose::Meta::Attribute
+ - When adding an attribute to a metaclass, if the attribute has no
+ methods associated with, it will now throw an error. (hdp)
+
0.83 Tue, Jun 23, 2009
* Moose::Meta::Class
- Fix _construct_instance not setting the special __MOP__ object
$options->{accessor} ||= $name;
}
}
+ elsif ($options->{is} eq 'bare') {
+ # do nothing, but don't complain (later) about missing methods
+ }
else {
$class->throw_error("I do not understand this option (is => " . $options->{is} . ") on attribute ($name)", data => $options->{is});
}
## installing accessors
+sub attach_to_class {
+ my $self = shift;
+ unless (
+ $self->has_accessor
+ || $self->has_reader
+ || $self->has_writer
+ || $self->has_handles
+ # init_arg?
+ || @{ $self->associated_methods }
+ || ($self->_is_metadata || '') eq 'bare'
+ ) {
+ $self->throw_error(
+ 'Attribute (' . $self->name . ') has no associated methods'
+ . ' (did you mean to provide an "is" argument?)'
+ )
+ }
+ return $self->SUPER::attach_to_class(@_);
+}
+
sub accessor_metaclass { 'Moose::Meta::Method::Accessor' }
sub install_accessors {
} '... the attribute metaclass alias worked correctly';
::lives_ok {
- has 'bar' => (metaclass => 'Bar');
+ has 'bar' => (metaclass => 'Bar', is => 'bare');
} '... the attribute metaclass alias worked correctly';
}
has 'one_last_one' => (is => 'rw', isa => 'Ref');
# this one will work here ....
- has 'fail' => (isa => 'CodeRef');
- has 'other_fail';
+ has 'fail' => (isa => 'CodeRef', is => 'bare');
+ has 'other_fail' => (is => 'bare');
package Bar;
use Moose;
documentation => q{
The 'foo' attribute is my favorite
attribute in the whole wide world.
- }
+ },
+ is => 'bare',
);
}
use Moose;
}
-lives_ok { OutOfClassTest::has('foo'); } 'create attr via direct sub call';
-lives_ok { OutOfClassTest->can('has')->('bar'); } 'create attr via can';
+lives_ok { OutOfClassTest::has('foo', is => 'bare'); } 'create attr via direct sub call';
+lives_ok { OutOfClassTest->can('has')->('bar', is => 'bare'); } 'create attr via can';
ok(OutOfClassTest->meta->get_attribute('foo'), 'attr created from sub call');
ok(OutOfClassTest->meta->get_attribute('bar'), 'attr created from can');
has 'bar' => (
metaclass => 'Bar::Meta::Attribute',
- my_legal_option => sub { 'Bar' }
+ my_legal_option => sub { 'Bar' },
+ is => 'bare',
);
package Bar::B;
},
},
],
+ is => 'bare',
);
}
},
},
],
+ is => 'bare',
);
}
--- /dev/null
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+
+use Test::More tests => 2;
+
+use Moose ();
+use Moose::Meta::Class;
+
+my $meta = Moose::Meta::Class->create_anon_class;
+
+#local $TODO = 'not implemented yet';
+
+eval { $meta->add_attribute('foo') };
+like $@, qr/Attribute \(foo\) has no associated methods/,
+ 'correct error message';
+
+ok(
+ eval { $meta->add_attribute('bar', is => 'bare'); 1 },
+ 'add attribute with no methods',
+) or diag $@;
for (1..3) {
has "err$_" => (
isa => 'Str | Int',
+ is => 'bare',
);
}
has age => (
isa => 'Positive',
+ is => 'bare',
);
}
has age => (
isa => 'Negative',
+ is => 'bare',
);
}
MooseAlike1->import();
- ::lives_ok( sub { has( 'size' ) },
+ ::lives_ok( sub { has( 'size', is => 'bare' ) },
'has was exported via MooseAlike1' );
MooseAlike1->unimport();
MooseAlike2->import();
- ::lives_ok( sub { has( 'size' ) },
+ ::lives_ok( sub { has( 'size', is => 'bare' ) },
'has was exported via MooseAlike2' );
MooseAlike2->unimport();
package Foo;
use Moose;
- has 'foo';
+ has 'foo', is => 'bare';
}
{
extends 'Foo';
- has 'bar';
+ has 'bar', is => 'bare';
}
my %trustme = (
'Moose' => ['make_immutable'],
- 'Moose::Meta::Attribute' => [ 'interpolate_class', 'throw_error' ],
+ 'Moose::Meta::Attribute' => [
+ qw( interpolate_class
+ throw_error
+ attach_to_class
+ )
+ ],
'Moose::Meta::Class' => [
qw( check_metaclass_compatibility
construct_instance