From: Matt S Trout Date: Wed, 4 Apr 2012 04:03:46 +0000 (+0000) Subject: add required methods for roles X-Git-Tag: v0.009_015~16 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=55afe2664248907e42b479442677c59404a15e11;p=gitmo%2FMoo.git add required methods for roles --- diff --git a/Changes b/Changes index a0b9d7e..7884efb 100644 --- a/Changes +++ b/Changes @@ -1,5 +1,7 @@ - Introduce Moo::HandleMoose, which should allow Moo classes and roles - to be treated as Moose classes/roles + to be treated as Moose classes/roles. Supported so far: + - Some level of attributes and methods for both classes and roles + - Required methods in roles 0.009014 - 2012-03-29 - Split Role::Tiny out into its own dist diff --git a/lib/Moo/HandleMoose.pm b/lib/Moo/HandleMoose.pm index 08f49a6..5d5c522 100644 --- a/lib/Moo/HandleMoose.pm +++ b/lib/Moo/HandleMoose.pm @@ -37,12 +37,17 @@ sub inject_real_metaclass_for { my %methods = %{Role::Tiny->_concrete_methods_of($name)}; my @attrs; { + # This local is completely not required for roles but harmless local @{_getstash($name)}{keys %methods}; foreach my $name (keys %$attr_specs) { - push @attrs, $meta->add_attribute($name => %{$attr_specs->{$name}}); + my %spec = %{$attr_specs->{$name}}; + $spec{is} = 'ro' if $spec{is} eq 'lazy'; + push @attrs, $meta->add_attribute($name => %spec); } } - unless ($am_role) { + if ($am_role) { + $meta->add_required_methods(@{$Moo::Role::INFO{$name}{requires}}); + } else { foreach my $attr (@attrs) { foreach my $method (@{$attr->associated_methods}) { $method->{body} = $name->can($method->name);