Skip Menu |
 

This queue is for tickets about the Role-Tiny CPAN distribution.

Report information
The Basics
Id: 128470
Status: resolved
Priority: 0/
Queue: Role-Tiny

People
Owner: Nobody in particular
Requestors: djerius [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: 2.001003



Subject: roles w/ common attributes treated differently when composed w/ create_class_with_roles vs direct composition and apply_roles_to_package
Given these two essentially identical roles, package R1 { use Moo::Role; has a => ( is => 'rw', builder => sub { {} } ); after _build_a => sub { say __PACKAGE__ }; } package R2 { use Moo::Role; has a => ( is => 'rw', builder => sub { {} } ); after _build_a => sub { say __PACKAGE__ }; } I would expect that the following three approaches to composition would be equivalent: -------------- package C1 { use Moo; with 'R1'; with 'R2'; } C1->new->a; -------------- package C2 { use Moo; } my $class = Moo::Role->create_class_with_roles( 'C2', 'R1' ); Moo::Role->apply_roles_to_package( $class, 'R2' ); $class->new->a; -------------- package C3 { use Moo; } Moo::Role->apply_roles_to_package( 'C3', 'R1' ); Moo::Role->apply_roles_to_package( 'C3', 'R2' ); C3->new->a; However, they are not. % perl test.pl --------------- C1: R1 R2 --------------- C2: R2 --------------- C3: R1 R2 The results for the first and last approaches are what I expect to happen. Something seems to be going awry with create_class_with_roles. Attached is the example code. Thanks! Diab
Subject: test.pl
Download test.pl
text/x-perl 789b
use 5.010; use strictures 2; use Moo::Role (); package R1 { use Moo::Role; has a => ( is => 'rw', builder => sub { {} } ); after _build_a => sub { say __PACKAGE__ }; } package R2 { use Moo::Role; has a => ( is => 'rw', builder => sub { {} } ); after _build_a => sub { say __PACKAGE__ }; } package C1 { use Moo; with 'R1'; with 'R2'; } say '---------------'; say 'C1:'; C1->new->a; say '---------------'; say 'C2:'; package C2 { use Moo; } my $class = Moo::Role->create_class_with_roles( 'C2', 'R1' ); Moo::Role->apply_roles_to_package( $class, 'R2' ); $class->new->a; say '---------------'; say 'C3:'; package C3 { use Moo; } Moo::Role->apply_roles_to_package( 'C3', 'R1' ); Moo::Role->apply_roles_to_package( 'C3', 'R2' ); C3->new->a;
Fixed in Role::Tiny 2.001003. This will be included as a prereq in the next stable Moo release.
Download (untitled) / with headers
text/plain 152b
On Fri Oct 18 08:22:51 2019, haarg wrote: Show quoted text
> Fixed in Role::Tiny 2.001003. This will be included as a prereq in > the next stable Moo release.
Thanks!


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

Please report any issues with rt.cpan.org to rt-cpan-admin@bestpractical.com.