An open API service indexing awesome lists of open source software.

https://github.com/rsrchboy/moosex-newdefaults

Alter attribute defaults with less pain
https://github.com/rsrchboy/moosex-newdefaults

Last synced: 4 months ago
JSON representation

Alter attribute defaults with less pain

Awesome Lists containing this project

README

        

[![Build Status](https://travis-ci.org/RsrchBoy/moosex-newdefaults.svg?branch=master)](https://travis-ci.org/RsrchBoy/moosex-newdefaults)
[![Kwalitee status](http://cpants.cpanauthors.org/dist/MooseX-NewDefaults.png)](http://cpants.charsbar.org/dist/overview/MooseX-NewDefaults)

# NAME

MooseX::NewDefaults - Alter attribute defaults with less pain

# VERSION

This document describes version 0.005 of MooseX::NewDefaults - released April 24, 2015 as part of MooseX-NewDefaults.

# 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;

extends 'One';

# 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 certainly not the prettiest thing
ever, either.

That's where we come in.

This package introduces new sugar that you can use in your class,
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

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');

# SOURCE

The development version is on github at [http://https://github.com/RsrchBoy/moosex-newdefaults](http://https://github.com/RsrchBoy/moosex-newdefaults)
and may be cloned from [git://https://github.com/RsrchBoy/moosex-newdefaults.git](git://https://github.com/RsrchBoy/moosex-newdefaults.git)

# BUGS

Please report any bugs or feature requests on the bugtracker website
https://github.com/RsrchBoy/moosex-newdefaults/issues

When submitting a bug or request, please include a test-file or a
patch to an existing test-file that illustrates the bug or desired
feature.

# AUTHOR

Chris Weyl

## I'm a material boy in a material world





Please note **I do not expect to be gittip'ed or flattr'ed for this work**,
rather **it is simply a very pleasant surprise**. I largely create and release
works like this because I need them or I find it enjoyable; however, don't let
that stop you if you feel like it ;)

[Flattr this](https://flattr.com/submit/auto?user_id=RsrchBoy&url=https%3A%2F%2Fgithub.com%2FRsrchBoy%2Fmoosex-newdefaults&title=RsrchBoy's%20CPAN%20MooseX-NewDefaults&tags=%22RsrchBoy's%20MooseX-NewDefaults%20in%20the%20CPAN%22),
[gittip me](https://www.gittip.com/RsrchBoy/), or indulge my
[Amazon Wishlist](http://bit.ly/rsrchboys-wishlist)... If you so desire.

# 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