MooseX::Has::Options - Succinct options for Moose
version 0.002
use Moose; use MooseX::Has::Options; has 'some_attribute' => ( qw(:ro :required), isa => 'Str', ... ); has 'another_attribute' => ( qw(:ro :lazy_build), isa => 'Str', ... );
This module provides a succinct syntax for declaring options for Moose attributes. It hijacks the has function imported by Moose and replaces it with one that understands the options syntax described above.
has
MooseX::Has::Params works by checking the arguments to has for strings that look like options, i.e. alphanumeric strings preceded by a colon, and replaces them with a hash whose keys are the names of the options (sans the colon) and the values are 1's. Thus,
1
has 'some_attribute', ':required';
becomes:
has 'some_attribute', required => 1;
The options ro, rw and bare are treated differently:
ro
rw
bare
has 'some_attribute', ':ro';
has 'some_attribute', is => 'ro';
Options must come in the beginning of the argument list. MooseX::Has::Options will stop searching for options after the first alphanumeric string that does not start with a colon.
MooseX::Has::Params hooks into a has function that already exists in your module's namespace. Therefore it must be imported after Moose. A side effect of this is that it will work with any module that provides a has function, e.g. Mouse.
If you specify arguments when importing MooseX::Has::Params, it will hook to these functions instead. Use this to change the behavior of functions that provide a syntax similar to Moose attributes:
use HTML::FormHandler::Moose; use MooseX::Has::Options qw(has_field); has_field 'name' => ( qw(:required), type => 'Text', );
The special treatment of ro, rw and bare will be disabled for such functions.
MooseX::Has::Sugar
Peter Shangov <pshangov@yahoo.com>
This software is copyright (c) 2011 by Peter Shangov.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
To install MooseX::Has::Options, copy and paste the appropriate command in to your terminal.
cpanm
cpanm MooseX::Has::Options
CPAN shell
perl -MCPAN -e shell install MooseX::Has::Options
For more information on module installation, please visit the detailed CPAN module installation guide.