| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Toolforge::MixNMatch::Struct::YearMonth; |
|
2
|
|
|
|
|
|
|
|
|
3
|
8
|
|
|
8
|
|
335148
|
use base qw(Exporter); |
|
|
8
|
|
|
|
|
53
|
|
|
|
8
|
|
|
|
|
1028
|
|
|
4
|
8
|
|
|
8
|
|
67
|
use strict; |
|
|
8
|
|
|
|
|
16
|
|
|
|
8
|
|
|
|
|
153
|
|
|
5
|
8
|
|
|
8
|
|
38
|
use warnings; |
|
|
8
|
|
|
|
|
14
|
|
|
|
8
|
|
|
|
|
233
|
|
|
6
|
|
|
|
|
|
|
|
|
7
|
8
|
|
|
8
|
|
1540
|
use Error::Pure qw(err); |
|
|
8
|
|
|
|
|
35132
|
|
|
|
8
|
|
|
|
|
340
|
|
|
8
|
8
|
|
|
8
|
|
221
|
use Readonly; |
|
|
8
|
|
|
|
|
15
|
|
|
|
8
|
|
|
|
|
324
|
|
|
9
|
8
|
|
|
8
|
|
2986
|
use Toolforge::MixNMatch::Object::YearMonth; |
|
|
8
|
|
|
|
|
14139
|
|
|
|
8
|
|
|
|
|
2067
|
|
|
10
|
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
Readonly::Array our @EXPORT_OK => qw(obj2struct struct2obj); |
|
12
|
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
our $VERSION = 0.04; |
|
14
|
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub obj2struct { |
|
16
|
5
|
|
|
5
|
1
|
19186
|
my $obj = shift; |
|
17
|
|
|
|
|
|
|
|
|
18
|
5
|
100
|
|
|
|
15
|
if (! defined $obj) { |
|
19
|
1
|
|
|
|
|
5
|
err "Object doesn't exist."; |
|
20
|
|
|
|
|
|
|
} |
|
21
|
4
|
100
|
|
|
|
29
|
if (! $obj->isa('Toolforge::MixNMatch::Object::YearMonth')) { |
|
22
|
1
|
|
|
|
|
5
|
err "Object isn't 'Toolforge::MixNMatch::Object::YearMonth'."; |
|
23
|
|
|
|
|
|
|
} |
|
24
|
|
|
|
|
|
|
|
|
25
|
3
|
|
|
|
|
11
|
my $struct_hr = { |
|
26
|
|
|
|
|
|
|
'cnt' => $obj->count, |
|
27
|
|
|
|
|
|
|
'ym' => $obj->year.(sprintf '%02d', $obj->month), |
|
28
|
|
|
|
|
|
|
}; |
|
29
|
|
|
|
|
|
|
|
|
30
|
3
|
|
|
|
|
68
|
return $struct_hr; |
|
31
|
|
|
|
|
|
|
} |
|
32
|
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub struct2obj { |
|
34
|
3
|
|
|
3
|
1
|
88
|
my $struct_hr = shift; |
|
35
|
|
|
|
|
|
|
|
|
36
|
3
|
|
|
|
|
22
|
my ($year, $month) = $struct_hr->{'ym'} =~ m/^(\d{4})(\d{2})$/ms; |
|
37
|
|
|
|
|
|
|
my $obj = Toolforge::MixNMatch::Object::YearMonth->new( |
|
38
|
3
|
|
|
|
|
29
|
'count' => $struct_hr->{'cnt'}, |
|
39
|
|
|
|
|
|
|
'month' => int($month), |
|
40
|
|
|
|
|
|
|
'year' => $year, |
|
41
|
|
|
|
|
|
|
); |
|
42
|
|
|
|
|
|
|
|
|
43
|
3
|
|
|
|
|
214
|
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::YearMonth - Mix'n'match year/month structure serialization. |
|
57
|
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
59
|
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
use Toolforge::MixNMatch::Struct::YearMonth 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::YearMonth 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::YearMonth 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::YearMonth instance. |
|
87
|
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
=head1 ERRORS |
|
89
|
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
obj2struct(): |
|
91
|
|
|
|
|
|
|
Object doesn't exist. |
|
92
|
|
|
|
|
|
|
Object isn't 'Toolforge::MixNMatch::Object::YearMonth'. |
|
93
|
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
=head1 EXAMPLE1 |
|
95
|
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
use strict; |
|
97
|
|
|
|
|
|
|
use warnings; |
|
98
|
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
use Data::Printer; |
|
100
|
|
|
|
|
|
|
use Toolforge::MixNMatch::Object::YearMonth; |
|
101
|
|
|
|
|
|
|
use Toolforge::MixNMatch::Struct::YearMonth qw(obj2struct); |
|
102
|
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
# Object. |
|
104
|
|
|
|
|
|
|
my $obj = Toolforge::MixNMatch::Object::YearMonth->new( |
|
105
|
|
|
|
|
|
|
'count' => 6, |
|
106
|
|
|
|
|
|
|
'month' => 9, |
|
107
|
|
|
|
|
|
|
'year' => 2020, |
|
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
|
|
|
|
|
|
|
# ym 202009 |
|
120
|
|
|
|
|
|
|
# } |
|
121
|
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
=head1 EXAMPLE2 |
|
123
|
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
use strict; |
|
125
|
|
|
|
|
|
|
use warnings; |
|
126
|
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
use Toolforge::MixNMatch::Struct::YearMonth qw(struct2obj); |
|
128
|
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
# Time structure. |
|
130
|
|
|
|
|
|
|
my $struct_hr = { |
|
131
|
|
|
|
|
|
|
'cnt' => 6, |
|
132
|
|
|
|
|
|
|
'ym' => 202009, |
|
133
|
|
|
|
|
|
|
}; |
|
134
|
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
# Get object. |
|
136
|
|
|
|
|
|
|
my $obj = struct2obj($struct_hr); |
|
137
|
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
# Get count. |
|
139
|
|
|
|
|
|
|
my $count = $obj->count; |
|
140
|
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
# Get month. |
|
142
|
|
|
|
|
|
|
my $month = $obj->month; |
|
143
|
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
# Get year. |
|
145
|
|
|
|
|
|
|
my $year = $obj->year; |
|
146
|
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
# Print out. |
|
148
|
|
|
|
|
|
|
print "Count: $count\n"; |
|
149
|
|
|
|
|
|
|
print "Month: $month\n"; |
|
150
|
|
|
|
|
|
|
print "Year: $year\n"; |
|
151
|
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
# Output: |
|
153
|
|
|
|
|
|
|
# Count: 6 |
|
154
|
|
|
|
|
|
|
# Month: 9 |
|
155
|
|
|
|
|
|
|
# Year: 2020 |
|
156
|
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
=head1 DEPENDENCIES |
|
158
|
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
L<Error::Pure>, |
|
160
|
|
|
|
|
|
|
L<Exporter>, |
|
161
|
|
|
|
|
|
|
L<Readonly>, |
|
162
|
|
|
|
|
|
|
L<Toolforge::MixNMatch::Struct::YearMonth>. |
|
163
|
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
=head1 SEE ALSO |
|
165
|
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
=over |
|
167
|
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
=item L<Toolforge::MixNMatch::Struct> |
|
169
|
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
Toolforge Mix'n'match tool structures. |
|
171
|
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
=back |
|
173
|
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
=head1 REPOSITORY |
|
175
|
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
L<https://github.com/michal-josef-spacek/Toolforge-MixNMatch-Struct> |
|
177
|
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
=head1 AUTHOR |
|
179
|
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
Michal Josef Špaček L<mailto:skim@cpan.org> |
|
181
|
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
L<http://skim.cz> |
|
183
|
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
=head1 LICENSE AND COPYRIGHT |
|
185
|
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
© Michal Josef Špaček 2020 |
|
187
|
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
BSD 2-Clause License |
|
189
|
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
=head1 VERSION |
|
191
|
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
0.04 |
|
193
|
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
=cut |