Skip Menu |

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

Report information
The Basics
Id: 111683
Status: open
Priority: 0/
Queue: MooseX-Role-Parameterized

People
Owner: Nobody in particular
Requestors: DROLSKY [...] cpan.org
Cc:
AdminCc:

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



Subject: Add a strict option for p-roles
It's nice to have an option to die on unknown parameters. We implemented this in an internal wrapper at $WORK using this code: package MM::MooseX::Role::Parameterized::Meta::Trait::Parameterizable::Strict; + +use MM::Moose::Role; + +with 'MooseX::Role::Parameterized::Meta::Trait::Parameterizable'; + +around construct_parameters => sub ($orig, $self, %params) { + my %attrs = ( + -alias => 1, + -excludes => 1, + ( + map { $_ => 1 } + grep { defined } + map { $_->init_arg } + $self->parameters_metaclass->get_all_attributes + ), + ); + + if ( my @bad = sort grep { !exists $attrs{$_} } keys %params ) { + die 'Found unknown parameter(s) passed to role: ' . join ', ', + @bad; + } + + return $self->$orig(%params); +}; + +1;
On 2016-2月-02 火 11:22:51, DROLSKY wrote: Show quoted text
> It's nice to have an option to die on unknown parameters. We > implemented this in an internal wrapper at $WORK using this code:
I'd love to have that in MXRP.
On Tue Feb 02 11:24:17 2016, SARTAK wrote: Show quoted text
> On 2016-2月-02 火 11:22:51, DROLSKY wrote:
> > It's nice to have an option to die on unknown parameters. We > > implemented this in an internal wrapper at $WORK using this code:
> > I'd love to have that in MXRP.
I think the only question is the API. Would "use MooseX::Role::Parameterized -strict" work? That should be very easy to implement.