From: Fuji, Goro Date: Sat, 25 Sep 2010 05:49:31 +0000 (+0900) Subject: Make the interface of composite role more comatible X-Git-Tag: 0.72~19 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=92d87891cfa6391f35fcde0dfc09ea00635525e4;p=gitmo%2FMouse.git Make the interface of composite role more comatible --- diff --git a/lib/Mouse/Meta/Role.pm b/lib/Mouse/Meta/Role.pm index b9055ee..045f0e5 100644 --- a/lib/Mouse/Meta/Role.pm +++ b/lib/Mouse/Meta/Role.pm @@ -75,13 +75,7 @@ sub combine { 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; diff --git a/lib/Mouse/Meta/Role/Composite.pm b/lib/Mouse/Meta/Role/Composite.pm index b05f917..240540b 100644 --- a/lib/Mouse/Meta/Role/Composite.pm +++ b/lib/Mouse/Meta/Role/Composite.pm @@ -4,6 +4,26 @@ use Mouse::Meta::Role; 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} }; diff --git a/Moose-t-failing/030_roles/020_role_composite.t b/t/030_roles/020_role_composite.t similarity index 92% rename from Moose-t-failing/030_roles/020_role_composite.t rename to t/030_roles/020_role_composite.t index 78335e8..0a6c6c7 100644 --- a/Moose-t-failing/030_roles/020_role_composite.t +++ b/t/030_roles/020_role_composite.t @@ -7,7 +7,6 @@ use strict; use warnings; use Test::More; -$TODO = q{Mouse is not yet completed}; use Test::Exception; use Mouse::Meta::Role::Application; @@ -36,9 +35,9 @@ use Mouse::Meta::Role::Composite; ] ); 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, @@ -51,10 +50,11 @@ use Mouse::Meta::Role::Composite; 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 { @@ -65,9 +65,9 @@ use Mouse::Meta::Role::Composite; ] ); 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,