line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
1
|
|
|
1
|
|
406252
|
use 5.008; |
|
1
|
|
|
|
|
4
|
|
2
|
1
|
|
|
1
|
|
5
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
25
|
|
3
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
55
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
package MooseX::AttributeTags; |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $AUTHORITY = 'cpan:TOBYINK'; |
8
|
|
|
|
|
|
|
our $VERSION = '0.004'; |
9
|
|
|
|
|
|
|
|
10
|
1
|
|
|
1
|
|
5
|
use Carp; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
73
|
|
11
|
1
|
|
|
1
|
|
6
|
use Data::OptList qw(mkopt); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
8
|
|
12
|
1
|
|
|
1
|
|
93
|
use Scalar::Util qw(blessed); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
178
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
my $yah = 1; # avoid exported subs becoming constants |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub import |
17
|
|
|
|
|
|
|
{ |
18
|
1
|
|
|
1
|
|
13
|
my $caller = caller; |
19
|
1
|
|
|
|
|
2
|
my $class = shift; |
20
|
1
|
|
|
|
|
5
|
my $opts = mkopt(\@_); |
21
|
1
|
|
|
|
|
55
|
my $prole = $class->_prole; |
22
|
|
|
|
|
|
|
|
23
|
1
|
|
|
|
|
11
|
for (@$opts) |
24
|
|
|
|
|
|
|
{ |
25
|
3
|
|
|
|
|
10
|
my ($traitname, $traitdesc) = @$_; |
26
|
3
|
|
100
|
|
|
13
|
$traitdesc ||= []; |
27
|
3
|
50
|
|
|
|
12
|
ref($traitdesc) eq 'ARRAY' |
28
|
|
|
|
|
|
|
or croak("Expected arrayref, not $traitdesc; stopped"); |
29
|
|
|
|
|
|
|
|
30
|
3
|
|
|
|
|
5
|
my %attrs; |
31
|
3
|
|
|
|
|
11
|
my $inner_opts = mkopt($traitdesc); |
32
|
3
|
|
|
|
|
114
|
for (@$inner_opts) |
33
|
|
|
|
|
|
|
{ |
34
|
4
|
|
|
|
|
9
|
my ($attrname, $attrdesc) = @$_; |
35
|
4
|
|
|
|
|
12
|
$attrs{$attrname} = $class->_canonicalize_attribute_spec($attrdesc); |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
3
|
|
|
|
|
13
|
my $traitqname = sprintf('%s::%s', $caller, $traitname); |
39
|
3
|
|
|
|
|
14
|
my $trait = $prole->generate_role( |
40
|
|
|
|
|
|
|
package => $traitqname, |
41
|
|
|
|
|
|
|
parameters => { attributes => \%attrs }, |
42
|
|
|
|
|
|
|
); |
43
|
|
|
|
|
|
|
|
44
|
1
|
|
|
1
|
|
6
|
no strict 'refs'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
190
|
|
45
|
3
|
50
|
|
5
|
|
2599
|
*$traitqname = sub () { $traitqname if $yah }; |
|
5
|
|
|
|
|
52296
|
|
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub _prole |
50
|
|
|
|
|
|
|
{ |
51
|
1
|
|
|
1
|
|
295
|
require MooseX::AttributeTags::PRole; |
52
|
1
|
|
|
|
|
5
|
Class::MOP::class_of('MooseX::AttributeTags::PRole'); |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub _canonicalize_attribute_spec |
56
|
|
|
|
|
|
|
{ |
57
|
4
|
|
|
4
|
|
9
|
shift; |
58
|
4
|
|
|
|
|
6
|
my $spec = $_[0]; |
59
|
|
|
|
|
|
|
|
60
|
4
|
50
|
|
|
|
11
|
return [ is => 'ro' ] |
61
|
|
|
|
|
|
|
unless defined $spec; |
62
|
|
|
|
|
|
|
|
63
|
4
|
100
|
|
|
|
14
|
return $spec |
64
|
|
|
|
|
|
|
if ref $spec eq 'ARRAY'; |
65
|
|
|
|
|
|
|
|
66
|
1
|
50
|
|
|
|
4
|
return [ %$spec ] |
67
|
|
|
|
|
|
|
if ref $spec eq 'HASH'; |
68
|
|
|
|
|
|
|
|
69
|
1
|
50
|
|
|
|
10
|
return [ is => 'ro', lazy => 1, default => $spec ] |
70
|
|
|
|
|
|
|
if ref $spec eq 'CODE'; |
71
|
|
|
|
|
|
|
|
72
|
0
|
0
|
0
|
|
|
|
return [ is => 'ro', isa => $spec ] |
73
|
|
|
|
|
|
|
if blessed($spec) && $spec->isa('Moose::Meta::TypeConstraint'); |
74
|
|
|
|
|
|
|
|
75
|
0
|
|
|
|
|
|
croak("Expected coderef/arrayref/hashref/constraint, not $spec; stopped"); |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
1; |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
__END__ |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
=pod |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
=encoding utf-8 |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
=head1 NAME |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
MooseX::AttributeTags - tag your Moose attributes |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
=head1 SYNOPSIS |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
package User; |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
use Moose; |
95
|
|
|
|
|
|
|
use MooseX::Types::Moose 'Bool'; |
96
|
|
|
|
|
|
|
use MooseX::AttributeTags ( |
97
|
|
|
|
|
|
|
SerializationStyle => [ |
98
|
|
|
|
|
|
|
hidden => Bool, |
99
|
|
|
|
|
|
|
], |
100
|
|
|
|
|
|
|
); |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
has username => ( |
103
|
|
|
|
|
|
|
traits => [ SerializationStyle ], |
104
|
|
|
|
|
|
|
is => 'ro', |
105
|
|
|
|
|
|
|
hidden => 0, |
106
|
|
|
|
|
|
|
); |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
has password => ( |
109
|
|
|
|
|
|
|
traits => [ SerializationStyle ], |
110
|
|
|
|
|
|
|
is => 'rw', |
111
|
|
|
|
|
|
|
hidden => 1, |
112
|
|
|
|
|
|
|
); |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
=head1 DESCRIPTION |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
MooseX::AttributeTags is a factory for attribute traits. All the work is |
117
|
|
|
|
|
|
|
done in the import method. |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
=head2 Methods |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
=over |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
=item C<< import(@optlist) >> |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
The option list is a list of trait names to create (which will be exported |
126
|
|
|
|
|
|
|
to the caller package as constants). |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
Each trait name may be optionally followed by an arrayref of attributes to |
129
|
|
|
|
|
|
|
be created within the trait. (In the SYNOPSIS, the "SerializationStyle" trait |
130
|
|
|
|
|
|
|
gets an attribute called "hidden".) |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
Each attribute may be optionally followed by I<one> of: |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
=over |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
=item * |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
A coderef which provides a default value for the attribute. |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
=item * |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
A type constraint object (such as those provided by Types::Standard or |
143
|
|
|
|
|
|
|
MooseX::Types; not a type constraint string) to validate the attribute. |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
=item * |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
An arrayref or hashref providing options similar to those given to |
148
|
|
|
|
|
|
|
Moose's C<has> keyword. |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
=back |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
=back |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
=head1 BUGS |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
Please report any bugs to |
157
|
|
|
|
|
|
|
L<http://rt.cpan.org/Dist/Display.html?Queue=MooseX-AttributeTags>. |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
=head1 SEE ALSO |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
L<Moose>. |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
=head1 AUTHOR |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
Toby Inkster E<lt>tobyink@cpan.orgE<gt>. |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENCE |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
This software is copyright (c) 2013, 2017 by Toby Inkster. |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
172
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
=head1 DISCLAIMER OF WARRANTIES |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED |
177
|
|
|
|
|
|
|
WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF |
178
|
|
|
|
|
|
|
MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
179
|
|
|
|
|
|
|
|