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