CC: | rjbs [...] icgroup.com |
Subject: | Moose::Util::apply_all_roles fails for role objects |
Date: | Fri, 08 Apr 2011 14:50:03 -0400 |
To: | bug-moose [...] rt.cpan.org |
From: | Mark Jason Dominus <mjd [...] plover.com> |
The manual says "the list of @roles should a list of names or
Moose::Meta::Role objects," but apply_all_roles garbles the argument
list. The following program demonstrates the problem:
package Role;
use Moose::Role;
sub meth { }
package Role2;
use Moose::Role;
sub meth2 { }
package main;
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,
Role->meta,
Role2->meta,
);
use Test::More;
ok(Class->can('meth'), "can meth");
ok(Class->can('meth2'), "can meth2");
Both methods should be found in Class; only the first is. The problem
persists if «Role->meta» is replaced with «"Role"».
RJBS identified the problem:
<rjbs> my $roles = Data::OptList::mkopt( [@_] );
<rjbs> You can't make an optlist from a list of references.
<rjbs> that's around line 100 of Moose::Util
<rjbs> It's going to drop every other role, basically.
He suggests replacing the line with:
Data::OptList::mkopt([ map { try{$_->isa('Moose::Meta::Role')} ? ($_, undef) : $_ } @_ ])
Mark Jason Dominus mjd@plover.com