From: Yuval Kogman Date: Wed, 5 Jul 2006 00:12:34 +0000 (+0000) Subject: calculate_all_roles method X-Git-Tag: 0_11~5 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=b8aeb4dcc043ebd12cfd22af0037ac03aab77a50;p=gitmo%2FMoose.git calculate_all_roles method --- diff --git a/lib/Moose/Meta/Class.pm b/lib/Moose/Meta/Class.pm index 3fcb6d2..14073d9 100644 --- a/lib/Moose/Meta/Class.pm +++ b/lib/Moose/Meta/Class.pm @@ -34,6 +34,12 @@ sub add_role { push @{$self->roles} => $role; } +sub calculate_all_roles { + my $self = shift; + my %seen; + grep { !$seen{$_->name}++ } map { $_->calculate_all_roles } @{ $self->roles }; +} + sub does_role { my ($self, $role_name) = @_; (defined $role_name) diff --git a/lib/Moose/Meta/Role.pm b/lib/Moose/Meta/Role.pm index 9c87164..bea6656 100644 --- a/lib/Moose/Meta/Role.pm +++ b/lib/Moose/Meta/Role.pm @@ -95,6 +95,12 @@ sub add_role { push @{$self->get_roles} => $role; } +sub calculate_all_roles { + my $self = shift; + my %seen; + grep { !$seen{$_->name}++ } $self, map { $_->calculate_all_roles } @{ $self->get_roles }; +} + sub does_role { my ($self, $role_name) = @_; (defined $role_name) @@ -706,4 +712,4 @@ L This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. -=cut \ No newline at end of file +=cut