Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Allow lvalue attributes in roles #1

Closed
doherty opened this Issue · 7 comments

2 participants

@doherty

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

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

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

@dams dams closed this
@doherty

Sweet, thanks!

@dams
Owner

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
@dams dams referenced this issue from a commit
@dams issue #1, fix documentation 3b5024e
@doherty

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

@dams
Owner

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

@dams dams closed this
@doherty

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
Something went wrong with that request. Please try again.