| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package MooseX::AttributeHelpers::MethodProvider::Hash; |
|
2
|
22
|
|
|
22
|
|
90
|
use Moose::Role; |
|
|
22
|
|
|
|
|
25
|
|
|
|
22
|
|
|
|
|
115
|
|
|
3
|
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
our $VERSION = '0.25'; |
|
5
|
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
with 'MooseX::AttributeHelpers::MethodProvider::ImmutableHash'; |
|
7
|
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
sub set : method { |
|
9
|
2
|
|
|
2
|
1
|
11
|
my ($attr, $reader, $writer) = @_; |
|
10
|
2
|
50
|
33
|
|
|
87
|
if ($attr->has_type_constraint && $attr->type_constraint->isa('Moose::Meta::TypeConstraint::Parameterized')) { |
|
11
|
2
|
|
|
|
|
121
|
my $container_type_constraint = $attr->type_constraint->type_parameter; |
|
12
|
|
|
|
|
|
|
return sub { |
|
13
|
10
|
|
|
10
|
|
6607
|
my ( $self, @kvp ) = @_; |
|
|
|
|
|
16
|
|
|
|
|
14
|
|
|
|
|
|
|
|
|
15
|
10
|
|
|
|
|
13
|
my ( @keys, @values ); |
|
16
|
|
|
|
|
|
|
|
|
17
|
10
|
|
|
|
|
26
|
while ( @kvp ) { |
|
18
|
14
|
|
|
|
|
23
|
my ( $key, $value ) = ( shift(@kvp), shift(@kvp) ); |
|
19
|
14
|
100
|
50
|
|
|
38
|
($container_type_constraint->check($value)) |
|
20
|
|
|
|
|
|
|
|| confess "Value " . ($value||'undef') . " did not pass container type constraint '$container_type_constraint'"; |
|
21
|
12
|
|
|
|
|
731
|
push @keys, $key; |
|
22
|
12
|
|
|
|
|
26
|
push @values, $value; |
|
23
|
|
|
|
|
|
|
} |
|
24
|
|
|
|
|
|
|
|
|
25
|
8
|
100
|
|
|
|
16
|
if ( @values > 1 ) { |
|
26
|
4
|
|
|
|
|
10
|
@{ $reader->($self) }{@keys} = @values; |
|
|
4
|
|
|
|
|
19
|
|
|
27
|
|
|
|
|
|
|
} else { |
|
28
|
4
|
|
|
|
|
15
|
$reader->($self)->{$keys[0]} = $values[0]; |
|
29
|
|
|
|
|
|
|
} |
|
30
|
2
|
|
|
|
|
75
|
}; |
|
31
|
|
|
|
|
|
|
} |
|
32
|
|
|
|
|
|
|
else { |
|
33
|
|
|
|
|
|
|
return sub { |
|
34
|
0
|
0
|
|
0
|
|
0
|
if ( @_ == 3 ) { |
|
35
|
0
|
|
|
|
|
0
|
$reader->($_[0])->{$_[1]} = $_[2] |
|
36
|
|
|
|
|
|
|
} else { |
|
37
|
0
|
|
|
|
|
0
|
my ( $self, @kvp ) = @_; |
|
38
|
0
|
|
|
|
|
0
|
my ( @keys, @values ); |
|
39
|
|
|
|
|
|
|
|
|
40
|
0
|
|
|
|
|
0
|
while ( @kvp ) { |
|
41
|
0
|
|
|
|
|
0
|
push @keys, shift @kvp; |
|
42
|
0
|
|
|
|
|
0
|
push @values, shift @kvp; |
|
43
|
|
|
|
|
|
|
} |
|
44
|
|
|
|
|
|
|
|
|
45
|
0
|
|
|
|
|
0
|
@{ $reader->($_[0]) }{@keys} = @values; |
|
|
0
|
|
|
|
|
0
|
|
|
46
|
|
|
|
|
|
|
} |
|
47
|
0
|
|
|
|
|
0
|
}; |
|
48
|
|
|
|
|
|
|
} |
|
49
|
|
|
|
|
|
|
} |
|
50
|
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
sub accessor : method { |
|
52
|
4
|
|
|
4
|
1
|
19
|
my ($attr, $reader, $writer) = @_; |
|
53
|
|
|
|
|
|
|
|
|
54
|
4
|
50
|
33
|
|
|
127
|
if ($attr->has_type_constraint && $attr->type_constraint->isa('Moose::Meta::TypeConstraint::Parameterized')) { |
|
55
|
4
|
|
|
|
|
233
|
my $container_type_constraint = $attr->type_constraint->type_parameter; |
|
56
|
|
|
|
|
|
|
return sub { |
|
57
|
7
|
|
|
7
|
|
45635
|
my $self = shift; |
|
58
|
|
|
|
|
|
|
|
|
59
|
7
|
100
|
|
|
|
25
|
if (@_ == 1) { # reader |
|
|
|
100
|
|
|
|
|
|
|
60
|
2
|
|
|
|
|
10
|
return $reader->($self)->{$_[0]}; |
|
61
|
|
|
|
|
|
|
} |
|
62
|
|
|
|
|
|
|
elsif (@_ == 2) { # writer |
|
63
|
2
|
50
|
0
|
|
|
9
|
($container_type_constraint->check($_[1])) |
|
64
|
|
|
|
|
|
|
|| confess "Value " . ($_[1]||'undef') . " did not pass container type constraint '$container_type_constraint'"; |
|
65
|
2
|
|
|
|
|
158
|
$reader->($self)->{$_[0]} = $_[1]; |
|
66
|
|
|
|
|
|
|
} |
|
67
|
|
|
|
|
|
|
else { |
|
68
|
3
|
|
|
|
|
42
|
confess "One or two arguments expected, not " . @_; |
|
69
|
|
|
|
|
|
|
} |
|
70
|
4
|
|
|
|
|
150
|
}; |
|
71
|
|
|
|
|
|
|
} |
|
72
|
|
|
|
|
|
|
else { |
|
73
|
|
|
|
|
|
|
return sub { |
|
74
|
0
|
|
|
7
|
|
0
|
my $self = shift; |
|
75
|
|
|
|
|
|
|
|
|
76
|
0
|
0
|
|
|
|
0
|
if (@_ == 1) { # reader |
|
|
|
0
|
|
|
|
|
|
|
77
|
0
|
|
|
|
|
0
|
return $reader->($self)->{$_[0]}; |
|
78
|
|
|
|
|
|
|
} |
|
79
|
|
|
|
|
|
|
elsif (@_ == 2) { # writer |
|
80
|
0
|
|
|
|
|
0
|
$reader->($self)->{$_[0]} = $_[1]; |
|
81
|
|
|
|
|
|
|
} |
|
82
|
|
|
|
|
|
|
else { |
|
83
|
0
|
|
|
|
|
0
|
confess "One or two arguments expected, not " . @_; |
|
84
|
|
|
|
|
|
|
} |
|
85
|
0
|
|
|
|
|
0
|
}; |
|
86
|
|
|
|
|
|
|
} |
|
87
|
|
|
|
|
|
|
} |
|
88
|
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
sub clear : method { |
|
90
|
2
|
|
|
2
|
1
|
11
|
my ($attr, $reader, $writer) = @_; |
|
91
|
2
|
|
|
2
|
|
12
|
return sub { %{$reader->($_[0])} = () }; |
|
|
2
|
|
|
|
|
1730
|
|
|
|
2
|
|
|
|
|
10
|
|
|
92
|
|
|
|
|
|
|
} |
|
93
|
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
sub delete : method { |
|
95
|
2
|
|
|
4
|
1
|
10
|
my ($attr, $reader, $writer) = @_; |
|
96
|
|
|
|
|
|
|
return sub { |
|
97
|
6
|
|
|
6
|
|
2075
|
my $hashref = $reader->(shift); |
|
98
|
6
|
|
|
|
|
139
|
CORE::delete @{$hashref}{@_}; |
|
|
6
|
|
|
|
|
22
|
|
|
99
|
2
|
|
|
|
|
11
|
}; |
|
100
|
|
|
|
|
|
|
} |
|
101
|
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
1; |
|
103
|
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
__END__ |
|
105
|
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
=pod |
|
107
|
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
=encoding UTF-8 |
|
109
|
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
=head1 NAME |
|
111
|
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
MooseX::AttributeHelpers::MethodProvider::Hash |
|
113
|
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
=head1 VERSION |
|
115
|
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
version 0.25 |
|
117
|
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
119
|
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
This is a role which provides the method generators for |
|
121
|
|
|
|
|
|
|
L<MooseX::AttributeHelpers::Collection::Hash>. |
|
122
|
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
This role is composed from the |
|
124
|
|
|
|
|
|
|
L<MooseX::AttributeHelpers::Collection::ImmutableHash> role. |
|
125
|
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
=head1 METHODS |
|
127
|
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
=over 4 |
|
129
|
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
=item B<meta> |
|
131
|
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
=back |
|
133
|
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
=head1 PROVIDED METHODS |
|
135
|
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
=over 4 |
|
137
|
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
=item B<count> |
|
139
|
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
Returns the number of elements in the hash. |
|
141
|
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
=item B<delete> |
|
143
|
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
Removes the element with the given key |
|
145
|
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
=item B<defined> |
|
147
|
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
Returns true if the value of a given key is defined |
|
149
|
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
=item B<empty> |
|
151
|
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
If the list is populated, returns true. Otherwise, returns false. |
|
153
|
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
=item B<clear> |
|
155
|
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
Unsets the hash entirely. |
|
157
|
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
=item B<exists> |
|
159
|
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
Returns true if the given key is present in the hash |
|
161
|
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
=item B<get> |
|
163
|
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
Returns an element of the hash by its key. |
|
165
|
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
=item B<keys> |
|
167
|
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
Returns the list of keys in the hash. |
|
169
|
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
=item B<set> |
|
171
|
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
Sets the element in the hash at the given key to the given value. |
|
173
|
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
=item B<values> |
|
175
|
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
Returns the list of values in the hash. |
|
177
|
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
=item B<kv> |
|
179
|
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
Returns the key, value pairs in the hash |
|
181
|
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
=item B<accessor> |
|
183
|
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
If passed one argument, returns the value of the requested key. If passed two |
|
185
|
|
|
|
|
|
|
arguments, sets the value of the requested key. |
|
186
|
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
=back |
|
188
|
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
=head1 SUPPORT |
|
190
|
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
Bugs may be submitted through L<the RT bug tracker|https://rt.cpan.org/Public/Dist/Display.html?Name=MooseX-AttributeHelpers> |
|
192
|
|
|
|
|
|
|
(or L<bug-MooseX-AttributeHelpers@rt.cpan.org|mailto:bug-MooseX-AttributeHelpers@rt.cpan.org>). |
|
193
|
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
There is also a mailing list available for users of this distribution, at |
|
195
|
|
|
|
|
|
|
L<http://lists.perl.org/list/moose.html>. |
|
196
|
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
There is also an irc channel available for users of this distribution, at |
|
198
|
|
|
|
|
|
|
L<C<#moose> on C<irc.perl.org>|irc://irc.perl.org/#moose>. |
|
199
|
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
=head1 AUTHOR |
|
201
|
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
Stevan Little <stevan@iinteractive.com> |
|
203
|
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
|
205
|
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
This software is copyright (c) 2007 by Stevan Little and Infinity Interactive, Inc. |
|
207
|
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
|
209
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
|
210
|
|
|
|
|
|
|
|
|
211
|
|
|
|
|
|
|
=cut |