From: Shawn M Moore Date: Sat, 28 Mar 2009 22:49:51 +0000 (-0400) Subject: Don't iterate over the same list twice X-Git-Tag: 0.73_01~32 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=6fab0b75a64e959232d18f753eb4c0355ee9d2e4;p=gitmo%2FMoose.git Don't iterate over the same list twice (especially since the two loops can share state) --- diff --git a/lib/Moose/Util.pm b/lib/Moose/Util.pm index 66b0bc6..67b33ad 100644 --- a/lib/Moose/Util.pm +++ b/lib/Moose/Util.pm @@ -80,15 +80,10 @@ sub apply_all_roles { my $roles = Data::OptList::mkopt( [@_] ); - my $meta = ( blessed $applicant ? $applicant : find_meta($applicant) ); - - foreach my $role_spec (@$roles) { - Class::MOP::load_class( $role_spec->[0] ); - } - foreach my $role (@$roles) { - unless (Class::MOP::class_of($role->[0])->isa('Moose::Meta::Role') ) { + my $meta = Class::MOP::load_class( $role->[0] ); + unless ($meta->isa('Moose::Meta::Role') ) { require Moose; Moose->throw_error( "You can only consume roles, " . $role->[0] @@ -96,6 +91,8 @@ sub apply_all_roles { } } + my $meta = ( blessed $applicant ? $applicant : find_meta($applicant) ); + if ( scalar @$roles == 1 ) { my ( $role, $params ) = @{ $roles->[0] }; my $role_meta = Class::MOP::class_of($role);