File Coverage

blib/lib/Wikibase/Datatype/Mediainfo.pm
Criterion Covered Total %
statement 26 26 100.0
branch n/a
condition n/a
subroutine 7 7 100.0
pod 0 1 0.0
total 33 34 97.0


line stmt bran cond sub pod time code
1             package Wikibase::Datatype::Mediainfo;
2              
3 15     15   2245809 use strict;
  15         36  
  15         642  
4 15     15   80 use warnings;
  15         30  
  15         1069  
5              
6 15     15   8351 use Error::Pure qw(err);
  15         218809  
  15         457  
7 15     15   10094 use Mo qw(build default is);
  15         11371  
  15         105  
8 15     15   69690 use Mo::utils qw(check_number check_number_of_items);
  15         53753  
  15         530  
9 15     15   15970 use Mo::utils::Array qw(check_array_object);
  15         47504  
  15         423  
10              
11             our $VERSION = 0.39;
12              
13             has descriptions => (
14             default => [],
15             is => 'ro',
16             );
17              
18             has id => (
19             is => 'ro',
20             );
21              
22             has labels => (
23             default => [],
24             is => 'ro',
25             );
26              
27             has lastrevid => (
28             is => 'ro',
29             );
30              
31             has modified => (
32             is => 'ro',
33             );
34              
35             has ns => (
36             default => 6,
37             is => 'ro',
38             );
39              
40             has page_id => (
41             is => 'ro',
42             );
43              
44             has statements => (
45             default => [],
46             is => 'ro',
47             );
48              
49             has title => (
50             is => 'ro',
51             );
52              
53             sub BUILD {
54 21     21 0 2432472 my $self = shift;
55              
56             # Check descriptions.
57 21         136 check_array_object($self, 'descriptions', 'Wikibase::Datatype::Value::Monolingual');
58 20         425 check_number_of_items($self, 'descriptions', 'language', 'Description', 'language');
59              
60             # Check labels.
61 19         747 check_array_object($self, 'labels', 'Wikibase::Datatype::Value::Monolingual');
62 18         252 check_number_of_items($self, 'labels', 'language', 'Label', 'language');
63              
64             # Check page id.
65 17         484 check_number($self, 'page_id');
66              
67             # Check statements.
68 16         273 check_array_object($self, 'statements', 'Wikibase::Datatype::MediainfoStatement');
69              
70 15         303 return;
71             }
72              
73             1;
74              
75             __END__
76              
77             =pod
78              
79             =encoding utf8
80              
81             =head1 NAME
82              
83             Wikibase::Datatype::Mediainfo - Wikibase mediainfo datatype.
84              
85             =head1 SYNOPSIS
86              
87             use Wikibase::Datatype::Mediainfo;
88              
89             my $obj = Wikibase::Datatype::Mediainfo->new(%params);
90             my $descriptions_ar = $obj->descriptions;
91             my $id = $obj->id;
92             my $labels_ar = $obj->labels;
93             my $lastrevid = $obj->lastrevid;
94             my $modified = $obj->modified;
95             my $ns = $obj->ns;
96             my $page_id = $obj->page_id;
97             my $statements_ar = $obj->statements;
98             my $title = $obj->title;
99              
100             =head1 DESCRIPTION
101              
102             This datatype is mediainfo class for representing commons structured data.
103              
104             =head1 METHODS
105              
106             =head2 C<new>
107              
108             my $obj = Wikibase::Datatype::Mediainfo->new(%params);
109              
110             Constructor.
111              
112             Returns instance of object.
113              
114             =over 8
115              
116             =item * C<descriptions>
117              
118             Mediainfo descriptions. One per language.
119             Reference to array with Wikibase::Datatype::Value::Monolingual instances.
120             Parameter is optional.
121              
122             =item * C<id>
123              
124             Id.
125             Parameter is optional.
126              
127             =item * C<labels>
128              
129             Mediainfo descriptions. One per language.
130             Reference to array with Wikibase::Datatype::Value::Monolingual instances.
131             Parameter is optional.
132              
133             =item * C<lastrevid>
134              
135             Last revision ID.
136             Parameter is optional.
137              
138             =item * C<modified>
139              
140             Date of modification.
141             Parameter is optional.
142              
143             =item * C<ns>
144              
145             Namespace.
146             Default value is 6.
147              
148             =item * C<page_id>
149              
150             Page id. Numeric value.
151             Parameter is optional.
152              
153             =item * C<statements>
154              
155             Mediainfo statements.
156             Reference to array with Wikibase::Datatype::MediainfoStatement instances.
157             Parameter is optional.
158              
159             =item * C<title>
160              
161             Mediainfo title.
162             Parameter is optional.
163              
164             =back
165              
166             =head2 C<descriptions>
167              
168             my $descriptions_ar = $obj->descriptions;
169              
170             Get descriptions.
171              
172             Returns reference to array with Wikibase::Datatype::Value::Monolingual instances.
173              
174             =head2 C<id>
175              
176             my $id = $obj->id;
177              
178             Get id.
179              
180             Returns string.
181              
182             =head2 C<labels>
183              
184             my $labels_ar = $obj->labels;
185              
186             Get labels.
187              
188             Returns reference to array with Wikibase::Datatype::Value::Monolingual instances.
189              
190             =head2 C<lastrevid>
191              
192             my $lastrevid = $obj->lastrevid;
193              
194             Get last revision ID.
195              
196             Returns string.
197              
198             =head2 C<modified>
199              
200             my $modified = $obj->modified;
201              
202             Get date of modification.
203              
204             Returns string.
205              
206             =head2 C<ns>
207              
208             my $ns = $obj->ns;
209              
210             Get namespace.
211              
212             Returns number.
213              
214             =head2 C<page_id>
215              
216             my $page_id = $obj->page_id;
217              
218             Get page id.
219              
220             Returns number.
221              
222             =head2 C<statements>
223              
224             my $statements_ar = $obj->statements;
225              
226             Get statements.
227              
228             Returns reference to array with Wikibase::Datatype::MediainfoStatement instances.
229              
230             =head2 C<title>
231              
232             my $title = $obj->title;
233              
234             Get title.
235              
236             Returns string.
237              
238             =head1 ERRORS
239              
240             new():
241             From Mo::utils::check_page_id():
242             Parameter 'page_id' must a number.
243              
244             From Mo::utils::check_number_of_items():
245             Sitelink for site '%s' has multiple values.
246             Description for language '%s' has multiple values.
247             Label for language '%s' has multiple values.
248              
249             From Mo::utils::Array::check_array_object():
250             Parameter 'descriptions' must be a array.
251             Value: %s
252             Reference: %s
253             Parameter 'descriptions' with array must contain 'Wikibase::Datatype::Value::Monolingual' objects.
254             Value: %s
255             Reference: %s
256             Parameter 'labels' must be a array.
257             Value: %s
258             Reference: %s
259             Parameter 'labels' with array must contain 'Wikibase::Datatype::Value::Monolingual' objects.
260             Value: %s
261             Reference: %s
262             Parameter 'statements' must be a array.
263             Value: %s
264             Reference: %s
265             Parameter 'statements' with array must contain 'Wikibase::Datatype::MediainfoStatement' objects.
266             Value: %s
267             Reference: %s
268              
269             =head1 EXAMPLE
270              
271             =for comment filename=create_and_print_mediainfo.pl
272              
273             use strict;
274             use warnings;
275              
276             use Unicode::UTF8 qw(decode_utf8 encode_utf8);
277             use Wikibase::Datatype::Mediainfo;
278             use Wikibase::Datatype::MediainfoSnak;
279             use Wikibase::Datatype::MediainfoStatement;
280             use Wikibase::Datatype::Value::Item;
281             use Wikibase::Datatype::Value::Monolingual;
282             use Wikibase::Datatype::Value::String;
283             use Wikibase::Datatype::Value::Time;
284              
285             # Statements.
286             my $statement1 = Wikibase::Datatype::MediainfoStatement->new(
287             # depicts (P180) beach (Q40080)
288             'snak' => Wikibase::Datatype::MediainfoSnak->new(
289             'datavalue' => Wikibase::Datatype::Value::Item->new(
290             'value' => 'Q40080',
291             ),
292             'property' => 'P180',
293             ),
294             );
295             my $statement2 = Wikibase::Datatype::MediainfoStatement->new(
296             # creator (P170)
297             'snak' => Wikibase::Datatype::MediainfoSnak->new(
298             'property' => 'P170',
299             'snaktype' => 'novalue',
300             ),
301             'property_snaks' => [
302             # Wikimedia username (P4174): Lviatour
303             Wikibase::Datatype::MediainfoSnak->new(
304             'datavalue' => Wikibase::Datatype::Value::String->new(
305             'value' => 'Lviatour',
306             ),
307             'property' => 'P4174',
308             ),
309              
310             # URL (P2699): https://commons.wikimedia.org/wiki/user:Lviatour
311             Wikibase::Datatype::MediainfoSnak->new(
312             'datavalue' => Wikibase::Datatype::Value::String->new(
313             'value' => 'https://commons.wikimedia.org/wiki/user:Lviatour',
314             ),
315             'property' => 'P2699',
316             ),
317              
318             # author name string (P2093): Lviatour
319             Wikibase::Datatype::MediainfoSnak->new(
320             'datavalue' => Wikibase::Datatype::Value::String->new(
321             'value' => 'Lviatour',
322             ),
323             'property' => 'P2093',
324             ),
325              
326             # object has role (P3831): photographer (Q33231)
327             Wikibase::Datatype::MediainfoSnak->new(
328             'datavalue' => Wikibase::Datatype::Value::Item->new(
329             'value' => 'Q33231',
330             ),
331             'property' => 'P3831',
332             ),
333             ],
334             );
335             my $statement3 = Wikibase::Datatype::MediainfoStatement->new(
336             # copyright status (P6216) copyrighted (Q50423863)
337             'snak' => Wikibase::Datatype::MediainfoSnak->new(
338             'datavalue' => Wikibase::Datatype::Value::Item->new(
339             'value' => 'Q50423863',
340             ),
341             'property' => 'P6216',
342             ),
343             );
344             my $statement4 = Wikibase::Datatype::MediainfoStatement->new(
345             # copyright license (P275) Creative Commons Attribution-ShareAlike 3.0 Unported (Q14946043)
346             'snak' => Wikibase::Datatype::MediainfoSnak->new(
347             'datavalue' => Wikibase::Datatype::Value::Item->new(
348             'value' => 'Q14946043',
349             ),
350             'property' => 'P275',
351             ),
352             );
353             my $statement5 = Wikibase::Datatype::MediainfoStatement->new(
354             # Commons quality assessment (P6731) Wikimedia Commons featured picture (Q63348049)
355             'snak' => Wikibase::Datatype::MediainfoSnak->new(
356             'datavalue' => Wikibase::Datatype::Value::Item->new(
357             'value' => 'Q63348049',
358             ),
359             'property' => 'P6731',
360             ),
361             );
362             my $statement6 = Wikibase::Datatype::MediainfoStatement->new(
363             # inception (P571) 16. 7. 2011
364             'snak' => Wikibase::Datatype::MediainfoSnak->new(
365             'datavalue' => Wikibase::Datatype::Value::Time->new(
366             'value' => '+2011-07-16T00:00:00Z',
367             ),
368             'property' => 'P571',
369             ),
370             );
371             my $statement7 = Wikibase::Datatype::MediainfoStatement->new(
372             # source of file (P7482) original creation by uploader (Q66458942)
373             'snak' => Wikibase::Datatype::MediainfoSnak->new(
374             'datavalue' => Wikibase::Datatype::Value::Item->new(
375             'value' => 'Q66458942',
376             ),
377             'property' => 'P7482',
378             ),
379             );
380              
381             # Main mediainfo.
382             my $obj = Wikibase::Datatype::Mediainfo->new(
383             'id' => 'M16041229',
384             'labels' => [
385             Wikibase::Datatype::Value::Monolingual->new(
386             'language' => 'cs',
387             'value' => decode_utf8('Pláž Papagayo, ostrov Lanzarote, Kanárské ostrovy, Španělsko'),
388             ),
389             ],
390             'lastrevid' => 528085091,
391             'modified' => '2021-01-24T11:44:10Z',
392             'page_id' => 16041229,
393             'statements' => [
394             $statement1,
395             $statement2,
396             $statement3,
397             $statement4,
398             $statement5,
399             $statement6,
400             $statement7,
401             ],
402             'title' => 'File:Lanzarote 1 Luc Viatour.jpg',
403             );
404              
405             # Print out.
406             print "Title: ".$obj->title."\n";
407             print 'Id: '.$obj->id."\n";
408             print 'Page id: '.$obj->page_id."\n";
409             print 'Modified: '.$obj->modified."\n";
410             print 'Last revision id: '.$obj->lastrevid."\n";
411             print "Labels:\n";
412             foreach my $label (sort { $a->language cmp $b->language } @{$obj->labels}) {
413             print "\t".encode_utf8($label->value).' ('.$label->language.")\n";
414             }
415             print "Statements:\n";
416             foreach my $statement (@{$obj->statements}) {
417             print "\t".$statement->snak->property.' -> ';
418             if ($statement->snak->snaktype eq 'value') {
419             print $statement->snak->datavalue->value."\n";
420             } elsif ($statement->snak->snaktype eq 'novalue') {
421             print "-\n";
422             } elsif ($statement->snak->snaktype eq 'somevalue') {
423             print "?\n";
424             }
425             if (@{$statement->property_snaks}) {
426             print "\t\tQualifers:\n";
427             foreach my $property_snak (@{$statement->property_snaks}) {
428             print "\t\t\t".$property_snak->property.' -> '.
429             $property_snak->datavalue->value."\n";
430             }
431             }
432             }
433              
434             # Output:
435             # Title: File:Lanzarote 1 Luc Viatour.jpg
436             # Id: M16041229
437             # Page id: 16041229
438             # Modified: 2021-01-24T11:44:10Z
439             # Last revision id: 528085091
440             # Labels:
441             # Pláž Papagayo, ostrov Lanzarote, Kanárské ostrovy, Španělsko (cs)
442             # Statements:
443             # P180 -> Q40080
444             # P170 -> -
445             # Qualifers:
446             # P4174 -> Lviatour
447             # P2699 -> https://commons.wikimedia.org/wiki/user:Lviatour
448             # P2093 -> Lviatour
449             # P3831 -> Q33231
450             # P6216 -> Q50423863
451             # P275 -> Q14946043
452             # P6731 -> Q63348049
453             # P571 -> +2011-07-16T00:00:00Z
454             # P7482 -> Q66458942
455              
456             =head1 DEPENDENCIES
457              
458             L<Error::Pure>,
459             L<Mo>,
460             L<Mo:utils>,
461             L<Mo:utils::Utils>.
462              
463             =head1 SEE ALSO
464              
465             =over
466              
467             =item L<Wikibase::Datatype>
468              
469             Wikibase datatypes.
470              
471             =back
472              
473             =head1 REPOSITORY
474              
475             L<https://github.com/michal-josef-spacek/Wikibase-Datatype>
476              
477             =head1 AUTHOR
478              
479             Michal Josef Špaček L<mailto:skim@cpan.org>
480              
481             L<http://skim.cz>
482              
483             =head1 LICENSE AND COPYRIGHT
484              
485             © 2020-2025 Michal Josef Špaček
486              
487             BSD 2-Clause License
488              
489             =head1 VERSION
490              
491             0.39
492              
493             =cut