{
}
{
}
{
has
foo
=> (
is
=>
'ro'
);
}
{
Moose::Util::MetaRole::apply_metaroles(
for
=> __PACKAGE__,
class_metaroles
=> {
attribute
=> [
'Foo::Meta::Attribute'
] },
role_metaroles
=> {
applied_attribute
=> [
'Foo::Meta::Attribute2'
] },
);
has
bar
=> (
is
=>
'ro'
);
}
ok(Moose::Util::does_role(Foo->meta->get_attribute(
'bar'
),
'Foo::Meta::Attribute'
),
"attrs defined in the class get the class metarole applied"
);
ok(!Moose::Util::does_role(Foo->meta->get_attribute(
'bar'
),
'Foo::Meta::Attribute2'
),
"attrs defined in the class don't get the role metarole applied"
);
ok(!Moose::Util::does_role(Foo->meta->get_attribute(
'foo'
),
'Foo::Meta::Attribute'
),
"attrs defined in the role don't get the metarole applied"
);
ok(!Moose::Util::does_role(Foo->meta->get_attribute(
'foo'
),
'Foo::Meta::Attribute'
),
"attrs defined in the role don't get the role metarole defined in the class applied"
);
{
}
{
}
{
Moose::Util::MetaRole::apply_metaroles(
for
=> __PACKAGE__,
class_metaroles
=> {
attribute
=> [
'Bar::Meta::Attribute'
] },
role_metaroles
=> {
applied_attribute
=> [
'Bar::Meta::Attribute2'
] },
);
has
foo
=> (
is
=>
'ro'
);
}
{
has
bar
=> (
is
=>
'ro'
);
}
ok(!Moose::Util::does_role(Bar->meta->get_attribute(
'bar'
),
'Bar::Meta::Attribute'
),
"attrs defined in the class don't get the class metarole from the role applied"
);
ok(!Moose::Util::does_role(Bar->meta->get_attribute(
'bar'
),
'Bar::Meta::Attribute2'
),
"attrs defined in the class don't get the role metarole applied"
);
ok(Moose::Util::does_role(Bar->meta->get_attribute(
'foo'
),
'Bar::Meta::Attribute2'
),
"attrs defined in the role get the role metarole applied"
);
ok(!Moose::Util::does_role(Bar->meta->get_attribute(
'foo'
),
'Bar::Meta::Attribute'
),
"attrs defined in the role don't get the class metarole applied"
);
{
}
{
}
{
Moose::Util::MetaRole::apply_metaroles(
for
=> __PACKAGE__,
class_metaroles
=> {
attribute
=> [
'Baz::Meta::Attribute'
] },
role_metaroles
=> {
applied_attribute
=> [
'Baz::Meta::Attribute2'
] },
);
has
foo
=> (
is
=>
'ro'
);
}
{
Moose::Util::MetaRole::apply_metaroles(
for
=> __PACKAGE__,
class_metaroles
=> {
attribute
=> [
'Baz::Meta::Attribute'
] },
role_metaroles
=> {
applied_attribute
=> [
'Baz::Meta::Attribute2'
] },
);
has
bar
=> (
is
=>
'ro'
);
}
ok(Moose::Util::does_role(Baz->meta->get_attribute(
'bar'
),
'Baz::Meta::Attribute'
),
"attrs defined in the class get the class metarole applied"
);
ok(!Moose::Util::does_role(Baz->meta->get_attribute(
'bar'
),
'Baz::Meta::Attribute2'
),
"attrs defined in the class don't get the role metarole applied"
);
ok(Moose::Util::does_role(Baz->meta->get_attribute(
'foo'
),
'Baz::Meta::Attribute2'
),
"attrs defined in the role get the role metarole applied"
);
ok(!Moose::Util::does_role(Baz->meta->get_attribute(
'foo'
),
'Baz::Meta::Attribute'
),
"attrs defined in the role don't get the class metarole applied"
);
{
around
_process_options
=>
sub
{
my
$orig
=
shift
;
my
$self
=
shift
;
my
(
$name
,
$params
) =
@_
;
$self
->
$orig
(
@_
);
$params
->{reader} .=
'_foo'
;
};
}
{
has
foo
=> (
is
=>
'ro'
,
isa
=>
'Str'
,
);
}
{
Moose::Util::MetaRole::apply_metaroles(
for
=> __PACKAGE__,
class_metaroles
=> {
attribute
=> [
'Accessor::Modifying::Role'
],
},
);
has
bar
=> (
is
=>
'ro'
,
isa
=>
'Str'
,
);
}
{
can_ok(
'Class::With::Trait'
,
'foo'
);
can_ok(
'Class::With::Trait'
,
'bar_foo'
);
}
{
Moose::Util::MetaRole::apply_metaroles(
for
=> __PACKAGE__,
role_metaroles
=> {
applied_attribute
=> [
'Accessor::Modifying::Role'
],
},
);
has
foo
=> (
is
=>
'ro'
,
isa
=>
'Str'
,
);
sub
foo_test {
my
$self
=
shift
;
return
$self
->can(
'foo_foo'
);
}
}
{
has
bar
=> (
is
=>
'ro'
,
isa
=>
'Str'
,
);
sub
bar_test {
my
$self
=
shift
;
return
$self
->can(
'bar'
);
}
}
{
can_ok(
'Class::With::Role::With::Trait'
,
'foo_foo'
);
can_ok(
'Class::With::Role::With::Trait'
,
'bar'
);
}
{
}
{
has
foo
=> (
traits
=> [
'Quux::Meta::Role::Attribute'
],
is
=>
'ro'
);
has
baz
=> (
is
=>
'ro'
);
}
{
Moose::Util::MetaRole::apply_metaroles(
for
=> __PACKAGE__,
role_metaroles
=> {
applied_attribute
=> [
'Quux::Meta::Role::Attribute'
]
},
);
has
bar
=> (
is
=>
'ro'
);
}
{
}
{
my
$foo
= Quux->meta->get_attribute(
'foo'
);
does_ok(
$foo
,
'Quux::Meta::Role::Attribute'
,
"individual attribute trait applied correctly"
);
my
$baz
= Quux->meta->get_attribute(
'baz'
);
ok(! does_role(
$baz
,
'Quux::Meta::Role::Attribute'
),
"applied_attribute traits do not end up applying to attributes from other roles during composition"
);
my
$bar
= Quux->meta->get_attribute(
'bar'
);
does_ok(
$bar
,
'Quux::Meta::Role::Attribute'
,
"attribute metarole applied correctly"
);
}
{
Moose::Util::MetaRole::apply_metaroles(
for
=> __PACKAGE__,
role_metaroles
=> {
applied_attribute
=> [
'Quux::Meta::Role::Attribute'
]
},
);
has
foo
=> (
is
=>
'ro'
);
}
{
has
bar
=> (
is
=>
'ro'
);
}
{
}
{
my
$foo
= ConsumesBoth->meta->get_attribute(
'foo'
);
does_ok(
$foo
,
'Quux::Meta::Role::Attribute'
,
'applied_attribute traits are preserved when one role consumes another'
);
my
$bar
= ConsumesBoth->meta->get_attribute(
'bar'
);
ok(! does_role(
$bar
,
'Quux::Meta::Role::Attribute'
),
"applied_attribute traits do not spill over from consumed role"
);
}
done_testing;