README
1NAME
2 MooseX::Has::Options - Succinct options for Moose
3
4VERSION
5 version 0.003
6
7SYNOPSIS
8 use Moose;
9 use MooseX::Has::Options;
10
11 has 'some_attribute' => (
12 qw(:ro :required),
13 isa => 'Str',
14 ...
15 );
16
17 has 'another_attribute' => (
18 qw(:ro :lazy_build),
19 isa => 'Str',
20 ...
21 );
22
23DESCRIPTION
24 This module provides a succinct syntax for declaring options for Moose
25 attributes.
26
27USAGE
28 Declaring options
29 "MooseX::Has::Params" works by checking the arguments to "has" for
30 strings that look like options, i.e. alphanumeric strings preceded by a
31 colon, and replaces them with a hash whose keys are the names of the
32 options (sans the colon) and the values are 1's. Thus,
33
34 has 'some_attribute', ':required';
35
36 becomes:
37
38 has 'some_attribute', required => 1;
39
40 Options must come in the beginning of the argument list.
41 MooseX::Has::Options will stop searching for options after the first
42 alphanumeric string that does not start with a colon.
43
44 The default behaviour can be customised per attribute. For example, here
45 is how "ro", "rw" and "bare" work:
46
47 has 'some_attribute', ':ro';
48
49 becomes:
50
51 has 'some_attribute', is => 'ro';
52
53 See below for details.
54
55 Handlers
56 "MooseX::Has::Options" allows you to expand specific 'shortcut'
57 arguments to arbitrary values via the handler interface. A 'handler' is
58 a module in the MooseX::Has::Options::Handler namespace that provides a
59 "handler" function. The handler function should return a hash whose keys
60 are shortcut names, and the values are hashrefs with the values that the
61 respective shortcuts should be expanded to. In order to enable the
62 shortcuts supplied by a given handler you need to add it in the import
63 statement:
64
65 use MooseX::Has::Options qw(NativeTypes);
66
67 has 'some_attribute', qw(:ro :hash), default => sub {{ foo => bar }};
68
69 The following handlers ship with the default distribution:
70
71 * MooseX::Has::Options::Handler::Accessors (included by default when
72 you import this module)
73
74 * MooseX::Has::Options::Handler::NativeTypes
75
76 * MooseX::Has::Options::Handler::NoInit
77
78IMPLEMENTATION DETAILS
79 "MooseX::Has::Options" hijacks the "has" function imported by Moose and
80 replaces it with one that understands the options syntax described
81 above. This is not an optimal solution, but the current implementation
82 of "Moose::Meta::Attribute" prevents this functionality from being
83 provided as a meta trait.
84
85DEPRECATED BEHAVIOUR
86 Previous versions of "MooseX::Has::Params" allowed you to specify during
87 import the name of the function too hook into, like so:
88
89 use HTML::FormHandler::Moose;
90 use MooseX::Has::Options qw(has_field);
91
92 has_field 'name' => (
93 qw(:required),
94 type => 'Text',
95 );
96
97 This behaviour is deprecated as of version 0.003 as this syntax is now
98 used for specifying handlers. If you need to hook into a different
99 function see the implementation of "MooseX::Has::Options::import()" and
100 "MooseX::Has::Options::import_into()".
101
102SEE ALSO
103 * MooseX::Has::Sugar
104
105AUTHOR
106 Peter Shangov <pshangov@yahoo.com>
107
108COPYRIGHT AND LICENSE
109 This software is copyright (c) 2012 by Peter Shangov.
110
111 This is free software; you can redistribute it and/or modify it under
112 the same terms as the Perl 5 programming language system itself.
113
114