I started to migrate a couple of Perl modules to Moo but got stuck because the setter/writer can only have one single argument (can't it?). This also applies to coercing:
package MyThing:
use Moo;
use Scalar::Util qw(blessed);
use SomeOtherThing;
has foo => (
is => 'rw',
coerce => sub {
return $_[0] if blessed($_[0]) and $_[0]->isa('SomeOtherThing');
return SomeOtherThing->new( @_ ); # does not work, because @_ == 1
},
);
Here is a simple use case:
package MyApplication;
use MyThing;
$thing = MyThing->new;
$thing->foo( 'some', 'values'); # would like to have this shortcut
$thing->foo; # expected a SomeOtherThing
# must use this ugly form instead
$thing->foo( SomeOtherThing->new('some', 'values') );
Is there an easy way to implement accessors that support setting with multiple arguments?