Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: Class Attributes with Moo ?

by tobyink (Abbot)
on Dec 27, 2012 at 07:53 UTC ( #1010465=note: print w/replies, xml ) Need Help??


in reply to Class Attributes with Moo ?

Yes, this is a MooX module I've been meaning to write for some time. Like you, I've been using package variables, but a proper class attribute would give you delegation, type constraints, triggers, etc.

I may have a stab at writing something along these lines in the next couple of weeks. I just need to delve into the Method::Generate::* code to see how feasible it might be.

perl -E'sub Monkey::do{say$_,for@_,do{($monkey=[caller(0)]->[3])=~s{::}{ }and$monkey}}"Monkey say"->Monkey::do'

Replies are listed 'Best First'.
Re^2: Class Attributes with Moo ?
by mascip (Pilgrim) on Dec 27, 2012 at 16:22 UTC

    Thank you for your reply :-) I was wondering if i was missing anything.
    In the future if i need to use inheritance, i might put this timer as a simple attribute, and pass it to my objects from the client code. It's giving some non-related job to the client, but it should do the trick.
    I'll keep an eye open, in case you created a new MooX module. Sorry i cannot help : i don't have the skills nor the time to develop them right now.

      OK, MooX::ClassAttribute is now on CPAN. Subclassing Method::Generate::Accessor to generate class attributes was relatively easy. The hard parts were getting class attributes defined in roles to work, and getting Moose inflation going.

      perl -E'sub Monkey::do{say$_,for@_,do{($monkey=[caller(0)]->[3])=~s{::}{ }and$monkey}}"Monkey say"->Monkey::do'

        Wow, that was fast! You're a star thanks a lot :-)

Re^2: Class Attributes with Moo ?
by mascip (Pilgrim) on Dec 28, 2012 at 07:29 UTC

    I don't have the time to try it today, but maybe tomorrow : Class::Data::Inheritable might do the trick according to its documentation.
    This could be enough for me right now.

    The annoying bit is that you have to inherit from Class::Data::Inheritable. I'm not sure how annoying that could be though.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1010465]
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (4)
As of 2017-10-23 23:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My fridge is mostly full of:

















    Results (285 votes). Check out past polls.

    Notices?