my %options;
- $options{':attribute_metaclass'} = $policy->attribute_metaclass
- if $policy->can('attribute_metaclass');
+ # build options out of policy's constants
+ $policy->can($_) and $options{":$_"} = $policy->$_()
+ for (qw(
+ attribute_metaclass
+ instance_metaclass
+ method_metaclass
+ ));
my $package = caller();
+ $package->can('meta') and
+ croak("'$package' already has a meta() method");
# create a meta object so we can install &meta
my $meta = $metaclass->initialize($package => %options);
__END__
+
use strict;
use warnings;
-use Test::More tests => 8;
+use Test::More 'no_plan';
BEGIN {
use_ok('Moose::Policy');
extends 'Moose::Meta::Attribute';
+ # this method (mostly stolen from M::M::Attribute) just rebuilds the
+ # options so anything with 'is' gets PBP accessors
sub _process_options {
my ($class, $name, $options) = @_;
if (exists $options->{is}) {
{
package My::Moose::Policy;
+ # policy just specifies metaclass delegates
use constant attribute_metaclass => 'My::Moose::Meta::Attribute';
}
use Moose;
has 'bar' => (is => 'rw', default => 'Foo::bar');
+ has 'baz' => (is => 'ro', default => 'Foo::baz');
}
isa_ok(Foo->meta, 'Moose::Meta::Class');
can_ok($foo, 'get_bar');
can_ok($foo, 'set_bar');
+can_ok($foo, 'get_baz');
+
is($foo->get_bar, 'Foo::bar', '... got the right default value');
+is($foo->get_baz, 'Foo::baz', '... got the right default value');