-
Notifications
You must be signed in to change notification settings - Fork 4
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
Possible to have a :required attribute? #5
Comments
This seems like a reasonable request. Attributes could be made non-required by explicitly specifying |
Would this require changes to MooseX::MungeHas to support this? |
That would be the simplest way to implement it, yes. |
Released a new MooseX::MungeHas. |
Wow! That was fast :) |
It was only a few lines of code. The test cases were more work than the implementation. Moops just needs this now: use v5.14;
use strict;
use warnings FATAL => 'all';
no warnings qw(void once uninitialized numeric);
package Moops::TraitFor::Keyword::req;
our $AUTHORITY = 'cpan:TOBYINK';
our $VERSION = '0.036';
use Moo::Role;
around arguments_for_moosex_mungehas => sub {
my $next = shift;
my $self = shift;
require MooseX::MungeHas;
MooseX::MungeHas->VERSION('0.011');
return ('always_required', $self->$next(@_));
};
1; Once you've got that, you should be able to do:
I'll try to get it included in a release of Moops some time this month. If you wanted to write some test cases for it, that might help me get it released faster. t/94trait-ro-rw-rwp.t is pretty close to the kinds of tests you'd want to do. |
Thank you! I'm on vacation without my laptop now, but I will try to get to this soon to help you out :) |
Created pull request here: Sorry-- I'm not sure if there's a better way to link these. |
Also, if you don't mind, could you explain how
Works? It's returning ' |
push @lines, "use MooseX::MungeHas qw(@{[ $self->arguments_for_moosex_mungehas ]});"
if $using =~ /^Mo/; And Traits like |
Thank you for taking the time to explain this to me-- I'm trying to learn how Moops works and I appreciate it. One more follow up question, when you have multiple traits like |
Yep. That's just generally how |
Awesome, thank you :) Please let me know if you'd like any changes on the pull request :) |
Looks good to me. |
I find the :ro attribute super useful. I often want to use :ro and have all fields be required, too. Would it be possible to add this as an attribute?
The text was updated successfully, but these errors were encountered: