1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
|
#!/usr/bin/perl
use strict;
use warnings;
use Test::More;
use Test::Exception;
{
package Foo::Meta::Attribute;
use Moose;
extends 'Moose::Meta::Attribute';
around 'new' => sub {
my $next = shift;
my $self = shift;
my $name = shift;
$next->($self, $name, (is => 'rw', isa => 'Foo'), @_);
};
package Foo;
use Moose;
has 'foo' => (metaclass => 'Foo::Meta::Attribute');
}
{
my $foo = Foo->new;
isa_ok($foo, 'Foo');
my $foo_attr = Foo->meta->get_attribute('foo');
isa_ok($foo_attr, 'Foo::Meta::Attribute');
isa_ok($foo_attr, 'Moose::Meta::Attribute');
is($foo_attr->name, 'foo', '... got the right name for our meta-attribute');
ok($foo_attr->has_accessor, '... our meta-attrubute created the accessor for us');
ok($foo_attr->has_type_constraint, '... our meta-attrubute created the type_constraint for us');
my $foo_attr_type_constraint = $foo_attr->type_constraint;
isa_ok($foo_attr_type_constraint, 'Moose::Meta::TypeConstraint');
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 Moose;
extends 'Class::MOP::Attribute';
package Bar;
use Moose;
::lives_ok {
has 'bar' => (metaclass => 'Bar::Meta::Attribute');
} '... the attribute metaclass need not be a Moose::Meta::Attribute as long as it behaves';
}
{
package Moose::Meta::Attribute::Custom::Foo;
sub register_implementation { 'Foo::Meta::Attribute' }
package Moose::Meta::Attribute::Custom::Bar;
use Moose;
extends 'Moose::Meta::Attribute';
package Another::Foo;
use Moose;
::lives_ok {
has 'foo' => (metaclass => 'Foo');
} '... the attribute metaclass alias worked correctly';
::lives_ok {
has 'bar' => (metaclass => 'Bar', is => 'bare');
} '... the attribute metaclass alias worked correctly';
}
{
my $foo_attr = Another::Foo->meta->get_attribute('foo');
isa_ok($foo_attr, 'Foo::Meta::Attribute');
isa_ok($foo_attr, 'Moose::Meta::Attribute');
my $bar_attr = Another::Foo->meta->get_attribute('bar');
isa_ok($bar_attr, 'Moose::Meta::Attribute::Custom::Bar');
isa_ok($bar_attr, 'Moose::Meta::Attribute');
}
done_testing;
|