From: Ricardo Signes Date: Fri, 8 Apr 2011 21:04:14 +0000 (-0400) Subject: use hypothetical next version of Data::OptList X-Git-Tag: 2.0100~176 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=8e590ae4a57950d3138f619cd4ec5456eb72aa19;p=gitmo%2FMoose.git use hypothetical next version of Data::OptList --- diff --git a/lib/Moose/Util.pm b/lib/Moose/Util.pm index 1128111..43defdb 100644 --- a/lib/Moose/Util.pm +++ b/lib/Moose/Util.pm @@ -3,7 +3,7 @@ package Moose::Util; use strict; use warnings; -use Data::OptList; +use Data::OptList 0.107; use Params::Util qw( _STRING ); use Sub::Exporter; use Scalar::Util 'blessed'; @@ -96,7 +96,18 @@ sub _apply_all_roles { Moose->throw_error("Must specify at least one role to apply to $applicant"); } - my $roles = Data::OptList::mkopt( [@_] ); + # If @_ contains role meta objects, mkopt will think that they're values, + # because they're references. In other words (roleobj1, roleobj2, + # roleobj3) will become [ [ roleobj1, roleobj2 ], [ roleobj3, undef ] ] + # -- this is no good. We'll preprocess @_ first to eliminate the potential + # bug. + # -- rjbs, 2011-04-08 + my $roles = Data::OptList::mkopt( [@_], { + moniker => 'role', + name_test => sub { + ! ref $_[0] or blessed($_[0]) && $_[0]->isa('Moose::Meta::Role') + } + }); my @role_metas; foreach my $role (@$roles) { diff --git a/t/roles/apply_role.t b/t/roles/apply_role.t index 05722b0..1c2c38e 100644 --- a/t/roles/apply_role.t +++ b/t/roles/apply_role.t @@ -183,4 +183,33 @@ foreach my $foo ( $foo, $foobar ) { is( $foo->bar, $foo2, '... got the right value for bar now' ); } +{ + { + package MRole; + use Moose::Role; + sub meth { } + } + + { + package MRole2; + use Moose::Role; + sub meth2 { } + } + + { + use Moose::Meta::Class; + use Moose::Object; + use Moose::Util qw(apply_all_roles); + + my $class = Moose::Meta::Class->create( 'Class' => ( + superclasses => [ 'Moose::Object' ], + )); + + apply_all_roles($class, MRole->meta, MRole2->meta); + + ok(Class->can('meth'), "can meth"); + ok(Class->can('meth2'), "can meth2"); + } +} + done_testing;