line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# |
2
|
|
|
|
|
|
|
# This file is part of MooseX-Attribute-Deflator |
3
|
|
|
|
|
|
|
# |
4
|
|
|
|
|
|
|
# This software is Copyright (c) 2012 by Moritz Onken. |
5
|
|
|
|
|
|
|
# |
6
|
|
|
|
|
|
|
# This is free software, licensed under: |
7
|
|
|
|
|
|
|
# |
8
|
|
|
|
|
|
|
# The (three-clause) BSD License |
9
|
|
|
|
|
|
|
# |
10
|
|
|
|
|
|
|
package MooseX::Attribute::Deflator::Structured; |
11
|
|
|
|
|
|
|
{ |
12
|
|
|
|
|
|
|
$MooseX::Attribute::Deflator::Structured::VERSION = '2.1.11'; # TRIAL |
13
|
|
|
|
|
|
|
} |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
# ABSTRACT: Deflators for MooseX::Types::Structured |
16
|
|
|
|
|
|
|
|
17
|
1
|
|
|
1
|
|
1010691
|
use MooseX::Attribute::Deflator; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
4
|
|
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
deflate 'MooseX::Types::Structured::Optional[]', via { |
20
|
|
|
|
|
|
|
my ( $attr, $constraint, $deflate ) = @_; |
21
|
|
|
|
|
|
|
return $deflate->( $_, $constraint->type_parameter ); |
22
|
|
|
|
|
|
|
}, inline_as { |
23
|
|
|
|
|
|
|
my ( $attr, $constraint, $deflators ) = @_; |
24
|
|
|
|
|
|
|
return $deflators->( $constraint->type_parameter ); |
25
|
|
|
|
|
|
|
}; |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
inflate 'MooseX::Types::Structured::Optional[]', via { |
28
|
|
|
|
|
|
|
my ( $attr, $constraint, $inflate ) = @_; |
29
|
|
|
|
|
|
|
return $inflate->( $_, $constraint->type_parameter ); |
30
|
|
|
|
|
|
|
}, inline_as { |
31
|
|
|
|
|
|
|
my ( $attr, $constraint, $deflators ) = @_; |
32
|
|
|
|
|
|
|
return $deflators->( $constraint->type_parameter ); |
33
|
|
|
|
|
|
|
}; |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
deflate 'MooseX::Types::Structured::Map[]', via { |
36
|
|
|
|
|
|
|
my ( $attr, $constraint, $deflate ) = @_; |
37
|
|
|
|
|
|
|
my $value = {%$_}; |
38
|
|
|
|
|
|
|
my $constraints = $constraint->type_constraints; |
39
|
|
|
|
|
|
|
while ( my ( $k, $v ) = each %$value ) { |
40
|
|
|
|
|
|
|
$value->{$k} = $deflate->( $value->{$k}, $constraints->[1] ); |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
return $deflate->( $value, $constraint->parent ); |
43
|
|
|
|
|
|
|
}, inline_as { |
44
|
|
|
|
|
|
|
my ( $attr, $constraint, $deflators ) = @_; |
45
|
|
|
|
|
|
|
return ( |
46
|
|
|
|
|
|
|
'$value = {%$value};', |
47
|
|
|
|
|
|
|
'while ( my ( $k, $v ) = each %$value ) {', |
48
|
|
|
|
|
|
|
'$value->{$k} = do {', |
49
|
|
|
|
|
|
|
' my $value = $value->{$k};', |
50
|
|
|
|
|
|
|
' $value = do {', |
51
|
|
|
|
|
|
|
$deflators->( $constraint->type_constraints->[1] ), |
52
|
|
|
|
|
|
|
' };', |
53
|
|
|
|
|
|
|
' };', |
54
|
|
|
|
|
|
|
'}', |
55
|
|
|
|
|
|
|
$deflators->( $constraint->parent ), |
56
|
|
|
|
|
|
|
); |
57
|
|
|
|
|
|
|
}; |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
inflate 'MooseX::Types::Structured::Map[]', via { |
60
|
|
|
|
|
|
|
my ( $attr, $constraint, $inflate ) = @_; |
61
|
|
|
|
|
|
|
my $value = $inflate->( $_, $constraint->parent ); |
62
|
|
|
|
|
|
|
my $constraints = $constraint->type_constraints; |
63
|
|
|
|
|
|
|
while ( my ( $k, $v ) = each %$value ) { |
64
|
|
|
|
|
|
|
$value->{$k} = $inflate->( $value->{$k}, $constraints->[1] ); |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
return $value; |
67
|
|
|
|
|
|
|
}, inline_as { |
68
|
|
|
|
|
|
|
my ( $attr, $constraint, $deflators ) = @_; |
69
|
|
|
|
|
|
|
return ( |
70
|
|
|
|
|
|
|
'$value = do {', |
71
|
|
|
|
|
|
|
$deflators->( $constraint->parent ), |
72
|
|
|
|
|
|
|
' };', |
73
|
|
|
|
|
|
|
'while ( my ( $k, $v ) = each %$value ) {', |
74
|
|
|
|
|
|
|
' $value->{$k} = do {', |
75
|
|
|
|
|
|
|
' my $value = $value->{$k};', |
76
|
|
|
|
|
|
|
' $value = do {', |
77
|
|
|
|
|
|
|
$deflators->( $constraint->type_constraints->[1] ), |
78
|
|
|
|
|
|
|
' };', |
79
|
|
|
|
|
|
|
' };', |
80
|
|
|
|
|
|
|
'}', |
81
|
|
|
|
|
|
|
'$value', |
82
|
|
|
|
|
|
|
); |
83
|
|
|
|
|
|
|
}; |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
deflate 'MooseX::Types::Structured::Dict[]', via { |
86
|
|
|
|
|
|
|
my ( $attr, $constraint, $deflate ) = @_; |
87
|
|
|
|
|
|
|
my %constraints = @{ $constraint->type_constraints }; |
88
|
|
|
|
|
|
|
my $value = {%$_}; |
89
|
|
|
|
|
|
|
while ( my ( $k, $v ) = each %$value ) { |
90
|
|
|
|
|
|
|
$value->{$k} = $deflate->( $value->{$k}, $constraints{$k} ); |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
return $deflate->( $value, $constraint->parent ); |
93
|
|
|
|
|
|
|
}, inline_as { |
94
|
|
|
|
|
|
|
my ( $attr, $constraint, $deflators ) = @_; |
95
|
|
|
|
|
|
|
my %constraints = @{ $constraint->type_constraints }; |
96
|
|
|
|
|
|
|
my @map = 'my $dict;'; |
97
|
|
|
|
|
|
|
while ( my ( $k, $v ) = each %constraints ) { |
98
|
|
|
|
|
|
|
push( @map, |
99
|
|
|
|
|
|
|
'$dict->{"' . quotemeta($k) . '"} = sub { ', |
100
|
|
|
|
|
|
|
'my $value = shift;', |
101
|
|
|
|
|
|
|
$deflators->($v), ' };' ); |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
return ( |
104
|
|
|
|
|
|
|
@map, |
105
|
|
|
|
|
|
|
'$value = {%$value};', |
106
|
|
|
|
|
|
|
'while ( my ( $k, $v ) = each %$value ) {', |
107
|
|
|
|
|
|
|
'$value->{$k} = do {', |
108
|
|
|
|
|
|
|
' my $value = $value->{$k};', |
109
|
|
|
|
|
|
|
' $value = $dict->{$k}->($value);', |
110
|
|
|
|
|
|
|
' };', |
111
|
|
|
|
|
|
|
'}', |
112
|
|
|
|
|
|
|
$deflators->( $constraint->parent ), |
113
|
|
|
|
|
|
|
); |
114
|
|
|
|
|
|
|
}; |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
inflate 'MooseX::Types::Structured::Dict[]', via { |
117
|
|
|
|
|
|
|
my ( $attr, $constraint, $inflate ) = @_; |
118
|
|
|
|
|
|
|
my %constraints = @{ $constraint->type_constraints }; |
119
|
|
|
|
|
|
|
my $value = $inflate->( $_, $constraint->parent ); |
120
|
|
|
|
|
|
|
while ( my ( $k, $v ) = each %$value ) { |
121
|
|
|
|
|
|
|
$value->{$k} = $inflate->( $value->{$k}, $constraints{$k} ); |
122
|
|
|
|
|
|
|
} |
123
|
|
|
|
|
|
|
return $value; |
124
|
|
|
|
|
|
|
}, inline_as { |
125
|
|
|
|
|
|
|
my ( $attr, $constraint, $deflators ) = @_; |
126
|
|
|
|
|
|
|
my %constraints = @{ $constraint->type_constraints }; |
127
|
|
|
|
|
|
|
my @map = 'my $dict;'; |
128
|
|
|
|
|
|
|
while ( my ( $k, $v ) = each %constraints ) { |
129
|
|
|
|
|
|
|
push( @map, |
130
|
|
|
|
|
|
|
'$dict->{"' . quotemeta($k) . '"} = sub { ', |
131
|
|
|
|
|
|
|
'my $value = shift;', |
132
|
|
|
|
|
|
|
$deflators->($v), ' };' ); |
133
|
|
|
|
|
|
|
} |
134
|
|
|
|
|
|
|
return ( |
135
|
|
|
|
|
|
|
@map, |
136
|
|
|
|
|
|
|
'$value = do {', |
137
|
|
|
|
|
|
|
$deflators->( $constraint->parent ), |
138
|
|
|
|
|
|
|
' };', |
139
|
|
|
|
|
|
|
'while ( my ( $k, $v ) = each %$value ) {', |
140
|
|
|
|
|
|
|
'$value->{$k} = do {', |
141
|
|
|
|
|
|
|
' my $value = $value->{$k};', |
142
|
|
|
|
|
|
|
' $value = $dict->{$k}->($value);', |
143
|
|
|
|
|
|
|
' };', |
144
|
|
|
|
|
|
|
'}', |
145
|
|
|
|
|
|
|
'$value', |
146
|
|
|
|
|
|
|
); |
147
|
|
|
|
|
|
|
}; |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
deflate 'MooseX::Types::Structured::Tuple[]', via { |
150
|
|
|
|
|
|
|
my ( $attr, $constraint, $deflate ) = @_; |
151
|
|
|
|
|
|
|
my @constraints = @{ $constraint->type_constraints }; |
152
|
|
|
|
|
|
|
my $value = [@$_]; |
153
|
|
|
|
|
|
|
for ( my $i = 0; $i < @$value; $i++ ) { |
154
|
|
|
|
|
|
|
$value->[$i] = $deflate->( $value->[$i], |
155
|
|
|
|
|
|
|
$constraints[$i] || $constraints[-1] ); |
156
|
|
|
|
|
|
|
} |
157
|
|
|
|
|
|
|
return $deflate->( $value, $constraint->parent ); |
158
|
|
|
|
|
|
|
}, inline_as { |
159
|
|
|
|
|
|
|
my ( $attr, $constraint, $deflators ) = @_; |
160
|
|
|
|
|
|
|
my @constraints = @{ $constraint->type_constraints }; |
161
|
|
|
|
|
|
|
my @map = 'my $tuple = [];'; |
162
|
|
|
|
|
|
|
foreach my $tc (@constraints) { |
163
|
|
|
|
|
|
|
push( @map, |
164
|
|
|
|
|
|
|
'push(@$tuple, sub {', |
165
|
|
|
|
|
|
|
'my $value = shift;', |
166
|
|
|
|
|
|
|
$deflators->($tc), ' });' ); |
167
|
|
|
|
|
|
|
} |
168
|
|
|
|
|
|
|
return ( |
169
|
|
|
|
|
|
|
@map, |
170
|
|
|
|
|
|
|
'$value = [@$value];', |
171
|
|
|
|
|
|
|
'for ( my $i = 0; $i < @$value; $i++ ) {', |
172
|
|
|
|
|
|
|
'$value->[$i] = do {', |
173
|
|
|
|
|
|
|
' my $value = $value->[$i];', |
174
|
|
|
|
|
|
|
' $value = ($tuple->[$i] || $tuple->[-1])->($value);', |
175
|
|
|
|
|
|
|
' };', |
176
|
|
|
|
|
|
|
'}', |
177
|
|
|
|
|
|
|
$deflators->( $constraint->parent ), |
178
|
|
|
|
|
|
|
); |
179
|
|
|
|
|
|
|
}; |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
inflate 'MooseX::Types::Structured::Tuple[]', via { |
182
|
|
|
|
|
|
|
my ( $attr, $constraint, $inflate ) = @_; |
183
|
|
|
|
|
|
|
my @constraints = @{ $constraint->type_constraints }; |
184
|
|
|
|
|
|
|
my $value = $inflate->( $_, $constraint->parent ); |
185
|
|
|
|
|
|
|
for ( my $i = 0; $i < @$value; $i++ ) { |
186
|
|
|
|
|
|
|
$value->[$i] = $inflate->( $value->[$i], |
187
|
|
|
|
|
|
|
$constraints[$i] || $constraints[-1] ); |
188
|
|
|
|
|
|
|
} |
189
|
|
|
|
|
|
|
return $value; |
190
|
|
|
|
|
|
|
}, inline_as { |
191
|
|
|
|
|
|
|
my ( $attr, $constraint, $deflators ) = @_; |
192
|
|
|
|
|
|
|
my @constraints = @{ $constraint->type_constraints }; |
193
|
|
|
|
|
|
|
my @map = 'my $tuple = [];'; |
194
|
|
|
|
|
|
|
foreach my $tc (@constraints) { |
195
|
|
|
|
|
|
|
push( @map, |
196
|
|
|
|
|
|
|
'push(@$tuple, sub {', |
197
|
|
|
|
|
|
|
'my $value = shift;', |
198
|
|
|
|
|
|
|
$deflators->($tc), ' });' ); |
199
|
|
|
|
|
|
|
} |
200
|
|
|
|
|
|
|
return ( |
201
|
|
|
|
|
|
|
@map, |
202
|
|
|
|
|
|
|
'$value = do {', |
203
|
|
|
|
|
|
|
$deflators->( $constraint->parent ), |
204
|
|
|
|
|
|
|
' };', |
205
|
|
|
|
|
|
|
'for ( my $i = 0; $i < @$value; $i++ ) {', |
206
|
|
|
|
|
|
|
'$value->[$i] = do {', |
207
|
|
|
|
|
|
|
' my $value = $value->[$i];', |
208
|
|
|
|
|
|
|
' $value = ($tuple->[$i] || $tuple->[-1])->($value);', |
209
|
|
|
|
|
|
|
' };', |
210
|
|
|
|
|
|
|
'}', |
211
|
|
|
|
|
|
|
'$value', |
212
|
|
|
|
|
|
|
); |
213
|
|
|
|
|
|
|
}; |
214
|
|
|
|
|
|
|
|
215
|
|
|
|
|
|
|
1; |
216
|
|
|
|
|
|
|
|
217
|
|
|
|
|
|
|
|
218
|
|
|
|
|
|
|
|
219
|
|
|
|
|
|
|
=pod |
220
|
|
|
|
|
|
|
|
221
|
|
|
|
|
|
|
=head1 NAME |
222
|
|
|
|
|
|
|
|
223
|
|
|
|
|
|
|
MooseX::Attribute::Deflator::Structured - Deflators for MooseX::Types::Structured |
224
|
|
|
|
|
|
|
|
225
|
|
|
|
|
|
|
=head1 VERSION |
226
|
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
version 2.1.11 |
228
|
|
|
|
|
|
|
|
229
|
|
|
|
|
|
|
=head1 SYNOPSIS |
230
|
|
|
|
|
|
|
|
231
|
|
|
|
|
|
|
use MooseX::Attribute::Deflator::Structured; |
232
|
|
|
|
|
|
|
|
233
|
|
|
|
|
|
|
=head1 DESCRIPTION |
234
|
|
|
|
|
|
|
|
235
|
|
|
|
|
|
|
This module registers sane type deflators and inflators for L<MooseX::Types::Structured>. |
236
|
|
|
|
|
|
|
|
237
|
|
|
|
|
|
|
=head1 AUTHOR |
238
|
|
|
|
|
|
|
|
239
|
|
|
|
|
|
|
Moritz Onken |
240
|
|
|
|
|
|
|
|
241
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
242
|
|
|
|
|
|
|
|
243
|
|
|
|
|
|
|
This software is Copyright (c) 2012 by Moritz Onken. |
244
|
|
|
|
|
|
|
|
245
|
|
|
|
|
|
|
This is free software, licensed under: |
246
|
|
|
|
|
|
|
|
247
|
|
|
|
|
|
|
The (three-clause) BSD License |
248
|
|
|
|
|
|
|
|
249
|
|
|
|
|
|
|
=cut |
250
|
|
|
|
|
|
|
|
251
|
|
|
|
|
|
|
|
252
|
|
|
|
|
|
|
__END__ |
253
|
|
|
|
|
|
|
|