in reply to Re^4: Perl Moose syntax
in thread Perl Moose syntax

These are all exactly equivalent:

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

Moose has just chosen to write things the way they do, but you're free to choose any of the above, whichever is clearest to you - that's a lot of freedom! It's just a matter of taste, and arguing about it is just like arguing about whether your sandwich tastes better depending on if it's sliced diagonally, horizontally or vertically ;-)

Replies are listed 'Best First'.
Re^6: Perl Moose syntax
by choroba (Cardinal) on Dec 28, 2014 at 15:12 UTC
    Which is, by the way, exactly equivalent to
    has qw< friends is rw isa Array default >;
    لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ

      Just keeping it analogous to OP's example. Test code was this:

      $ perl -wMstrict -MData::Dump=pp sub has { print pp(@_),"\n" } has 'friends' => ( is => 'rw', isa => 'Array', default => () ); has friends => ((is => 'rw'), (isa => 'Array'), (default => ())); has friends => is => 'rw', isa => 'Array', default => (); has friends => is => rw => isa => Array => default => (); has "friends", "is", "rw", "isa", "Array", "default", (); has qw/friends is rw isa Array default/, (); __END__ ("friends", "is", "rw", "isa", "Array", "default") ("friends", "is", "rw", "isa", "Array", "default") ("friends", "is", "rw", "isa", "Array", "default") ("friends", "is", "rw", "isa", "Array", "default") ("friends", "is", "rw", "isa", "Array", "default") ("friends", "is", "rw", "isa", "Array", "default")