my($self, @role_specs) = @_;
require 'Mouse/Meta/Role/Composite.pm';
- my $composite = Mouse::Meta::Role::Composite->create_anon_role();
-
- foreach my $role_spec (@role_specs) {
- my($role, $args) = @{$role_spec};
- $role->apply($composite, %{$args});
- }
- return $composite;
+ return Mouse::Meta::Role::Composite->new(roles => \@role_specs);
}
sub add_before_method_modifier;
use Mouse::Meta::Role::Application;
our @ISA = qw(Mouse::Meta::Role);
+sub new {
+ my $class = shift;
+ my $args = $class->Mouse::Object::BUILDARGS(@_);
+ my $roles = delete $args->{roles};
+ my $self = $class->create_anon_role(%{$args});
+ foreach my $role_spec(@{$roles}) {
+ my($role, $args) = ref($role_spec) eq 'ARRAY'
+ ? @{$role_spec}
+ : ($role_spec, {});
+ $role->apply($self, %{$args});
+ }
+ return $self;
+}
+
+sub apply_params {
+ #my($self, $role_params) = @_;
+ # TODO
+ return $_[0];
+}
+
sub get_method_list {
my($self) = @_;
return keys %{ $self->{methods} };
use warnings;
use Test::More;
-$TODO = q{Mouse is not yet completed};
use Test::Exception;
use Mouse::Meta::Role::Application;
]
);
isa_ok($c, 'Mouse::Meta::Role::Composite');
-
+ { local $TODO = 'M::M::R::Compisite name';
is($c->name, 'Role::Foo|Role::Bar|Role::Baz', '... got the composite role name');
-
+ }
is_deeply($c->get_roles, [
Role::Foo->meta,
Role::Bar->meta,
Role::Bar
Role::Baz
);
-
+ { local $TODO = 'cannot apply a composite role directly';
lives_ok {
Mouse::Meta::Role::Application->new->apply($c);
} '... this composed okay';
+ }
##... now nest 'em
{
]
);
isa_ok($c2, 'Mouse::Meta::Role::Composite');
-
+ { local $TODO = 'name';
is($c2->name, 'Role::Foo|Role::Bar|Role::Baz|Role::Gorch', '... got the composite role name');
-
+ }
is_deeply($c2->get_roles, [
$c,
Role::Gorch->meta,