Allow lvalue attributes in roles #1

Closed
doherty opened this Issue Aug 17, 2013 · 7 comments

Projects

None yet

2 participants

@doherty
doherty commented Aug 17, 2013

It's not clear why lvalue attributes are only allowed in classes. I'd like to give the consumers of my role an lvalue attribute, which I think makes sense. It'd be nice to have that supported, if possible.

@dams
Owner
dams commented Aug 17, 2013

I had some troubles making it work in roles, but I'll try to fix it. As soon as I get back from holiday, that is :)

@dams
Owner
dams commented Aug 21, 2013

fixed. Let me know if it doesn't work for you.

@dams dams closed this Aug 21, 2013
@doherty
doherty commented Aug 21, 2013

Sweet, thanks!

@dams
Owner
dams commented Aug 27, 2013

hi @doherty ,

@haarg pointed out to me that maybe what you had in mind with " I'd like to give the consumers of my role an lvalue attribute" was: "I should be able to define an lvalue attribute in the role", instead of what I originally understood: "when using MooX::LvalueAttribute in a Role, any class consuming it will get the MooX::LvalueAttribute behaviour".

In other words, in this code:

    package MyRole;
    use Moo::Role;
    use MooX::LvalueAttribute;

    has a1 => ( is => 'rw', lvalue => 1);

    package MyClass;
    use Moo;
    with ('MyRole');

    has a2 => ( is => 'rw', lvalue => 1);

    sub do_stuff { shift->a1 = 15 }
    sub doesnt_work { shift->a2 = 15 }

the attribute a1 will be lvalue, the attribute a2 won't. and do_stuff() will work.

I hope that's what you originally thought. Let me know :)

@dams dams reopened this Aug 27, 2013
@dams dams added a commit that referenced this issue Aug 27, 2013
@dams rewrite usage in Role to DWIM (issue #1 ) e89a7ef
@dams dams added a commit that referenced this issue Aug 27, 2013
@dams issue #1, fix documentation 3b5024e
@doherty
doherty commented Sep 27, 2013

@dams: Yes, the code example you provided illustrates what I meant more clearly.

@dams
Owner
dams commented Sep 27, 2013

@doherty Cool, then that's what's in the code now. Enjoy :)

@dams dams closed this Sep 27, 2013
@doherty
doherty commented Sep 28, 2013

Attributes of this sort exhibit a rather odd bug that I demonstrated here: doherty/MooX-LvalueAttribute@6ca819e

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment