line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Toolforge::MixNMatch::Struct::User; |
2
|
|
|
|
|
|
|
|
3
|
8
|
|
|
8
|
|
335773
|
use base qw(Exporter); |
|
8
|
|
|
|
|
54
|
|
|
8
|
|
|
|
|
1027
|
|
4
|
8
|
|
|
8
|
|
57
|
use strict; |
|
8
|
|
|
|
|
18
|
|
|
8
|
|
|
|
|
171
|
|
5
|
8
|
|
|
8
|
|
44
|
use warnings; |
|
8
|
|
|
|
|
16
|
|
|
8
|
|
|
|
|
228
|
|
6
|
|
|
|
|
|
|
|
7
|
8
|
|
|
8
|
|
1536
|
use Error::Pure qw(err); |
|
8
|
|
|
|
|
35762
|
|
|
8
|
|
|
|
|
254
|
|
8
|
8
|
|
|
8
|
|
210
|
use Readonly; |
|
8
|
|
|
|
|
24
|
|
|
8
|
|
|
|
|
315
|
|
9
|
8
|
|
|
8
|
|
3074
|
use Toolforge::MixNMatch::Object::User; |
|
8
|
|
|
|
|
14180
|
|
|
8
|
|
|
|
|
1731
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
Readonly::Array our @EXPORT_OK => qw(obj2struct struct2obj); |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
our $VERSION = 0.04; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub obj2struct { |
16
|
5
|
|
|
5
|
1
|
19468
|
my $obj = shift; |
17
|
|
|
|
|
|
|
|
18
|
5
|
100
|
|
|
|
20
|
if (! defined $obj) { |
19
|
1
|
|
|
|
|
4
|
err "Object doesn't exist."; |
20
|
|
|
|
|
|
|
} |
21
|
4
|
100
|
|
|
|
29
|
if (! $obj->isa('Toolforge::MixNMatch::Object::User')) { |
22
|
1
|
|
|
|
|
5
|
err "Object isn't 'Toolforge::MixNMatch::Object::User'."; |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
|
25
|
3
|
|
|
|
|
13
|
my $struct_hr = { |
26
|
|
|
|
|
|
|
'cnt' => $obj->count, |
27
|
|
|
|
|
|
|
'uid' => $obj->uid, |
28
|
|
|
|
|
|
|
'username' => $obj->username, |
29
|
|
|
|
|
|
|
}; |
30
|
|
|
|
|
|
|
|
31
|
3
|
|
|
|
|
57
|
return $struct_hr; |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
sub struct2obj { |
35
|
3
|
|
|
3
|
1
|
100
|
my $struct_hr = shift; |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
my $obj = Toolforge::MixNMatch::Object::User->new( |
38
|
|
|
|
|
|
|
'count' => $struct_hr->{'cnt'}, |
39
|
|
|
|
|
|
|
'uid' => $struct_hr->{'uid'}, |
40
|
3
|
|
|
|
|
23
|
'username' => $struct_hr->{'username'}, |
41
|
|
|
|
|
|
|
); |
42
|
|
|
|
|
|
|
|
43
|
3
|
|
|
|
|
204
|
return $obj; |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
1; |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
__END__ |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
=pod |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
=encoding utf8 |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
=head1 NAME |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
Toolforge::MixNMatch::Struct::User - Mix'n'match user structure serialization. |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
=head1 SYNOPSIS |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
use Toolforge::MixNMatch::Struct::User qw(obj2struct struct2obj); |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
my $struct_hr = obj2struct($obj); |
63
|
|
|
|
|
|
|
my $obj = struct2obj($struct_hr); |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
=head1 DESCRIPTION |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
This conversion is between object defined in Toolforge::MixNMatch::Object::User and structure |
68
|
|
|
|
|
|
|
serialized via JSON to Mix'n'match application. |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
=head1 SUBROUTINES |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
=head2 C<obj2struct> |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
my $struct_hr = obj2struct($obj); |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
Convert Toolforge::MixNMatch::Object::User instance to structure. |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
Returns reference to hash with structure. |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
=head2 C<struct2obj> |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
my $obj = struct2obj($struct_hr); |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
Convert structure of time to object. |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
Returns Toolforge::MixNMatch::Object::User instance. |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
=head1 ERRORS |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
obj2struct(): |
91
|
|
|
|
|
|
|
Object doesn't exist. |
92
|
|
|
|
|
|
|
Object isn't 'Toolforge::MixNMatch::Object::User'. |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
=head1 EXAMPLE1 |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
use strict; |
97
|
|
|
|
|
|
|
use warnings; |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
use Data::Printer; |
100
|
|
|
|
|
|
|
use Toolforge::MixNMatch::Object::User; |
101
|
|
|
|
|
|
|
use Toolforge::MixNMatch::Struct::User qw(obj2struct); |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
# Object. |
104
|
|
|
|
|
|
|
my $obj = Toolforge::MixNMatch::Object::User->new( |
105
|
|
|
|
|
|
|
'count' => 6, |
106
|
|
|
|
|
|
|
'uid' => 1, |
107
|
|
|
|
|
|
|
'username' => 'Skim', |
108
|
|
|
|
|
|
|
); |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
# Get structure. |
111
|
|
|
|
|
|
|
my $struct_hr = obj2struct($obj); |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
# Dump to output. |
114
|
|
|
|
|
|
|
p $struct_hr; |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
# Output: |
117
|
|
|
|
|
|
|
# \ { |
118
|
|
|
|
|
|
|
# cnt 6, |
119
|
|
|
|
|
|
|
# uid 1, |
120
|
|
|
|
|
|
|
# username "Skim" |
121
|
|
|
|
|
|
|
# } |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
=head1 EXAMPLE2 |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
use strict; |
126
|
|
|
|
|
|
|
use warnings; |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
use Toolforge::MixNMatch::Struct::User qw(struct2obj); |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
# Time structure. |
131
|
|
|
|
|
|
|
my $struct_hr = { |
132
|
|
|
|
|
|
|
'cnt' => 6, |
133
|
|
|
|
|
|
|
'uid' => 1, |
134
|
|
|
|
|
|
|
'username' => 'Skim', |
135
|
|
|
|
|
|
|
}; |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
# Get object. |
138
|
|
|
|
|
|
|
my $obj = struct2obj($struct_hr); |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
# Get count. |
141
|
|
|
|
|
|
|
my $count = $obj->count; |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
# Get user UID. |
144
|
|
|
|
|
|
|
my $uid = $obj->uid; |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
# Get user name. |
147
|
|
|
|
|
|
|
my $username = $obj->username; |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
# Print out. |
150
|
|
|
|
|
|
|
print "Count: $count\n"; |
151
|
|
|
|
|
|
|
print "User UID: $uid\n"; |
152
|
|
|
|
|
|
|
print "User name: $username\n"; |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
# Output: |
155
|
|
|
|
|
|
|
# Count: 6 |
156
|
|
|
|
|
|
|
# User UID: 1 |
157
|
|
|
|
|
|
|
# User name: Skim |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
=head1 DEPENDENCIES |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
L<Error::Pure>, |
162
|
|
|
|
|
|
|
L<Exporter>, |
163
|
|
|
|
|
|
|
L<Readonly>, |
164
|
|
|
|
|
|
|
L<Toolforge::MixNMatch::Struct::User>. |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
=head1 SEE ALSO |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
=over |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
=item L<Toolforge::MixNMatch::Struct> |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
Toolforge Mix'n'match tool structures. |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
=back |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
=head1 REPOSITORY |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
L<https://github.com/michal-josef-spacek/Toolforge-MixNMatch-Struct> |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
=head1 AUTHOR |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
Michal Josef Špaček L<mailto:skim@cpan.org> |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
L<http://skim.cz> |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
=head1 LICENSE AND COPYRIGHT |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
© Michal Josef Špaček 2020 |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
BSD 2-Clause License |
191
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
=head1 VERSION |
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
0.04 |
195
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
=cut |