MooseX::Has::Options - Succinct options for Moose
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.
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
has 'some_attribute', ':required';
has 'some_attribute', required => 1;
bare are treated differently:
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
bare will be disabled for such functions.
Peter Shangov <firstname.lastname@example.org>
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.