MooX::NewDefaults - Alter attribute defaults with less pain
version 0.001002
Concept and documentation liberally stolen from MooseX::NewDefaults
MooseX::NewDefaults
package One; use Moo; has A => (is => 'ro', default => sub { 'say ahhh' }); has B => (is => 'ro', default => sub { 'say whoo' }); package Two; use Moo; use MooX::NewDefaults; extends 'One'; # sugar for defining a new default default_for A => sub { 'say oooh' }; # this is also legal default_for B => 'say oooh';
Ever start using a package from the CPAN, only to discover that it requires lots of subclassing and has '+foo' => (default => ...)? It's not recommended Moose best practice, and it's certainly not the prettiest thing ever, either.
has '+foo' => (default => ...)
That's where we come in.
This package introduces new sugar that you can use in your class, default_for (as seen above).
default_for
e.g.
has '+foo' => (default => sub { 'a b c' });
...is the same as:
default_for foo => sub { 'a b c' };
default_for() is a shortcut to extend an attribute to give it a new default; this default value may be any legal value for default options.
# attribute bar defined elsewhere (e.g. superclass) default_for bar => 'new default';
... is the same as:
has '+bar' => (default => 'new default');
Kent Fredric <kentnl@cpan.org>
Chris Weyl <cweyl@alumni.drew.edu>
This software is Copyright (c) 2011 by Chris Weyl <cweyl@alumni.drew.edu>.
This is free software, licensed under:
The GNU Lesser General Public License, Version 2.1, February 1999
To install MooX::NewDefaults, copy and paste the appropriate command in to your terminal.
cpanm
cpanm MooX::NewDefaults
CPAN shell
perl -MCPAN -e shell install MooX::NewDefaults
For more information on module installation, please visit the detailed CPAN module installation guide.