NAME
MooseX::NewDefaults - Alter attribute defaults with less pain
VERSION
version 0.002
SYNOPSIS
package One;
use Moose;
use namespace::autoclean;
has A => (is => 'ro', default => sub { 'say ahhh' });
has B => (is => 'ro', default => sub { 'say whoo' });
package Two;
use Moose;
use namespace::autoclean;
use MooseX::NewDefaults;
# sugar for defining a new default
default_for A => sub { 'say oooh' };
# this is also legal
default_for B => 'say oooh';
DESCRIPTION
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 certanly not the prettiest thing ever, either.
That's where we come in.
This package introduces new sugar that you can use in the baseclass, default_for (as seen above).
e.g.
has '+foo' => (default => sub { 'a b c' });
...is the same as:
default_for foo => sub { 'a b c' };
NEW SUGAR
default_for
This package exports one function, default_for(). This is shorthand sugar to give an attribute defined in a superclass a new default; it expects the name of an attribute and a legal value to be used as the new default.
BUGS
All complex software has bugs lurking in it, and this module is no exception.
Bugs, feature requests and pull requests through GitHub are most welcome; our page and repo (same URI):
https://github.com/RsrchBoy/moosex-newdefaults
AUTHOR
Chris Weyl <cweyl@alumni.drew.edu>
COPYRIGHT AND LICENSE
This software is Copyright (c) 2011 by Chris Weyl.
This is free software, licensed under:
The GNU Lesser General Public License, Version 2.1, February 1999