line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Toolforge::MixNMatch::Struct::Catalog; |
2
|
|
|
|
|
|
|
|
3
|
4
|
|
|
4
|
|
340661
|
use base qw(Exporter); |
|
4
|
|
|
|
|
33
|
|
|
4
|
|
|
|
|
563
|
|
4
|
4
|
|
|
4
|
|
33
|
use strict; |
|
4
|
|
|
|
|
10
|
|
|
4
|
|
|
|
|
88
|
|
5
|
4
|
|
|
4
|
|
22
|
use warnings; |
|
4
|
|
|
|
|
7
|
|
|
4
|
|
|
|
|
161
|
|
6
|
|
|
|
|
|
|
|
7
|
4
|
|
|
4
|
|
1511
|
use Error::Pure qw(err); |
|
4
|
|
|
|
|
36432
|
|
|
4
|
|
|
|
|
97
|
|
8
|
4
|
|
|
4
|
|
242
|
use Readonly; |
|
4
|
|
|
|
|
11
|
|
|
4
|
|
|
|
|
154
|
|
9
|
4
|
|
|
4
|
|
1621
|
use Toolforge::MixNMatch::Object::Catalog; |
|
4
|
|
|
|
|
15367
|
|
|
4
|
|
|
|
|
127
|
|
10
|
4
|
|
|
4
|
|
1829
|
use Toolforge::MixNMatch::Struct::User; |
|
4
|
|
|
|
|
12
|
|
|
4
|
|
|
|
|
170
|
|
11
|
4
|
|
|
4
|
|
1849
|
use Toolforge::MixNMatch::Struct::YearMonth; |
|
4
|
|
|
|
|
10
|
|
|
4
|
|
|
|
|
1691
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
Readonly::Array our @EXPORT_OK => qw(obj2struct struct2obj); |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
our $VERSION = 0.04; |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub obj2struct { |
18
|
4
|
|
|
4
|
1
|
22356
|
my $obj = shift; |
19
|
|
|
|
|
|
|
|
20
|
4
|
100
|
|
|
|
14
|
if (! defined $obj) { |
21
|
1
|
|
|
|
|
6
|
err "Object doesn't exist."; |
22
|
|
|
|
|
|
|
} |
23
|
3
|
100
|
|
|
|
22
|
if (! $obj->isa('Toolforge::MixNMatch::Object::Catalog')) { |
24
|
1
|
|
|
|
|
5
|
err "Object isn't 'Toolforge::MixNMatch::Object::Catalog'."; |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
|
27
|
2
|
|
|
|
|
8
|
my $struct_hr = { |
28
|
|
|
|
|
|
|
'type' => [{ |
29
|
|
|
|
|
|
|
'type' => $obj->type, |
30
|
|
|
|
|
|
|
'cnt' => $obj->count, |
31
|
|
|
|
|
|
|
}], |
32
|
|
|
|
|
|
|
'user' => [], |
33
|
|
|
|
|
|
|
'ym' => [], |
34
|
|
|
|
|
|
|
}; |
35
|
2
|
|
|
|
|
34
|
foreach my $year_month (@{$obj->year_months}) { |
|
2
|
|
|
|
|
7
|
|
36
|
2
|
|
|
|
|
12
|
push @{$struct_hr->{'ym'}}, |
|
2
|
|
|
|
|
8
|
|
37
|
|
|
|
|
|
|
Toolforge::MixNMatch::Struct::YearMonth::obj2struct($year_month); |
38
|
|
|
|
|
|
|
} |
39
|
2
|
|
|
|
|
18
|
foreach my $user (@{$obj->users}) { |
|
2
|
|
|
|
|
6
|
|
40
|
2
|
|
|
|
|
11
|
push @{$struct_hr->{'user'}}, |
|
2
|
|
|
|
|
7
|
|
41
|
|
|
|
|
|
|
Toolforge::MixNMatch::Struct::User::obj2struct($user); |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
2
|
|
|
|
|
15
|
return $struct_hr; |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
sub struct2obj { |
48
|
2
|
|
|
2
|
1
|
3033
|
my $struct_hr = shift; |
49
|
|
|
|
|
|
|
|
50
|
2
|
|
|
|
|
5
|
my $year_months = []; |
51
|
2
|
|
|
|
|
5
|
foreach my $year_month_hr (@{$struct_hr->{'ym'}}) { |
|
2
|
|
|
|
|
7
|
|
52
|
2
|
|
|
|
|
4
|
push @{$year_months}, Toolforge::MixNMatch::Struct::YearMonth::struct2obj($year_month_hr); |
|
2
|
|
|
|
|
10
|
|
53
|
|
|
|
|
|
|
} |
54
|
2
|
|
|
|
|
3
|
my $users = []; |
55
|
2
|
|
|
|
|
7
|
foreach my $user_hr (@{$struct_hr->{'user'}}) { |
|
2
|
|
|
|
|
6
|
|
56
|
2
|
|
|
|
|
4
|
push @{$users}, Toolforge::MixNMatch::Struct::User::struct2obj($user_hr); |
|
2
|
|
|
|
|
7
|
|
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
my $obj = Toolforge::MixNMatch::Object::Catalog->new( |
59
|
|
|
|
|
|
|
'count' => $struct_hr->{'type'}->[0]->{'cnt'}, |
60
|
2
|
|
|
|
|
13
|
'type' => $struct_hr->{'type'}->[0]->{'type'}, |
61
|
|
|
|
|
|
|
'users' => $users, |
62
|
|
|
|
|
|
|
'year_months' => $year_months, |
63
|
|
|
|
|
|
|
); |
64
|
|
|
|
|
|
|
|
65
|
2
|
|
|
|
|
204
|
return $obj; |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
1; |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
__END__ |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
=pod |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
=encoding utf8 |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
=head1 NAME |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
Toolforge::MixNMatch::Struct::Catalog - Mix'n'match catalog structure serialization. |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
=head1 SYNOPSIS |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
use Toolforge::MixNMatch::Struct::Catalog qw(obj2struct struct2obj); |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
my $struct_hr = obj2struct($obj); |
85
|
|
|
|
|
|
|
my $obj = struct2obj($struct_hr); |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=head1 DESCRIPTION |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
This conversion is between object defined in Toolforge::MixNMatch::Object::Catalog and structure |
90
|
|
|
|
|
|
|
serialized via JSON to Mix'n'match application. |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
=head1 SUBROUTINES |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
=head2 C<obj2struct> |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
my $struct_hr = obj2struct($obj); |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
Convert Toolforge::MixNMatch::Object::Catalog instance to structure. |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
Returns reference to hash with structure. |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
=head2 C<struct2obj> |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
my $obj = struct2obj($struct_hr); |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
Convert structure of time to object. |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
Returns Toolforge::MixNMatch::Object::Catalog instance. |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
=head1 ERRORS |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
obj2struct(): |
113
|
|
|
|
|
|
|
Object doesn't exist. |
114
|
|
|
|
|
|
|
Object isn't 'Toolforge::MixNMatch::Object::Catalog'. |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
=head1 EXAMPLE1 |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
use strict; |
119
|
|
|
|
|
|
|
use warnings; |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
use Data::Printer; |
122
|
|
|
|
|
|
|
use Toolforge::MixNMatch::Object::Catalog; |
123
|
|
|
|
|
|
|
use Toolforge::MixNMatch::Struct::Catalog qw(obj2struct); |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
# Object. |
126
|
|
|
|
|
|
|
my $obj = Toolforge::MixNMatch::Object::Catalog->new( |
127
|
|
|
|
|
|
|
'count' => 10, |
128
|
|
|
|
|
|
|
'type' => 'Q5', |
129
|
|
|
|
|
|
|
'users' => [ |
130
|
|
|
|
|
|
|
Toolforge::MixNMatch::Object::User->new( |
131
|
|
|
|
|
|
|
'count' => 6, |
132
|
|
|
|
|
|
|
'uid' => 1, |
133
|
|
|
|
|
|
|
'username' => 'Skim', |
134
|
|
|
|
|
|
|
), |
135
|
|
|
|
|
|
|
Toolforge::MixNMatch::Object::User->new( |
136
|
|
|
|
|
|
|
'count' => 4, |
137
|
|
|
|
|
|
|
'uid' => 2, |
138
|
|
|
|
|
|
|
'username' => 'Foo', |
139
|
|
|
|
|
|
|
), |
140
|
|
|
|
|
|
|
], |
141
|
|
|
|
|
|
|
'year_months' => [ |
142
|
|
|
|
|
|
|
Toolforge::MixNMatch::Object::YearMonth->new( |
143
|
|
|
|
|
|
|
'count' => 2, |
144
|
|
|
|
|
|
|
'month' => 9, |
145
|
|
|
|
|
|
|
'year' => 2020, |
146
|
|
|
|
|
|
|
), |
147
|
|
|
|
|
|
|
Toolforge::MixNMatch::Object::YearMonth->new( |
148
|
|
|
|
|
|
|
'count' => 8, |
149
|
|
|
|
|
|
|
'month' => 10, |
150
|
|
|
|
|
|
|
'year' => 2020, |
151
|
|
|
|
|
|
|
), |
152
|
|
|
|
|
|
|
], |
153
|
|
|
|
|
|
|
); |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
# Get structure. |
156
|
|
|
|
|
|
|
my $struct_hr = obj2struct($obj); |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
# Dump to output. |
159
|
|
|
|
|
|
|
p $struct_hr; |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
# Output: |
162
|
|
|
|
|
|
|
# \ { |
163
|
|
|
|
|
|
|
# type [ |
164
|
|
|
|
|
|
|
# [0] { |
165
|
|
|
|
|
|
|
# cnt 10, |
166
|
|
|
|
|
|
|
# type "Q5" |
167
|
|
|
|
|
|
|
# } |
168
|
|
|
|
|
|
|
# ], |
169
|
|
|
|
|
|
|
# user [ |
170
|
|
|
|
|
|
|
# [0] { |
171
|
|
|
|
|
|
|
# cnt 6, |
172
|
|
|
|
|
|
|
# uid 1, |
173
|
|
|
|
|
|
|
# username "Skim" |
174
|
|
|
|
|
|
|
# }, |
175
|
|
|
|
|
|
|
# [1] { |
176
|
|
|
|
|
|
|
# cnt 4, |
177
|
|
|
|
|
|
|
# uid 2, |
178
|
|
|
|
|
|
|
# username "Foo" |
179
|
|
|
|
|
|
|
# } |
180
|
|
|
|
|
|
|
# ], |
181
|
|
|
|
|
|
|
# ym [ |
182
|
|
|
|
|
|
|
# [0] { |
183
|
|
|
|
|
|
|
# cnt 2, |
184
|
|
|
|
|
|
|
# ym 202009 |
185
|
|
|
|
|
|
|
# }, |
186
|
|
|
|
|
|
|
# [1] { |
187
|
|
|
|
|
|
|
# cnt 8, |
188
|
|
|
|
|
|
|
# ym 202010 |
189
|
|
|
|
|
|
|
# } |
190
|
|
|
|
|
|
|
# ] |
191
|
|
|
|
|
|
|
# } |
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
=head1 EXAMPLE2 |
194
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
use strict; |
196
|
|
|
|
|
|
|
use warnings; |
197
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
use Toolforge::MixNMatch::Struct::Catalog qw(struct2obj); |
199
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
# Time structure. |
201
|
|
|
|
|
|
|
my $struct_hr = { |
202
|
|
|
|
|
|
|
'user' => [{ |
203
|
|
|
|
|
|
|
'cnt' => 6, |
204
|
|
|
|
|
|
|
'uid' => 1, |
205
|
|
|
|
|
|
|
'username' => 'Skim', |
206
|
|
|
|
|
|
|
}, { |
207
|
|
|
|
|
|
|
'cnt' => 4, |
208
|
|
|
|
|
|
|
'uid' => 2, |
209
|
|
|
|
|
|
|
'username' => 'Foo', |
210
|
|
|
|
|
|
|
}], |
211
|
|
|
|
|
|
|
'type' => [{ |
212
|
|
|
|
|
|
|
'cnt' => 10, |
213
|
|
|
|
|
|
|
'type' => 'Q5', |
214
|
|
|
|
|
|
|
}], |
215
|
|
|
|
|
|
|
'ym' => [{ |
216
|
|
|
|
|
|
|
'cnt' => 2, |
217
|
|
|
|
|
|
|
'ym' => 202009, |
218
|
|
|
|
|
|
|
}, { |
219
|
|
|
|
|
|
|
'cnt' => 8, |
220
|
|
|
|
|
|
|
'ym' => 202010, |
221
|
|
|
|
|
|
|
}], |
222
|
|
|
|
|
|
|
}; |
223
|
|
|
|
|
|
|
|
224
|
|
|
|
|
|
|
# Get object. |
225
|
|
|
|
|
|
|
my $obj = struct2obj($struct_hr); |
226
|
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
# Get count. |
228
|
|
|
|
|
|
|
my $count = $obj->count; |
229
|
|
|
|
|
|
|
|
230
|
|
|
|
|
|
|
# Get type. |
231
|
|
|
|
|
|
|
my $type = $obj->type; |
232
|
|
|
|
|
|
|
|
233
|
|
|
|
|
|
|
# Get user statistics. |
234
|
|
|
|
|
|
|
my $users_ar = $obj->users; |
235
|
|
|
|
|
|
|
|
236
|
|
|
|
|
|
|
# Get year/month statistics. |
237
|
|
|
|
|
|
|
my $year_months_ar = $obj->year_months; |
238
|
|
|
|
|
|
|
|
239
|
|
|
|
|
|
|
# Print out. |
240
|
|
|
|
|
|
|
print "Count: $count\n"; |
241
|
|
|
|
|
|
|
print "Type: $type\n"; |
242
|
|
|
|
|
|
|
print "Count of users: ".(scalar @{$users_ar})."\n"; |
243
|
|
|
|
|
|
|
print "Count of year/months: ".(scalar @{$year_months_ar})."\n"; |
244
|
|
|
|
|
|
|
|
245
|
|
|
|
|
|
|
# Output: |
246
|
|
|
|
|
|
|
# Count: 10 |
247
|
|
|
|
|
|
|
# Type: Q5 |
248
|
|
|
|
|
|
|
# Count of users: 2 |
249
|
|
|
|
|
|
|
# Count of year/months: 2 |
250
|
|
|
|
|
|
|
|
251
|
|
|
|
|
|
|
=head1 DEPENDENCIES |
252
|
|
|
|
|
|
|
|
253
|
|
|
|
|
|
|
L<Error::Pure>, |
254
|
|
|
|
|
|
|
L<Exporter>, |
255
|
|
|
|
|
|
|
L<Readonly>, |
256
|
|
|
|
|
|
|
L<Toolforge::MixNMatch::Object::Catalog>, |
257
|
|
|
|
|
|
|
L<Toolforge::MixNMatch::Struct::User>, |
258
|
|
|
|
|
|
|
L<Toolforge::MixNMatch::Struct::YearMonth>. |
259
|
|
|
|
|
|
|
|
260
|
|
|
|
|
|
|
=head1 SEE ALSO |
261
|
|
|
|
|
|
|
|
262
|
|
|
|
|
|
|
=over |
263
|
|
|
|
|
|
|
|
264
|
|
|
|
|
|
|
=item L<Toolforge::MixNMatch::Struct> |
265
|
|
|
|
|
|
|
|
266
|
|
|
|
|
|
|
Toolforge Mix'n'match tool structures. |
267
|
|
|
|
|
|
|
|
268
|
|
|
|
|
|
|
=back |
269
|
|
|
|
|
|
|
|
270
|
|
|
|
|
|
|
=head1 REPOSITORY |
271
|
|
|
|
|
|
|
|
272
|
|
|
|
|
|
|
L<https://github.com/michal-josef-spacek/Toolforge-MixNMatch-Struct> |
273
|
|
|
|
|
|
|
|
274
|
|
|
|
|
|
|
=head1 AUTHOR |
275
|
|
|
|
|
|
|
|
276
|
|
|
|
|
|
|
Michal Josef Špaček L<mailto:skim@cpan.org> |
277
|
|
|
|
|
|
|
|
278
|
|
|
|
|
|
|
L<http://skim.cz> |
279
|
|
|
|
|
|
|
|
280
|
|
|
|
|
|
|
=head1 LICENSE AND COPYRIGHT |
281
|
|
|
|
|
|
|
|
282
|
|
|
|
|
|
|
© Michal Josef Špaček 2020 |
283
|
|
|
|
|
|
|
|
284
|
|
|
|
|
|
|
BSD 2-Clause License |
285
|
|
|
|
|
|
|
|
286
|
|
|
|
|
|
|
=head1 VERSION |
287
|
|
|
|
|
|
|
|
288
|
|
|
|
|
|
|
0.04 |
289
|
|
|
|
|
|
|
|
290
|
|
|
|
|
|
|
=cut |