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::Moose; |
11
|
|
|
|
|
|
|
{ |
12
|
|
|
|
|
|
|
$MooseX::Attribute::Deflator::Moose::VERSION = '2.1.11'; # TRIAL |
13
|
|
|
|
|
|
|
} |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
# ABSTRACT: Deflators for Moose type constraints |
16
|
|
|
|
|
|
|
|
17
|
5
|
|
|
5
|
|
654585
|
use MooseX::Attribute::Deflator; |
|
5
|
|
|
|
|
8
|
|
|
5
|
|
|
|
|
27
|
|
18
|
5
|
|
|
5
|
|
4918
|
use JSON; |
|
5
|
|
|
|
|
35640
|
|
|
5
|
|
|
|
|
25
|
|
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
deflate [qw(ArrayRef HashRef)], via { JSON::encode_json($_) }, |
21
|
|
|
|
|
|
|
inline_as {'JSON::encode_json($value)'}; |
22
|
|
|
|
|
|
|
inflate [qw(ArrayRef HashRef)], via { JSON::decode_json($_) }, |
23
|
|
|
|
|
|
|
inline_as {'JSON::decode_json($value)'}; |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
deflate 'ScalarRef', via {$$_}, inline_as {'$$value'}; |
26
|
|
|
|
|
|
|
inflate 'ScalarRef', via { \$_ }, inline_as {'\$value'}; |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
deflate 'Bool', via { $_ ? JSON::true : JSON::false }, |
29
|
|
|
|
|
|
|
inline_as {'$value ? JSON::true : JSON::false'}; |
30
|
|
|
|
|
|
|
inflate 'Bool', via { $_ ? 1 : 0 }, inline_as {'$value ? 1 : 0'}; |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
deflate 'Item', via {$_}, inline_as {'$value'}; |
33
|
|
|
|
|
|
|
inflate 'Item', via {$_}, inline_as {'$value'}; |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
deflate 'HashRef[]', via { |
36
|
|
|
|
|
|
|
my ( $attr, $constraint, $deflate ) = @_; |
37
|
|
|
|
|
|
|
my $value = {%$_}; |
38
|
|
|
|
|
|
|
while ( my ( $k, $v ) = each %$value ) { |
39
|
|
|
|
|
|
|
$value->{$k} |
40
|
|
|
|
|
|
|
= $deflate->( $value->{$k}, $constraint->type_parameter ); |
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_parameter ), |
52
|
|
|
|
|
|
|
' };', |
53
|
|
|
|
|
|
|
' };', |
54
|
|
|
|
|
|
|
'}', |
55
|
|
|
|
|
|
|
$deflators->( $constraint->parent ), |
56
|
|
|
|
|
|
|
); |
57
|
|
|
|
|
|
|
}; |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
inflate 'HashRef[]', via { |
60
|
|
|
|
|
|
|
my ( $attr, $constraint, $inflate ) = @_; |
61
|
|
|
|
|
|
|
my $value = $inflate->( $_, $constraint->parent ); |
62
|
|
|
|
|
|
|
while ( my ( $k, $v ) = each %$value ) { |
63
|
|
|
|
|
|
|
$value->{$k} |
64
|
|
|
|
|
|
|
= $inflate->( $value->{$k}, $constraint->type_parameter ); |
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_parameter ), |
78
|
|
|
|
|
|
|
' };', |
79
|
|
|
|
|
|
|
' };', |
80
|
|
|
|
|
|
|
'}', |
81
|
|
|
|
|
|
|
'$value', |
82
|
|
|
|
|
|
|
); |
83
|
|
|
|
|
|
|
}; |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
deflate 'ArrayRef[]', via { |
86
|
|
|
|
|
|
|
my ( $attr, $constraint, $deflate ) = @_; |
87
|
|
|
|
|
|
|
my $value = [@$_]; |
88
|
|
|
|
|
|
|
$_ = $deflate->( $_, $constraint->type_parameter ) for (@$value); |
89
|
|
|
|
|
|
|
return $deflate->( $value, $constraint->parent ); |
90
|
|
|
|
|
|
|
}, inline_as { |
91
|
|
|
|
|
|
|
my ( $attr, $constraint, $deflators ) = @_; |
92
|
|
|
|
|
|
|
return ( |
93
|
|
|
|
|
|
|
'$value = [@$value];', |
94
|
|
|
|
|
|
|
'for( @$value ) {', |
95
|
|
|
|
|
|
|
' $_ = do {', |
96
|
|
|
|
|
|
|
' my $value = $_;', |
97
|
|
|
|
|
|
|
' $value = do {', |
98
|
|
|
|
|
|
|
$deflators->( $constraint->type_parameter ), |
99
|
|
|
|
|
|
|
' };', |
100
|
|
|
|
|
|
|
' };', |
101
|
|
|
|
|
|
|
'}', |
102
|
|
|
|
|
|
|
$deflators->( $constraint->parent ), |
103
|
|
|
|
|
|
|
); |
104
|
|
|
|
|
|
|
}; |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
inflate 'ArrayRef[]', via { |
107
|
|
|
|
|
|
|
my ( $attr, $constraint, $inflate ) = @_; |
108
|
|
|
|
|
|
|
my $value = $inflate->( $_, $constraint->parent ); |
109
|
|
|
|
|
|
|
$_ = $inflate->( $_, $constraint->type_parameter ) for (@$value); |
110
|
|
|
|
|
|
|
return $value; |
111
|
|
|
|
|
|
|
}, inline_as { |
112
|
|
|
|
|
|
|
my ( $attr, $constraint, $deflators ) = @_; |
113
|
|
|
|
|
|
|
return ( |
114
|
|
|
|
|
|
|
'$value = do {', |
115
|
|
|
|
|
|
|
$deflators->( $constraint->parent ), |
116
|
|
|
|
|
|
|
' };', |
117
|
|
|
|
|
|
|
'for( @$value ) {', |
118
|
|
|
|
|
|
|
' $_ = do {', |
119
|
|
|
|
|
|
|
' my $value = $_;', |
120
|
|
|
|
|
|
|
' $value = do {', |
121
|
|
|
|
|
|
|
$deflators->( $constraint->type_parameter ), |
122
|
|
|
|
|
|
|
' };', |
123
|
|
|
|
|
|
|
' };', |
124
|
|
|
|
|
|
|
'}', |
125
|
|
|
|
|
|
|
'$value', |
126
|
|
|
|
|
|
|
); |
127
|
|
|
|
|
|
|
}; |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
deflate 'Maybe[]', via { |
130
|
|
|
|
|
|
|
my ( $attr, $constraint, $deflate ) = @_; |
131
|
|
|
|
|
|
|
return $deflate->( $_, $constraint->type_parameter ); |
132
|
|
|
|
|
|
|
}, inline_as { |
133
|
|
|
|
|
|
|
my ( $attr, $constraint, $deflators ) = @_; |
134
|
|
|
|
|
|
|
return $deflators->( $constraint->type_parameter ); |
135
|
|
|
|
|
|
|
}; |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
inflate 'Maybe[]', via { |
138
|
|
|
|
|
|
|
my ( $attr, $constraint, $inflate ) = @_; |
139
|
|
|
|
|
|
|
return $inflate->( $_, $constraint->type_parameter ); |
140
|
|
|
|
|
|
|
}, inline_as { |
141
|
|
|
|
|
|
|
my ( $attr, $constraint, $deflators ) = @_; |
142
|
|
|
|
|
|
|
return $deflators->( $constraint->type_parameter ); |
143
|
|
|
|
|
|
|
}; |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
deflate 'ScalarRef[]', via { |
146
|
|
|
|
|
|
|
my ( $attr, $constraint, $deflate ) = @_; |
147
|
|
|
|
|
|
|
return ${ $deflate->( $_, $constraint->type_parameter ) }; |
148
|
|
|
|
|
|
|
}, inline_as { |
149
|
|
|
|
|
|
|
my ( $attr, $constraint, $deflators ) = @_; |
150
|
|
|
|
|
|
|
my $parameter = $deflators->( $constraint->type_parameter ); |
151
|
|
|
|
|
|
|
return ( '$value = do {', $parameter, '};', '$$value' ); |
152
|
|
|
|
|
|
|
}; |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
inflate 'ScalarRef[]', via { |
155
|
|
|
|
|
|
|
my ( $attr, $constraint, $inflate ) = @_; |
156
|
|
|
|
|
|
|
return \$inflate->( $_, $constraint->type_parameter ); |
157
|
|
|
|
|
|
|
}, inline_as { |
158
|
|
|
|
|
|
|
my ( $attr, $constraint, $deflators ) = @_; |
159
|
|
|
|
|
|
|
my $parameter = $deflators->( $constraint->type_parameter ); |
160
|
|
|
|
|
|
|
return ( '$value = do {', $parameter, '};', '\$value' ); |
161
|
|
|
|
|
|
|
}; |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
1; |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
=pod |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
=head1 NAME |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
MooseX::Attribute::Deflator::Moose - Deflators for Moose type constraints |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
=head1 VERSION |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
version 2.1.11 |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
=head1 SYNOPSIS |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
use MooseX::Attribute::Deflator::Moose; |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
=head1 DESCRIPTION |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
Using this module registers sane type deflators and inflators for Moose's built in types. |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
Some notes: |
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
=over |
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
=item * HashRef and ArrayRef deflate/inflate using JSON |
190
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
=item * ScalarRef is dereferenced on deflation and returns a reference on inflation |
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
=back |
194
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
=head1 AUTHOR |
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
Moritz Onken |
198
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
200
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
This software is Copyright (c) 2012 by Moritz Onken. |
202
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
This is free software, licensed under: |
204
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
The (three-clause) BSD License |
206
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
=cut |
208
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
__END__ |
211
|
|
|
|
|
|
|
|