Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Why Moose uses syntax like this:

has 'friends' => ( is => 'rw', isa => 'Array', default => () );

instead of using this syntax

has 'friends' => [ is => 'rw', isa => 'Array', default => () ];

I think the latter syntax does make more sense

Replies are listed 'Best First'.
Re: Perl Moose syntax
by choroba (Cardinal) on Dec 28, 2014 at 11:07 UTC
    Note the syntax for default:
    default => SCALAR | CODE
    Is () scalar or code?
    لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ
Re: Perl Moose syntax
by Anonymous Monk on Dec 28, 2014 at 03:12 UTC
    I think the latter syntax does make more sense

    Why?

      Because inside has subroutine you can assign value more clearly.
      like:

      my ($prop_name,$prop_options)=@_

        What's wrong with my ($prop_name,%prop_options) = @_;? Dereferencing a $prop_options would mean a bit more typing.

Re: Perl Moose syntax
by ambrus (Abbot) on Jan 16, 2015 at 08:45 UTC