-
-
12 Jul 2009 23:36:33 UTC
- Distribution: MooseX-Attributes-Curried
- Module version: 0.03
- Source (raw)
- Browse (raw)
- Changes
- Homepage
- How to Contribute
- Repository
- Issues
- Testers (843 / 0 / 0)
- Kwalitee
Bus factor: 1- % Coverage
- License: perl_5
- Activity
24 month- Tools
- Download (17.66KB)
- MetaCPAN Explorer
- Permissions
- Subscribe to distribution
- Permalinks
- This version
- Latest version
and 1 contributors-
Shawn M Moore, C
- Dependencies
- Moose
- Sub::Exporter
- and possibly others
- Reverse dependencies
- CPAN Testers List
- Dependency graph
NAME
MooseX::Attributes::Curried - curry your "has"es
SYNOPSIS
package MyAttrs; use MooseX::Attributes::Curried ( has_datetime => { isa => 'DateTime', default => sub { DateTime->now }, }, has_rw => { is => 'rw', }, ); package My::Class; use Moose; use MyAttrs; has_datetime 'birthday' => ( is => 'ro', ); has_rw 'age' => ( isa => 'Int', );
DESCRIPTION
This module lets you define curried versions of "has" in Moose. If many of your attributes share the same options, especially across multiple classes, then you can refactor those options away into a curried
has
.Typical usage of this extension is to create a standalone "
has
library" module. If you only need a curriedhas
for one class, then you might as well just define asub has_datetime { has(...) }
in that class.When you use your "
has
library", you can customize each curriedhas
further by specifying additional options on your import line, like so:use MyAttrs ( has_datetime => { is => 'ro', }, has_datetime => { -as => 'needs_datetime', required => 1, }, );
Your "defaults" for the attribute can also be a code reference. This code reference will receive both the additional specializations performed when the curried attribute was imported, as well as any additional specializations used in the individual attribute. This is immensely powerful, see t/007-smart-has.t for a taste.
SEE ALSO
MooseX::Attribute::Prototype, which has very similar goals; this extension was originally proposed as an implementation of prototype attributes.
AUTHOR
Shawn M Moore,
sartak@gmail.com
COPYRIGHT AND LICENSE
Copyright 2009 Shawn M Moore.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
Module Install Instructions
To install MooseX::Attributes::Curried, copy and paste the appropriate command in to your terminal.
cpanm MooseX::Attributes::Curried
perl -MCPAN -e shell install MooseX::Attributes::Curried
For more information on module installation, please visit the detailed CPAN module installation guide.