Skip Menu |

This queue is for tickets about the MooseX-CustomInitArgs CPAN distribution.

Report information
The Basics
Id: 127163
Status: open
Priority: 0/
Queue: MooseX-CustomInitArgs

People
Owner: Nobody in particular
Requestors: swestrup [...] gmail.com
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



Subject: Feature Request.
Date: Fri, 21 Sep 2018 11:53:47 -0400
To: bug-MooseX-CustomInitArgs [...] rt.cpan.org
From: Stirling Westrup <swestrup [...] gmail.com>
I recently came across the MooseX::CustomInitArgs package, and it solves a problem I'm having, in that I have a number of boolean attributes in a constructor that I wish to support being set as negations. ie, I'll have the attributes 'foo', 'bar', and 'baz' as well as 'no-foo', 'no-bar', 'no-baz', which store into the same three values. It would be nice however if there were some way to provide a regex or other pattern so that I could write something like: has [qw(foo bar baz)] => ( is => 'rw', isa => 'Bool', default => 0, init_args => [ /^no-/ => sub { not $_ } ] ); Whether or not you think its worth putting in this feature I wish to thank you for the work you've already done, as its simplified my coding efforts already. -- Stirling Westrup Programmer, Entrepreneur. https://www.linkedin.com/e/fpf/77228 http://www.linkedin.com/in/swestrup http://technaut.livejournal.com http://sourceforge.net/users/stirlingwestrup
This seems already pretty easy to accomplish: for my $attr (qw(foo bar baz)) { has $attr => ( is => 'rw', isa => 'Bool', default => 0, init_args => [ "no-$attr" => sub { not $_ } ], ); } You can even do: my $default = ( foo => 1, bar => 0, baz => 0, ); for my $attr (qw(foo bar baz)) { has $attr => ( is => 'rw', isa => 'Bool', default => $default{$attr}, init_args => [ "no-$attr" => sub { not $_ } ], ); }