Closed Ovid closed 3 years ago
Here's how it can be done in Zydeco. Zydeco doesn't support renaming methods composed from roles, but it does support parameterized roles. (Like MooseX::Role::Parameterized or Package::Variant+Moo::Role.)
Generally I dislike renaming methods from roles because it means that $object->does($rolename)
no longer guarantees that all the methods from the role's API will be available.
use v5.16;
package Local::App {
use Zydeco;
role CounterRole ( Str $get, Str $inc ) {
has $counter (
type => PositiveOrZeroInt,
default => 0,
reader => $get,
handles_via => 'Counter',
handles => [ $inc => 'inc...' ],
);
}
class TwoCounters does CounterRole('value1', 'inc_first'),
CounterRole('value2', 'inc_second')
{
method to_string {
sprintf "counter1 = %d; counter2 = %d", $self->value1, $self->value2;
}
overload q("") => 'to_string', fallback => true;
}
}
my $c = Local::App->new_twocounters;
$c->inc_first->inc_first->inc_second;
say $c;
This is resolved for the MVP. Further issues should be new tickets.
This ticket is for feedback on Proposal: Multiple Role Application.