Subject: | Moo should provide a public function to turn arguments into canonical form |
The default behavior of Moo is to turn (foo => 'bar') into { foo =>
'bar' } through the default BUILDARGS in Moo::Object. Users of
distributions based on Moo probably get used to being able to write
->new(foo => 'bar') or ->new({ foo => 'bar' }) at their convenience, so
it makes sense to be able to do that with regular methods as well.
As soon as you start writing custom BUILDARGS methods though, or using
parameter validation modules, you need to replicate this functionality
by hand (or in the case of a custom BUILDARGS, you can try running
SUPER::BUILDARGS but that's iffy at best since it relies on
implementation details).
A better alternative would be to have something like:
use Moo qw/canonicalize_arguments/;
sub reticulate_splines {
my $self = shift;
my $params = canonicalize_arguments(@_);
# now reticulate your splines, confident in the fact that whatever
# the user passed, $params is a hashref
}
except with a function name that doesn't suck.