Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a 'OneArgNew' trait #5

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

Add a 'OneArgNew' trait #5

wants to merge 2 commits into from

Conversation

yanick
Copy link

@yanick yanick commented Oct 22, 2016

A variation on the theme that does away with giving
the type and init arg attribute name in
the with, but rather lifts it straight from the
attribute's declaration.

The additional code doesn't change anything at all (and doesn't interact)
with the role, so this could be released as an independent
MooseX::OneArgNew::AsTrait. If you prefer me to do that, just say the word.
I just thought that offering the two options in the same distribution
wouldn't be the worst thing ever. :-)

A variation on the theme that does away with giving
the type and init arg attribute name in
the `with`, but rather lifts it straight from the
attribute's declaration.

The additional code doesn't change anything at all (and doesn't interact)
with the role, so this could be released as an independent
MooseX::OneArgNew::AsTrait. If you prefer me to do that, just say the word.
I just thought that offering the two options in the same distribution
wouldn't be the worst thing ever. :-)
@rjbs
Copy link
Owner

rjbs commented Oct 25, 2016

I like the trait idea, but not that you could apply it to more than one attribute. I think it will lead to more confusion than it's worth at some point. Also, can the ordering be guaranteed to work as described when attributes in the class come from multiple different roles?

I'd apply it with exclusivity: more than one attribute with this trait in a class is fatal…

…but is that really possible? With subclassing, I bet it can't be nicely guaranteed. What do you think?

@yanick
Copy link
Author

yanick commented Oct 25, 2016

While I see the appeal of having different attributes that can get the trait, I concede that this might lead to crazy-town real fast.

I think the "only one" rule can be enforced: when meddling with the class in attach_to_class, we can also snoop and see if there's already another attribute there with the trait. If there is, we holler and die.

@yanick
Copy link
Author

yanick commented Oct 25, 2016

I just pushed the changes required to only accept one attribute with the OneArgNew trait.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants