Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
Moo uses code like this to add an attribute to a class:
has taste => (is => 'ro',);That's too much typing for lazy people. So applying the standard rules: 'parentheses don't really do anything so you can delete them', 'fat commas are really just commas', leads to this:
has 'taste', 'is', 'ro';Well there's no point typing in that comma separated list is there? Why not use qw? This works:
has qw/weight is rw default 100/;MooseX::MungeHas allows has to haz defaults:
use MooseX::MungeHas 'is_rw'; has foo => ();
Using the 'standard rules' this becomes:
has 'foo'; # works okayBut then to create a read-only attribute, it needs to be specified:
has roattr => (is => 'ro');Is there a way to make hasro and hasrw functions to add attributes? Maybe there's a module that does this and i just haven't found it yet?
hasrw 'weight'; # read-write hasro 'roattr'; # read-only
Then if somebody was verrry lazy, they can easily define their classes without having to type a bunch of parentheses, fat commas, and typing in 'is' over and over again. Obviously this wouldn't be suitable for all uses.
|
|---|