line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
2
|
|
|
2
|
|
2816
|
use 5.006; # pragmas, qr |
|
2
|
|
|
|
|
7
|
|
|
2
|
|
|
|
|
85
|
|
2
|
2
|
|
|
2
|
|
11
|
use warnings; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
60
|
|
3
|
2
|
|
|
2
|
|
12
|
use strict; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
142
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
package MooseX::Has::Sugar; |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $VERSION = '1.000004'; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
# ABSTRACT: Sugar Syntax for moose 'has' fields |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
our $AUTHORITY = 'cpan:KENTNL'; # AUTHORITY |
12
|
|
|
|
|
|
|
|
13
|
2
|
|
|
2
|
|
13
|
use Carp (); |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
209
|
|
14
|
|
|
|
|
|
|
use Sub::Exporter::Progressive ( |
15
|
2
|
|
|
|
|
109
|
-setup => { |
16
|
|
|
|
|
|
|
exports => [ 'ro', 'rw', 'required', 'lazy', 'lazy_build', 'coerce', 'weak_ref', 'auto_deref', 'bare', ], |
17
|
|
|
|
|
|
|
groups => { |
18
|
|
|
|
|
|
|
isattrs => [ 'ro', 'rw', 'bare', ], |
19
|
|
|
|
|
|
|
attrs => [ 'required', 'lazy', 'lazy_build', 'coerce', 'weak_ref', 'auto_deref', ], |
20
|
|
|
|
|
|
|
default => [ 'ro', 'rw', 'bare', 'required', 'lazy', 'lazy_build', 'coerce', 'weak_ref', 'auto_deref', ], |
21
|
|
|
|
|
|
|
}, |
22
|
|
|
|
|
|
|
}, |
23
|
2
|
|
|
2
|
|
965
|
); |
|
2
|
|
|
|
|
1241
|
|
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub bare() { |
32
|
1
|
|
|
1
|
1
|
745
|
return ( 'is', 'bare' ); |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub ro() { |
42
|
2
|
|
|
2
|
1
|
2564
|
return ( 'is', 'ro' ); |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
sub rw() { |
52
|
1
|
|
|
1
|
1
|
706
|
return ( 'is', 'rw' ); |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
sub required() { |
62
|
5
|
|
|
5
|
1
|
1465
|
return ( 'required', 1 ); |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
sub lazy() { |
72
|
5
|
|
|
5
|
1
|
22
|
return ( 'lazy', 1 ); |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
sub lazy_build() { |
82
|
5
|
|
|
5
|
1
|
18
|
return ( 'lazy_build', 1 ); |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
sub weak_ref() { |
92
|
5
|
|
|
5
|
1
|
15
|
return ( 'weak_ref', 1 ); |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
sub coerce() { |
104
|
5
|
|
|
5
|
1
|
17
|
return ( 'coerce', 1 ); |
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
sub auto_deref() { |
114
|
5
|
|
|
5
|
1
|
51
|
return ( 'auto_deref', 1 ); |
115
|
|
|
|
|
|
|
} |
116
|
|
|
|
|
|
|
1; |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
__END__ |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
=pod |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
=encoding UTF-8 |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
=head1 NAME |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
MooseX::Has::Sugar - Sugar Syntax for moose 'has' fields |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
=head1 VERSION |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
version 1.000004 |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
=head1 SYNOPSIS |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
L<Moose|Moose> C<has> syntax is generally fine, but sometimes one gets bothered with |
135
|
|
|
|
|
|
|
the constant typing of string quotes for things. L<The MooseX::Types module|MooseX::Types> exists and in |
136
|
|
|
|
|
|
|
many ways reduces the need for constant string creation. |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
=head2 Primary Benefits at a Glance |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
=head3 Reduced Typing in C<has> declarations. |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
The constant need to type C<=E<gt>> and C<''> is fine for one-off cases, but |
143
|
|
|
|
|
|
|
the instant you have more than about 4 attributes it starts to get annoying. |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
=head3 More compact declarations. |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
Reduces much of the redundant typing in most cases, which makes your life easier, |
148
|
|
|
|
|
|
|
and makes it take up less visual space, which makes it faster to read. |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
=head3 No String Worries |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
Strings are often problematic, due to white-space etc. Noted that if you do |
153
|
|
|
|
|
|
|
happen to mess them up, Moose should at I<least> warn you that you've done |
154
|
|
|
|
|
|
|
something daft. Using this alleviates that worry. |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
=head2 Before this Module. |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
=head3 Classical Moose |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
has foo => ( |
161
|
|
|
|
|
|
|
isa => 'Str', |
162
|
|
|
|
|
|
|
is => 'ro', |
163
|
|
|
|
|
|
|
required => 1, |
164
|
|
|
|
|
|
|
); |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
has bar => ( |
167
|
|
|
|
|
|
|
isa => 'Str', |
168
|
|
|
|
|
|
|
is => 'rw' |
169
|
|
|
|
|
|
|
lazy_build => 1, |
170
|
|
|
|
|
|
|
); |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
=head3 Lazy Evil way to do it: |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
B<PLEASE DO NOT DO THIS> |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
has qw( foo isa Str is ro required 1 ); |
177
|
|
|
|
|
|
|
has qw( bar isa Str is rw lazy_build 1 ); |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
=head2 With this module |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
( and with MooseX::Types ) |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
use MooseX::Types::Moose qw( Str ); |
184
|
|
|
|
|
|
|
use MooseX::Has::Sugar; |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
has foo => ( |
187
|
|
|
|
|
|
|
isa => Str, |
188
|
|
|
|
|
|
|
ro, |
189
|
|
|
|
|
|
|
required, |
190
|
|
|
|
|
|
|
); |
191
|
|
|
|
|
|
|
has bar => ( |
192
|
|
|
|
|
|
|
isa => Str, |
193
|
|
|
|
|
|
|
rw, |
194
|
|
|
|
|
|
|
lazy_build, |
195
|
|
|
|
|
|
|
); |
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
Or even |
198
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
use MooseX::Types::Moose qw( Str ); |
200
|
|
|
|
|
|
|
use MooseX::Has::Sugar; |
201
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
has foo => ( isa => Str, ro, required, ); |
203
|
|
|
|
|
|
|
has bar => ( isa => Str, rw, lazy_build, ); |
204
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
=head2 Alternative Forms |
206
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
=head3 Basic C<is> Expansion Only |
208
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
( using L<::Sugar::Minimal|MooseX::Has::Sugar::Minimal> instead ) |
210
|
|
|
|
|
|
|
|
211
|
|
|
|
|
|
|
use MooseX::Types::Moose qw( Str ); |
212
|
|
|
|
|
|
|
use MooseX::Has::Sugar::Minimal; |
213
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
has foo => ( |
215
|
|
|
|
|
|
|
isa => Str, |
216
|
|
|
|
|
|
|
is => ro, |
217
|
|
|
|
|
|
|
required => 1, |
218
|
|
|
|
|
|
|
); |
219
|
|
|
|
|
|
|
has bar => ( |
220
|
|
|
|
|
|
|
isa => Str, |
221
|
|
|
|
|
|
|
is => rw, |
222
|
|
|
|
|
|
|
lazy_build => 1, |
223
|
|
|
|
|
|
|
); |
224
|
|
|
|
|
|
|
|
225
|
|
|
|
|
|
|
=head3 Attribute Expansions with Basic Expansions |
226
|
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
( Combining parts of this and L<::Sugar::Minimal|MooseX::Has::Sugar::Minimal> ) |
228
|
|
|
|
|
|
|
|
229
|
|
|
|
|
|
|
use MooseX::Types::Moose qw( Str ); |
230
|
|
|
|
|
|
|
use MooseX::Has::Sugar::Minimal; |
231
|
|
|
|
|
|
|
use MooseX::Has::Sugar qw( :attrs ); |
232
|
|
|
|
|
|
|
|
233
|
|
|
|
|
|
|
has foo => ( |
234
|
|
|
|
|
|
|
isa => Str, |
235
|
|
|
|
|
|
|
is => ro, |
236
|
|
|
|
|
|
|
required, |
237
|
|
|
|
|
|
|
); |
238
|
|
|
|
|
|
|
has bar => ( |
239
|
|
|
|
|
|
|
isa => Str, |
240
|
|
|
|
|
|
|
is => rw, |
241
|
|
|
|
|
|
|
lazy_build, |
242
|
|
|
|
|
|
|
); |
243
|
|
|
|
|
|
|
|
244
|
|
|
|
|
|
|
=head1 EXPORT GROUPS |
245
|
|
|
|
|
|
|
|
246
|
|
|
|
|
|
|
=head2 C<:default> |
247
|
|
|
|
|
|
|
|
248
|
|
|
|
|
|
|
Since 0.0300, this exports all our syntax, the same as C<:attrs> C<:isattrs>. |
249
|
|
|
|
|
|
|
Primarily because I found you generally want all the sugar, not just part of it. |
250
|
|
|
|
|
|
|
This also gets rid of that nasty exclusion logic. |
251
|
|
|
|
|
|
|
|
252
|
|
|
|
|
|
|
=head2 C<:isattrs> |
253
|
|
|
|
|
|
|
|
254
|
|
|
|
|
|
|
This exports C<ro>, C<rw> and C<bare> as lists, so they behave as stand-alone attributes like |
255
|
|
|
|
|
|
|
L</lazy> does. |
256
|
|
|
|
|
|
|
|
257
|
|
|
|
|
|
|
has foo => ( |
258
|
|
|
|
|
|
|
required, |
259
|
|
|
|
|
|
|
isa => 'Str', |
260
|
|
|
|
|
|
|
ro, |
261
|
|
|
|
|
|
|
); |
262
|
|
|
|
|
|
|
|
263
|
|
|
|
|
|
|
B<NOTE: This option is incompatible with L<::Sugar::Minimal|MooseX::Has::Sugar::Minimal>> : L</CONFLICTS> |
264
|
|
|
|
|
|
|
|
265
|
|
|
|
|
|
|
=head2 C<:attrs> |
266
|
|
|
|
|
|
|
|
267
|
|
|
|
|
|
|
This exports L</lazy> , L</lazy_build> and L</required>, L</coerce>, L</weak_ref> |
268
|
|
|
|
|
|
|
and L</auto_deref> as subs that assume positive. |
269
|
|
|
|
|
|
|
|
270
|
|
|
|
|
|
|
has foo => ( |
271
|
|
|
|
|
|
|
required, |
272
|
|
|
|
|
|
|
isa => 'Str', |
273
|
|
|
|
|
|
|
); |
274
|
|
|
|
|
|
|
|
275
|
|
|
|
|
|
|
B<NOTE: This option is incompatible with L<MooseX::Types|MooseX::Types> and L<Moose's Type Constraints Module|Moose::Util::TypeConstraints>> : L</CONFLICTS> |
276
|
|
|
|
|
|
|
|
277
|
|
|
|
|
|
|
=head2 C<:is> |
278
|
|
|
|
|
|
|
|
279
|
|
|
|
|
|
|
B<DEPRECATED>. See L<::Sugar::Minimal|MooseX::Has::Sugar::Minimal> for the same functionality |
280
|
|
|
|
|
|
|
|
281
|
|
|
|
|
|
|
=head2 C<:allattrs> |
282
|
|
|
|
|
|
|
|
283
|
|
|
|
|
|
|
B<DEPRECATED>, just use L</:default> or do |
284
|
|
|
|
|
|
|
|
285
|
|
|
|
|
|
|
use MooseX::Has::Sugar; |
286
|
|
|
|
|
|
|
|
287
|
|
|
|
|
|
|
=head1 EXPORTED FUNCTIONS |
288
|
|
|
|
|
|
|
|
289
|
|
|
|
|
|
|
=head2 C<bare> |
290
|
|
|
|
|
|
|
|
291
|
|
|
|
|
|
|
returns C<('is','bare')> |
292
|
|
|
|
|
|
|
|
293
|
|
|
|
|
|
|
=head2 C<ro> |
294
|
|
|
|
|
|
|
|
295
|
|
|
|
|
|
|
returns C<('is','ro')> |
296
|
|
|
|
|
|
|
|
297
|
|
|
|
|
|
|
=head2 C<rw> |
298
|
|
|
|
|
|
|
|
299
|
|
|
|
|
|
|
returns C<('is','rw')> |
300
|
|
|
|
|
|
|
|
301
|
|
|
|
|
|
|
=head2 C<required> |
302
|
|
|
|
|
|
|
|
303
|
|
|
|
|
|
|
returns C<('required',1)> |
304
|
|
|
|
|
|
|
|
305
|
|
|
|
|
|
|
=head2 C<lazy> |
306
|
|
|
|
|
|
|
|
307
|
|
|
|
|
|
|
returns C<('lazy',1)> |
308
|
|
|
|
|
|
|
|
309
|
|
|
|
|
|
|
=head2 C<lazy_build> |
310
|
|
|
|
|
|
|
|
311
|
|
|
|
|
|
|
returns C<('lazy_build',1)> |
312
|
|
|
|
|
|
|
|
313
|
|
|
|
|
|
|
=head2 C<weak_ref> |
314
|
|
|
|
|
|
|
|
315
|
|
|
|
|
|
|
returns C<('weak_ref',1)> |
316
|
|
|
|
|
|
|
|
317
|
|
|
|
|
|
|
=head2 C<coerce> |
318
|
|
|
|
|
|
|
|
319
|
|
|
|
|
|
|
returns C<('coerce',1)> |
320
|
|
|
|
|
|
|
|
321
|
|
|
|
|
|
|
B<WARNING:> Conflict with L<MooseX::Types|MooseX::Types> and L<Moose::Util::TypeConstraints|Moose::Util::TypeConstraints>, see L</CONFLICTS>. |
322
|
|
|
|
|
|
|
|
323
|
|
|
|
|
|
|
=head2 C<auto_deref> |
324
|
|
|
|
|
|
|
|
325
|
|
|
|
|
|
|
returns C<('auto_deref',1)> |
326
|
|
|
|
|
|
|
|
327
|
|
|
|
|
|
|
=head1 CONFLICTS |
328
|
|
|
|
|
|
|
|
329
|
|
|
|
|
|
|
=head2 MooseX::Has::Sugar::Minimal |
330
|
|
|
|
|
|
|
|
331
|
|
|
|
|
|
|
=head2 MooseX::Has::Sugar::Saccharin |
332
|
|
|
|
|
|
|
|
333
|
|
|
|
|
|
|
This module is not intended to be used in conjunction with |
334
|
|
|
|
|
|
|
L<::Sugar::Minimal|MooseX::Has::Sugar::Minimal> or L<::Sugar::Saccharin|MooseX::Has::Sugar::Saccharin> |
335
|
|
|
|
|
|
|
|
336
|
|
|
|
|
|
|
We export many of the same symbols and its just not very sensible. |
337
|
|
|
|
|
|
|
|
338
|
|
|
|
|
|
|
=head2 MooseX::Types |
339
|
|
|
|
|
|
|
|
340
|
|
|
|
|
|
|
=head2 Moose::Util::TypeConstraints |
341
|
|
|
|
|
|
|
|
342
|
|
|
|
|
|
|
due to exporting the L</coerce> symbol, using us in the same scope as a call to |
343
|
|
|
|
|
|
|
|
344
|
|
|
|
|
|
|
use MooseX::Types .... |
345
|
|
|
|
|
|
|
|
346
|
|
|
|
|
|
|
or |
347
|
|
|
|
|
|
|
use Moose::Util::TypeConstraints |
348
|
|
|
|
|
|
|
|
349
|
|
|
|
|
|
|
will result in a symbol collision. |
350
|
|
|
|
|
|
|
|
351
|
|
|
|
|
|
|
We recommend using and creating proper type libraries instead, ( which will absolve you entirely of the need to use MooseX::Types and MooseX::Has::Sugar(::*)? in the same scope ) |
352
|
|
|
|
|
|
|
|
353
|
|
|
|
|
|
|
=head1 AUTHOR |
354
|
|
|
|
|
|
|
|
355
|
|
|
|
|
|
|
Kent Fredric <kentnl at cpan.org> |
356
|
|
|
|
|
|
|
|
357
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
358
|
|
|
|
|
|
|
|
359
|
|
|
|
|
|
|
This software is copyright (c) 2014 by Kent Fredric. |
360
|
|
|
|
|
|
|
|
361
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
362
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
363
|
|
|
|
|
|
|
|
364
|
|
|
|
|
|
|
=cut |