+ - Switch composed role names to be a valid package name
+
0.9.5 Tue Jan 11 2011
- Fix clobberage of runtime-installed wrappers by Sub::Defer
- Fix nonMoo constructor firing through multiple layers of Moo
sub create_class_with_roles {
my ($me, $superclass, @roles) = @_;
- my $new_name = join('+', $superclass, my $compose_name = join '+', @roles);
+ my $new_name = join(
+ '__WITH__', $superclass, my $compose_name = join '__AND__', @roles
+ );
+
return $new_name if $Role::Tiny::COMPOSED{class}{$new_name};
require Sub::Quote;
die "${role} is not a Role::Tiny" unless my $info = $INFO{$role};
}
+ $Moo::MAKERS{$new_name} = {};
+
$me->_handle_constructor(
$new_name, { map %{$INFO{$_}{attributes}||{}}, @roles }, $superclass
);
die "No roles supplied!" unless @roles;
- my $new_name = join('+', $superclass, my $compose_name = join '+', @roles);
+ my $new_name = join(
+ '__WITH__', $superclass, my $compose_name = join '__AND__', @roles
+ );
+
return $new_name if $COMPOSED{class}{$new_name};
foreach my $role (@roles) {
--- /dev/null
+use strictures 1;
+use Test::More;
+use Sub::Quote;
+
+{
+ package One; use Moo;
+ has one => (is => 'ro', default => sub { 'one' });
+
+ package One::P1; use Moo::Role;
+ has two => (is => 'ro', default => sub { 'two' });
+
+ package One::P2; use Moo::Role;
+ has three => (is => 'ro', default => sub { 'three' });
+}
+
+my $combined = Moo::Role->create_class_with_roles('One', qw(One::P1 One::P2));
+isa_ok $combined, "One";
+ok $combined->does($_), "Does $_" for qw(One::P1 One::P2);
+
+my $c = $combined->new;
+is $c->one, "one", "attr default set from class";
+is $c->two, "two", "attr default set from role";
+is $c->three, "three", "attr default set from role";
+
+done_testing;