line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Data::Commons::Image; |
2
|
|
|
|
|
|
|
|
3
|
15
|
|
|
15
|
|
120599
|
use strict; |
|
15
|
|
|
|
|
104
|
|
|
15
|
|
|
|
|
428
|
|
4
|
15
|
|
|
15
|
|
77
|
use warnings; |
|
15
|
|
|
|
|
31
|
|
|
15
|
|
|
|
|
469
|
|
5
|
|
|
|
|
|
|
|
6
|
15
|
|
|
15
|
|
6527
|
use Mo qw(build is); |
|
15
|
|
|
|
|
7922
|
|
|
15
|
|
|
|
|
82
|
|
7
|
15
|
|
|
15
|
|
29384
|
use Mo::utils qw(check_isa check_length check_number check_required); |
|
15
|
|
|
|
|
232132
|
|
|
15
|
|
|
|
|
294
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
extends 'Data::Image'; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
our $VERSION = 0.06; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
has commons_name => ( |
14
|
|
|
|
|
|
|
is => 'ro', |
15
|
|
|
|
|
|
|
); |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
has dt_uploaded => ( |
18
|
|
|
|
|
|
|
is => 'ro', |
19
|
|
|
|
|
|
|
); |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
has license => ( |
22
|
|
|
|
|
|
|
is => 'ro', |
23
|
|
|
|
|
|
|
); |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
has page_id => ( |
26
|
|
|
|
|
|
|
is => 'ro', |
27
|
|
|
|
|
|
|
); |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub BUILD { |
30
|
27
|
|
|
27
|
0
|
17576
|
my $self = shift; |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
# Check commons_name. |
33
|
27
|
|
|
|
|
106
|
check_required($self, 'commons_name'); |
34
|
26
|
|
|
|
|
227
|
check_length($self, 'commons_name', 255); |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
# Check date uploaded. |
37
|
26
|
|
|
|
|
352
|
check_isa($self, 'dt_uploaded', 'DateTime'); |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
# Check page_id. |
40
|
26
|
|
|
|
|
257
|
check_number($self, 'page_id'); |
41
|
|
|
|
|
|
|
|
42
|
26
|
|
|
|
|
225
|
return; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
1; |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
__END__ |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
=pod |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
=encoding utf8 |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
=head1 NAME |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
Data::Commons::Image - Data object for Wikimedia Commons image. |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
=head1 SYNOPSIS |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
use Data::Commons::Image; |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
my $obj = Data::Commons::Image->new(%params); |
62
|
|
|
|
|
|
|
my $author = $obj->author; |
63
|
|
|
|
|
|
|
my $comment = $obj->comment; |
64
|
|
|
|
|
|
|
my $commons_name = $obj->commons_name; |
65
|
|
|
|
|
|
|
my $dt_created = $obj->dt_created; |
66
|
|
|
|
|
|
|
my $dt_uploaded = $obj->dt_uploaded; |
67
|
|
|
|
|
|
|
my $height = $obj->height; |
68
|
|
|
|
|
|
|
my $id = $obj->id; |
69
|
|
|
|
|
|
|
my $license = $obj->license; |
70
|
|
|
|
|
|
|
my $page_id = $obj->page_id; |
71
|
|
|
|
|
|
|
my $size = $obj->size; |
72
|
|
|
|
|
|
|
my $url = $obj->url; |
73
|
|
|
|
|
|
|
my $url_cb = $obj->url_cb; |
74
|
|
|
|
|
|
|
my $width = $obj->width; |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
=head1 DESCRIPTION |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
Data object for Wikimedia Commons image. Inherits L<Data::Image> common object. |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
=head1 METHODS |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
=head2 C<new> |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
my $obj = Data::Commons::Image->new(%params); |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
Constructor. |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
Returns instance of object. |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
=over 8 |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
=item * C<author> |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
Image author. |
95
|
|
|
|
|
|
|
It's optional. |
96
|
|
|
|
|
|
|
Default value is undef. |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
=item * C<comment> |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
Image comment. |
101
|
|
|
|
|
|
|
It's optional. |
102
|
|
|
|
|
|
|
Default value is undef. |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
=item * C<commons_name> |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
Image name in Wikimedia Commons. |
107
|
|
|
|
|
|
|
It's required. |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
=item * C<dt_created> |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
Date and time the image was created. |
112
|
|
|
|
|
|
|
Value must be L<DateTime> object. |
113
|
|
|
|
|
|
|
It's optional. |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
=item * C<dt_uploaded> |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
Date and time the image was uploaded to Wikimedia Commons. |
118
|
|
|
|
|
|
|
Value must be L<DateTime> object. |
119
|
|
|
|
|
|
|
It's optional. |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
=item * C<height> |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
Image height. |
124
|
|
|
|
|
|
|
It's optional. |
125
|
|
|
|
|
|
|
Default value is undef. |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
=item * C<id> |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
Image id. |
130
|
|
|
|
|
|
|
It's optional. |
131
|
|
|
|
|
|
|
Default value is undef. |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
=item * C<license> |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
Image license. |
136
|
|
|
|
|
|
|
It's optional. |
137
|
|
|
|
|
|
|
Default value is undef. |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
=item * C<page_id> |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
Image page id on Wikimedia Commons. |
142
|
|
|
|
|
|
|
It's used for structured data with 'M' prefix. |
143
|
|
|
|
|
|
|
It's optional. |
144
|
|
|
|
|
|
|
Default value is undef. |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
=item * C<size> |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
Image size. |
149
|
|
|
|
|
|
|
It's optional. |
150
|
|
|
|
|
|
|
Default value is undef. |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
=item * C<url> |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
URL of image. |
155
|
|
|
|
|
|
|
It's optional. |
156
|
|
|
|
|
|
|
Default value is undef. |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
=item * C<url_cb> |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
URL callback. To get URL from code. |
161
|
|
|
|
|
|
|
It's optional. |
162
|
|
|
|
|
|
|
Default value is undef. |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
=item * C<width> |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
Image width. |
167
|
|
|
|
|
|
|
It's optional. |
168
|
|
|
|
|
|
|
Default value is undef. |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
=back |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
=head2 C<author> |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
my $author = $obj->author; |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
Get image author. |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
Returns string. |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
=head2 C<comment> |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
my $comment = $obj->comment; |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
Get image comment. |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
Returns string. |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
=head2 C<commons_name> |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
my $commons_name = $obj->commons_name; |
191
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
Get image name in Wikimedia Commons. |
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
Returns string. |
195
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
=head2 C<dt_created> |
197
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
my $dt_created = $obj->dt_created; |
199
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
Get date and time the image was created. |
201
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
Returns L<DateTime> object. |
203
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
=head2 C<dt_uploaded> |
205
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
my $dt_uploaded = $obj->dt_uploaded; |
207
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
Get date and time the image was uploaded to Wikimedia Commons. |
209
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
Returns L<DateTime> object. |
211
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
=head2 C<height> |
213
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
my $height = $obj->height; |
215
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
Get image height. |
217
|
|
|
|
|
|
|
|
218
|
|
|
|
|
|
|
Returns number. |
219
|
|
|
|
|
|
|
|
220
|
|
|
|
|
|
|
=head2 C<id> |
221
|
|
|
|
|
|
|
|
222
|
|
|
|
|
|
|
my $id = $obj->id; |
223
|
|
|
|
|
|
|
|
224
|
|
|
|
|
|
|
Get image id. |
225
|
|
|
|
|
|
|
|
226
|
|
|
|
|
|
|
Returns number. |
227
|
|
|
|
|
|
|
|
228
|
|
|
|
|
|
|
=head2 C<license> |
229
|
|
|
|
|
|
|
|
230
|
|
|
|
|
|
|
my $license = $obj->license; |
231
|
|
|
|
|
|
|
|
232
|
|
|
|
|
|
|
Get image license. |
233
|
|
|
|
|
|
|
|
234
|
|
|
|
|
|
|
Returns string. |
235
|
|
|
|
|
|
|
|
236
|
|
|
|
|
|
|
=head2 C<page_id> |
237
|
|
|
|
|
|
|
|
238
|
|
|
|
|
|
|
my $page_id = $obj->page_id; |
239
|
|
|
|
|
|
|
|
240
|
|
|
|
|
|
|
Get image page id. |
241
|
|
|
|
|
|
|
|
242
|
|
|
|
|
|
|
Returns number. |
243
|
|
|
|
|
|
|
|
244
|
|
|
|
|
|
|
=head2 C<size> |
245
|
|
|
|
|
|
|
|
246
|
|
|
|
|
|
|
my $size = $obj->size; |
247
|
|
|
|
|
|
|
|
248
|
|
|
|
|
|
|
Get image size. |
249
|
|
|
|
|
|
|
|
250
|
|
|
|
|
|
|
Returns number. |
251
|
|
|
|
|
|
|
|
252
|
|
|
|
|
|
|
=head2 C<url> |
253
|
|
|
|
|
|
|
|
254
|
|
|
|
|
|
|
my $url = $obj->url; |
255
|
|
|
|
|
|
|
|
256
|
|
|
|
|
|
|
Get URL of image. |
257
|
|
|
|
|
|
|
|
258
|
|
|
|
|
|
|
Returns string. |
259
|
|
|
|
|
|
|
|
260
|
|
|
|
|
|
|
=head2 C<url_cb> |
261
|
|
|
|
|
|
|
|
262
|
|
|
|
|
|
|
my $url_cb = $obj->url_cb; |
263
|
|
|
|
|
|
|
|
264
|
|
|
|
|
|
|
Get URL callback. |
265
|
|
|
|
|
|
|
|
266
|
|
|
|
|
|
|
Returns code. |
267
|
|
|
|
|
|
|
|
268
|
|
|
|
|
|
|
=head2 C<width> |
269
|
|
|
|
|
|
|
|
270
|
|
|
|
|
|
|
my $width = $obj->width; |
271
|
|
|
|
|
|
|
|
272
|
|
|
|
|
|
|
Get image width. |
273
|
|
|
|
|
|
|
|
274
|
|
|
|
|
|
|
Returns number. |
275
|
|
|
|
|
|
|
|
276
|
|
|
|
|
|
|
new(): |
277
|
|
|
|
|
|
|
From Data::Image: |
278
|
|
|
|
|
|
|
From Mo::utils: |
279
|
|
|
|
|
|
|
Parameter 'author' has length greater than '255'. |
280
|
|
|
|
|
|
|
Value: %s |
281
|
|
|
|
|
|
|
Parameter 'comment' has length greater than '1000'. |
282
|
|
|
|
|
|
|
Value: %s |
283
|
|
|
|
|
|
|
Parameter 'dt_created' must be a 'DateTime' object. |
284
|
|
|
|
|
|
|
Value: %s |
285
|
|
|
|
|
|
|
Reference: %s |
286
|
|
|
|
|
|
|
Parameter 'height' must a number. |
287
|
|
|
|
|
|
|
Value: %s |
288
|
|
|
|
|
|
|
Parameter 'id' must a number. |
289
|
|
|
|
|
|
|
Value: %s |
290
|
|
|
|
|
|
|
Parameter 'size' must a number. |
291
|
|
|
|
|
|
|
Value: %s |
292
|
|
|
|
|
|
|
Parameter 'url' has length greater than '255'. |
293
|
|
|
|
|
|
|
Value: %s |
294
|
|
|
|
|
|
|
Parameter 'url_cb' must be a code. |
295
|
|
|
|
|
|
|
Value: %s |
296
|
|
|
|
|
|
|
Parameter 'width' must a number. |
297
|
|
|
|
|
|
|
Value: %s |
298
|
|
|
|
|
|
|
Parameter 'commons_name' is required. |
299
|
|
|
|
|
|
|
Parameter 'commons_name' has length greater than '255'. |
300
|
|
|
|
|
|
|
Value: %s |
301
|
|
|
|
|
|
|
Parameter 'dt_uploaded' must be a 'DateTime' object. |
302
|
|
|
|
|
|
|
Value: %s |
303
|
|
|
|
|
|
|
Reference: %s |
304
|
|
|
|
|
|
|
Parameter 'page_id' must a number. |
305
|
|
|
|
|
|
|
Value: %s |
306
|
|
|
|
|
|
|
|
307
|
|
|
|
|
|
|
=head1 EXAMPLE |
308
|
|
|
|
|
|
|
|
309
|
|
|
|
|
|
|
=for comment filename=create_and_print_image.pl |
310
|
|
|
|
|
|
|
|
311
|
|
|
|
|
|
|
use strict; |
312
|
|
|
|
|
|
|
use warnings; |
313
|
|
|
|
|
|
|
|
314
|
|
|
|
|
|
|
use Data::Commons::Image; |
315
|
|
|
|
|
|
|
use DateTime; |
316
|
|
|
|
|
|
|
|
317
|
|
|
|
|
|
|
my $obj = Data::Commons::Image->new( |
318
|
|
|
|
|
|
|
'author' => 'Zuzana Zonova', |
319
|
|
|
|
|
|
|
'comment' => 'Michal from Czechia', |
320
|
|
|
|
|
|
|
'commons_name' => 'Michal_from_Czechia.jpg', |
321
|
|
|
|
|
|
|
'dt_created' => DateTime->new( |
322
|
|
|
|
|
|
|
'day' => 1, |
323
|
|
|
|
|
|
|
'month' => 1, |
324
|
|
|
|
|
|
|
'year' => 2022, |
325
|
|
|
|
|
|
|
), |
326
|
|
|
|
|
|
|
'dt_uploaded' => DateTime->new( |
327
|
|
|
|
|
|
|
'day' => 14, |
328
|
|
|
|
|
|
|
'month' => 7, |
329
|
|
|
|
|
|
|
'year' => 2022, |
330
|
|
|
|
|
|
|
), |
331
|
|
|
|
|
|
|
'height' => 2730, |
332
|
|
|
|
|
|
|
'license' => 'cc-by-sa-4.0', |
333
|
|
|
|
|
|
|
'page_id' => '95648152', |
334
|
|
|
|
|
|
|
'size' => 1040304, |
335
|
|
|
|
|
|
|
'url' => 'https://upload.wikimedia.org/wikipedia/commons/a/a4/Michal_from_Czechia.jpg', |
336
|
|
|
|
|
|
|
'width' => 4096, |
337
|
|
|
|
|
|
|
); |
338
|
|
|
|
|
|
|
|
339
|
|
|
|
|
|
|
# Print out. |
340
|
|
|
|
|
|
|
print 'Author: '.$obj->author."\n"; |
341
|
|
|
|
|
|
|
print 'Comment: '.$obj->comment."\n"; |
342
|
|
|
|
|
|
|
print 'Wikimedia Commons name: '.$obj->commons_name."\n"; |
343
|
|
|
|
|
|
|
print 'Height: '.$obj->height."\n"; |
344
|
|
|
|
|
|
|
print 'Size: '.$obj->size."\n"; |
345
|
|
|
|
|
|
|
print 'URL: '.$obj->url."\n"; |
346
|
|
|
|
|
|
|
print 'Width: '.$obj->width."\n"; |
347
|
|
|
|
|
|
|
print 'License: '.$obj->license."\n"; |
348
|
|
|
|
|
|
|
print 'Page id: '.$obj->page_id."\n"; |
349
|
|
|
|
|
|
|
print 'Date and time the photo was created: '.$obj->dt_created."\n"; |
350
|
|
|
|
|
|
|
print 'Date and time the photo was uploaded: '.$obj->dt_uploaded."\n"; |
351
|
|
|
|
|
|
|
|
352
|
|
|
|
|
|
|
# Output: |
353
|
|
|
|
|
|
|
# Author: Zuzana Zonova |
354
|
|
|
|
|
|
|
# Comment: Michal from Czechia |
355
|
|
|
|
|
|
|
# Wikimedia Commons name: Michal_from_Czechia.jpg |
356
|
|
|
|
|
|
|
# Height: 2730 |
357
|
|
|
|
|
|
|
# Size: 1040304 |
358
|
|
|
|
|
|
|
# URL: https://upload.wikimedia.org/wikipedia/commons/a/a4/Michal_from_Czechia.jpg |
359
|
|
|
|
|
|
|
# Width: 4096 |
360
|
|
|
|
|
|
|
# License: cc-by-sa-4.0 |
361
|
|
|
|
|
|
|
# Page id: 95648152 |
362
|
|
|
|
|
|
|
# Date and time the photo was created: 2022-01-01T00:00:00 |
363
|
|
|
|
|
|
|
# Date and time the photo was uploaded: 2022-07-14T00:00:00 |
364
|
|
|
|
|
|
|
|
365
|
|
|
|
|
|
|
=head1 DEPENDENCIES |
366
|
|
|
|
|
|
|
|
367
|
|
|
|
|
|
|
L<Data::Image>, |
368
|
|
|
|
|
|
|
L<Mo>, |
369
|
|
|
|
|
|
|
L<Mo::utils>. |
370
|
|
|
|
|
|
|
|
371
|
|
|
|
|
|
|
=head1 REPOSITORY |
372
|
|
|
|
|
|
|
|
373
|
|
|
|
|
|
|
L<https://github.com/michal-josef-spacek/Data-Commons-Image> |
374
|
|
|
|
|
|
|
|
375
|
|
|
|
|
|
|
=head1 AUTHOR |
376
|
|
|
|
|
|
|
|
377
|
|
|
|
|
|
|
Michal Josef Špaček L<mailto:skim@cpan.org> |
378
|
|
|
|
|
|
|
|
379
|
|
|
|
|
|
|
L<http://skim.cz> |
380
|
|
|
|
|
|
|
|
381
|
|
|
|
|
|
|
=head1 LICENSE AND COPYRIGHT |
382
|
|
|
|
|
|
|
|
383
|
|
|
|
|
|
|
© 2022-2023 Michal Josef Špaček |
384
|
|
|
|
|
|
|
|
385
|
|
|
|
|
|
|
BSD 2-Clause License |
386
|
|
|
|
|
|
|
|
387
|
|
|
|
|
|
|
=head1 VERSION |
388
|
|
|
|
|
|
|
|
389
|
|
|
|
|
|
|
0.06 |
390
|
|
|
|
|
|
|
|
391
|
|
|
|
|
|
|
=cut |