Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Object::InsideOut and Roles/Mixins

by Yary (Scribe)
on Apr 11, 2014 at 17:15 UTC ( #1082001=perlquestion: print w/ replies, xml ) Need Help??
Yary has asked for the wisdom of the Perl Monks concerning the following question:

I wanted to try out Object::InsideOut, having already done a moderate-sized project with Moose, to educate myself and get the feel for another way of doing things.

But one part of Moose that I came to like are "roles", and a quick skim of Object::InsideOut docs doesn't mention that concept, or "mixins" or "interfaces."

Is there a module, or technique, for composing a role/mixin or defining an interface with Object::InsideOut?

Comment on Object::InsideOut and Roles/Mixins
Re: Object::InsideOut and Roles/Mixins
by Arunbear (Parson) on Apr 11, 2014 at 17:28 UTC
    Role::Tiny should be able to provide this service (for method reuse at least).
      Thanks... I would also want O::IO "fields" (what Moose calls "attributes") in the roles, so will look at the other modules Role::Tiny refers to, Role::Basic and Moo::Role. I'll have to think more about fields and how these role-helpers work to pick the right one.

      edit now I am in danger of writing Object::InsideOut::Role - not that I have the time to- but after re-reading about them, and comments implementers have made with the benefit of hindsight, and thinking about how I've already used and misused roles, it's tempting to roll something up taking it all into account.

        It's difficult to get roles and attributes to play nice. Attributes basically have two parts to the implementation:

        1. They need to be initialized in the constructor; and

        2. You need to provide accessors for them.

        The accessors are easy. But your role framework doesn't have any control over the constructor; the constructor gets built by the class framework!

        That's why if you look at Perl implementations of roles, you'll see them fall into two neat categories:

        • Moose::Role, Mouse::Role, Moo::Role, and p5-mop roles all allow you to define attributes in roles.

          These role implementations are all part of larger frameworks that include a class builder.

        • Role::Tiny and Role::Tiny do not allow you to define attributes in roles.

          These role implementations are stand-alone.

        So basically, if you want to write a role implementation that supports attributes, you'll need to write a class implementation to support it.

        I'm not saying you shouldn't do it. It's a good learning experience.

        use Moops; class Cow :rw { has name => (default => 'Ermintrude') }; say Cow->new->name

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1082001]
Front-paged by Arunbear
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (12)
As of 2014-10-01 20:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    What is your favourite meta-syntactic variable name?














    Results (38 votes), past polls