Class::Plain supports Role using Role::Tiny


Class::Plain was released at at 2022-09. This time, Class::Plain supports role using Role::Tiny at version 0.05.

use Class::Plain;
  
role Some::Role {
  
  method foo { ... }
    
  method bar { ... }
}
 
class Some::Class : does(Some::Role) {
  method foo { ... }
    
  # baz is wrapped in the around modifier by Class::Method::Modifiers
  method baz { ... }
}

See also the document of the role.

A role example is written in the cookbook.

Role - Cookbook of Class::Plain

Some role examples are written in the test codes.

role.t

Author's Comments in This Release

Currently I join the discussion of use feature 'class'.

I asked a question. Is it possible to adjust the class syntax so that the method keyword works with existing codes?.

In this discuttion, Ovid said that

I've actually been watching the development of your Class::Plain module and I think when you can get roles and push it a bit further, that's a good compromise between Corinna syntax and hash-based objects. You've got something working, so I would encourage you to push forward on that. I suspect a lot of people might like that compromise.

discussioncomment-3812515

So I started to search for the implementation of the role.

At first, I tried to implement it by myself, but I feel a little difficultness.

And I continue to search the web. I found Role::Tiny. I remember Mojolicious uses Role::Tiny.

I red the document of Role::Tiny and try it. I thought "this is good".

Role::Tiny's use Role::Tiny is the same as the role keyword in Corinna.

Role::Tiny's with is the same as does in Corinna.

Role::Tiny's requires is the same as method foo; in Corinna.

I only created the syntax suger of Role::Tiny using the spec of Corinna.

The role features of Class::Plain are completed!!!

Bug reports and opinions are here.

Github Issues - Class::Plain

Leave a comment

About Yuki Kimoto

user-pic I'm Perl Programmer. I LOVE Perl. I want to contribute Perl community and Perl users.