perlancar has asked for the wisdom of the Perl Monks concerning the following question:
How do you do per-object role composition on the typical OO/role frameworks e.g. Moose or Moo (I'm using Role::Tiny in this particular case)? So basically I create a role for a class, and I want the user to be able to mix that class on an as-needed basis. The manual way would be for the user to create a subclass:
package MyClass_With_Role1; use parent 'MyClass'; use Role::Tiny::With; with 'Role1';
Is there a shortcut for it? Something like:
my $obj = MyClass->new_with_roles('Role1');
I suspect Moose et al supports something like this, but I've never done this and do not know where to look.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Applying roles on the client-side (per-object role composition)
by Anonymous Monk on May 22, 2020 at 03:15 UTC | |
by perlancar (Hermit) on May 22, 2020 at 11:49 UTC |