Re: check arguments for ->new
[email protected] ("Ian Sillitoe")
| Newsgroups | perl.moose |
|---|---|
| Message-ID | <[email protected]> |
http://search.cpan.org/~drolsky/MooseX-StrictConstructor-0.07/lib/MooseX/StrictConstructor.pm
package My::Class;
use Moose;
use MooseX::StrictConstructor;
has 'size' => ...;
# then later ...
# this blows up because color is not a known attribute
My::Class->new( size => 5, color => 'blue' );
Cheers
Ian
2008/11/26 Jozef Kutej <[email protected]>
> Hi,
>
> is there a way how to check and throw an exception if an argument passed to
> constructor of Moose based class has no equivalent accessor?
>
> Example:
>
> --- cut ---
>
> package MyClass;
> use Moose;
> has 'colour' => ('is' => 'rw', 'isa' => 'Str');
> 1;
>
> package main;
> MyClass->new('color' => '#123456'); # should throw exception
>
> --- cut ---
>
> Thank you,
> Jozef
>