From: gfx Date: Mon, 19 Oct 2009 06:08:29 +0000 (+0900) Subject: Add calculate_all_roles() to Meta::Class/Meta::Role X-Git-Tag: 0.40~11 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=e72648617a5de4b9d589b9642ff2e84368809410;p=gitmo%2FMouse.git Add calculate_all_roles() to Meta::Class/Meta::Role --- diff --git a/lib/Mouse/Meta/Class.pm b/lib/Mouse/Meta/Class.pm index 7b40497..167f4b9 100644 --- a/lib/Mouse/Meta/Class.pm +++ b/lib/Mouse/Meta/Class.pm @@ -44,6 +44,13 @@ sub is_anon_class{ sub roles { $_[0]->{roles} } +sub calculate_all_roles { + my $self = shift; + my %seen; + return grep { !$seen{ $_->name }++ } + map { $_->calculate_all_roles } @{ $self->roles }; +} + sub superclasses { my $self = shift; diff --git a/lib/Mouse/Meta/Role.pm b/lib/Mouse/Meta/Role.pm index 9c56aab..d8d4053 100644 --- a/lib/Mouse/Meta/Role.pm +++ b/lib/Mouse/Meta/Role.pm @@ -35,6 +35,13 @@ sub is_anon_role{ sub get_roles { $_[0]->{roles} } +sub calculate_all_roles { + my $self = shift; + my %seen; + return grep { !$seen{ $_->name }++ } + ($self, map { $_->calculate_all_roles } @{ $self->get_roles }); +} + sub get_required_method_list{ return @{ $_[0]->{required_methods} }; }