File Coverage

blib/lib/Wikibase/Datatype/Print/Mediainfo.pm
Criterion Covered Total %
statement 36 36 100.0
branch 11 20 55.0
condition n/a
subroutine 9 9 100.0
pod 1 1 100.0
total 57 66 86.3


line stmt bran cond sub pod time code
1             package Wikibase::Datatype::Print::Mediainfo;
2              
3 3     3   932268 use base qw(Exporter);
  3         33  
  3         311  
4 3     3   20 use strict;
  3         6  
  3         58  
5 3     3   13 use warnings;
  3         6  
  3         79  
6              
7 3     3   928 use Error::Pure qw(err);
  3         22629  
  3         73  
8 3     3   113 use Readonly;
  3         6  
  3         119  
9 3     3   1355 use Wikibase::Datatype::Print::MediainfoStatement;
  3         12  
  3         183  
10 3         156 use Wikibase::Datatype::Print::Utils qw(print_descriptions print_labels
11 3     3   23 print_statements);
  3         6  
12 3     3   19 use Wikibase::Datatype::Print::Value::Monolingual;
  3         6  
  3         947  
13              
14             Readonly::Array our @EXPORT_OK => qw(print);
15              
16             our $VERSION = 0.13;
17              
18             sub print {
19 2     2 1 4640 my ($obj, $opts_hr) = @_;
20              
21 2 50       10 if (! defined $opts_hr) {
22 2         5 $opts_hr = {};
23             }
24              
25 2 50       7 if (! exists $opts_hr->{'lang'}) {
26 2         7 $opts_hr->{'lang'} = 'en';
27             }
28              
29 2 100       16 if (! $obj->isa('Wikibase::Datatype::Mediainfo')) {
30 1         11 err "Object isn't 'Wikibase::Datatype::Mediainfo'.";
31             }
32              
33 1 50       9 my @ret = (
    50          
    50          
    50          
    50          
    50          
34             defined $obj->id ? 'Id: '.$obj->id : (),
35             defined $obj->title ? 'Title: '.$obj->title : (),
36             defined $obj->ns ? 'NS: '.$obj->ns : (),
37             defined $obj->lastrevid ? 'Last revision id: '.$obj->lastrevid : (),
38             defined $obj->modified ? 'Date of modification: '.$obj->modified : (),
39             defined $obj->page_id ? 'Page ID: '.$obj->page_id : (),
40             );
41              
42             # Label.
43 1         119 push @ret, print_labels($obj, $opts_hr,
44             \&Wikibase::Datatype::Print::Value::Monolingual::print);
45              
46             # Description.
47 1         10 push @ret, print_descriptions($obj, $opts_hr,
48             \&Wikibase::Datatype::Print::Value::Monolingual::print);
49              
50             # Statements.
51 1         6 push @ret, print_statements($obj, $opts_hr,
52             \&Wikibase::Datatype::Print::MediainfoStatement::print);
53              
54 1 50       9 return wantarray ? @ret : (join "\n", @ret);
55             }
56              
57             1;
58              
59             __END__
60              
61             =pod
62              
63             =encoding utf8
64              
65             =head1 NAME
66              
67             Wikibase::Datatype::Print::Mediainfo - Wikibase mediainfo pretty print helpers.
68              
69             =head1 SYNOPSIS
70              
71             use Wikibase::Datatype::Print::Mediainfo qw(print);
72              
73             my $pretty_print_string = print($obj, $opts_hr);
74             my @pretty_print_lines = print($obj, $opts_hr);
75              
76             =head1 SUBROUTINES
77              
78             =head2 C<print>
79              
80             my $pretty_print_string = print($obj, $opts_hr);
81             my @pretty_print_lines = print($obj, $opts_hr);
82              
83             Construct pretty print output for L<Wikibase::Datatype::Mediainfo>
84             object.
85              
86             Returns string in scalar context.
87             Returns list of lines in array context.
88              
89             =head1 ERRORS
90              
91             print():
92             Object isn't 'Wikibase::Datatype::Mediainfo'.
93              
94             =head1 EXAMPLE1
95              
96             =for comment filename=create_and_print_mediainfo.pl
97              
98             use strict;
99             use warnings;
100              
101             use Unicode::UTF8 qw(decode_utf8 encode_utf8);
102             use Wikibase::Datatype::Mediainfo;
103             use Wikibase::Datatype::MediainfoSnak;
104             use Wikibase::Datatype::MediainfoStatement;
105             use Wikibase::Datatype::Print::Mediainfo;
106             use Wikibase::Datatype::Value::Item;
107             use Wikibase::Datatype::Value::Monolingual;
108             use Wikibase::Datatype::Value::String;
109             use Wikibase::Datatype::Value::Time;
110              
111             # Statements.
112             my $statement1 = Wikibase::Datatype::MediainfoStatement->new(
113             # depicts (P180) beach (Q40080)
114             'snak' => Wikibase::Datatype::MediainfoSnak->new(
115             'datavalue' => Wikibase::Datatype::Value::Item->new(
116             'value' => 'Q40080',
117             ),
118             'property' => 'P180',
119             ),
120             );
121             my $statement2 = Wikibase::Datatype::MediainfoStatement->new(
122             # creator (P170)
123             'snak' => Wikibase::Datatype::MediainfoSnak->new(
124             'property' => 'P170',
125             'snaktype' => 'novalue',
126             ),
127             'property_snaks' => [
128             # Wikimedia username (P4174): Lviatour
129             Wikibase::Datatype::MediainfoSnak->new(
130             'datavalue' => Wikibase::Datatype::Value::String->new(
131             'value' => 'Lviatour',
132             ),
133             'property' => 'P4174',
134             ),
135              
136             # URL (P2699): https://commons.wikimedia.org/wiki/user:Lviatour
137             Wikibase::Datatype::MediainfoSnak->new(
138             'datavalue' => Wikibase::Datatype::Value::String->new(
139             'value' => 'https://commons.wikimedia.org/wiki/user:Lviatour',
140             ),
141             'property' => 'P2699',
142             ),
143              
144             # author name string (P2093): Lviatour
145             Wikibase::Datatype::MediainfoSnak->new(
146             'datavalue' => Wikibase::Datatype::Value::String->new(
147             'value' => 'Lviatour',
148             ),
149             'property' => 'P2093',
150             ),
151              
152             # object has role (P3831): photographer (Q33231)
153             Wikibase::Datatype::MediainfoSnak->new(
154             'datavalue' => Wikibase::Datatype::Value::Item->new(
155             'value' => 'Q33231',
156             ),
157             'property' => 'P3831',
158             ),
159             ],
160             );
161             my $statement3 = Wikibase::Datatype::MediainfoStatement->new(
162             # copyright status (P6216) copyrighted (Q50423863)
163             'snak' => Wikibase::Datatype::MediainfoSnak->new(
164             'datavalue' => Wikibase::Datatype::Value::Item->new(
165             'value' => 'Q50423863',
166             ),
167             'property' => 'P6216',
168             ),
169             );
170             my $statement4 = Wikibase::Datatype::MediainfoStatement->new(
171             # copyright license (P275) Creative Commons Attribution-ShareAlike 3.0 Unported (Q14946043)
172             'snak' => Wikibase::Datatype::MediainfoSnak->new(
173             'datavalue' => Wikibase::Datatype::Value::Item->new(
174             'value' => 'Q14946043',
175             ),
176             'property' => 'P275',
177             ),
178             );
179             my $statement5 = Wikibase::Datatype::MediainfoStatement->new(
180             # Commons quality assessment (P6731) Wikimedia Commons featured picture (Q63348049)
181             'snak' => Wikibase::Datatype::MediainfoSnak->new(
182             'datavalue' => Wikibase::Datatype::Value::Item->new(
183             'value' => 'Q63348049',
184             ),
185             'property' => 'P6731',
186             ),
187             );
188             my $statement6 = Wikibase::Datatype::MediainfoStatement->new(
189             # inception (P571) 16. 7. 2011
190             'snak' => Wikibase::Datatype::MediainfoSnak->new(
191             'datavalue' => Wikibase::Datatype::Value::Time->new(
192             'value' => '+2011-07-16T00:00:00Z',
193             ),
194             'property' => 'P571',
195             ),
196             );
197             my $statement7 = Wikibase::Datatype::MediainfoStatement->new(
198             # source of file (P7482) original creation by uploader (Q66458942)
199             'snak' => Wikibase::Datatype::MediainfoSnak->new(
200             'datavalue' => Wikibase::Datatype::Value::Item->new(
201             'value' => 'Q66458942',
202             ),
203             'property' => 'P7482',
204             ),
205             );
206              
207             # Main mediainfo.
208             my $obj = Wikibase::Datatype::Mediainfo->new(
209             'id' => 'M16041229',
210             'labels' => [
211             Wikibase::Datatype::Value::Monolingual->new(
212             'language' => 'cs',
213             'value' => decode_utf8('Pláž Papagayo, ostrov Lanzarote, Kanárské ostrovy, Španělsko'),
214             ),
215             ],
216             'lastrevid' => 528085091,
217             'modified' => '2021-01-24T11:44:10Z',
218             'page_id' => 16041229,
219             'statements' => [
220             $statement1,
221             $statement2,
222             $statement3,
223             $statement4,
224             $statement5,
225             $statement6,
226             $statement7,
227             ],
228             'title' => 'File:Lanzarote 1 Luc Viatour.jpg',
229             );
230              
231             # Print.
232             print Wikibase::Datatype::Print::Mediainfo::print($obj)."\n";
233              
234             # Output:
235             # Id: M16041229
236             # Title: File:Lanzarote 1 Luc Viatour.jpg
237             # NS: 6
238             # Last revision id: 528085091
239             # Date of modification: 2021-01-24T11:44:10Z
240             # Page ID: 16041229
241             # Statements:
242             # P180: Q40080 (normal)
243             # P170: no value (normal)
244             # P4174: Lviatour
245             # P2699: https://commons.wikimedia.org/wiki/user:Lviatour
246             # P2093: Lviatour
247             # P3831: Q33231
248             # P6216: Q50423863 (normal)
249             # P275: Q14946043 (normal)
250             # P6731: Q63348049 (normal)
251             # P571: 16 July 2011 (Q1985727) (normal)
252             # P7482: Q66458942 (normal)
253              
254             =head1 EXAMPLE2
255              
256             =for comment filename=create_and_print_mediainfo_translated.pl
257              
258             use strict;
259             use warnings;
260              
261             use Unicode::UTF8 qw(decode_utf8 encode_utf8);
262             use Wikibase::Cache;
263             use Wikibase::Cache::Backend::Basic;
264             use Wikibase::Datatype::Mediainfo;
265             use Wikibase::Datatype::MediainfoSnak;
266             use Wikibase::Datatype::MediainfoStatement;
267             use Wikibase::Datatype::Print::Mediainfo;
268             use Wikibase::Datatype::Value::Item;
269             use Wikibase::Datatype::Value::Monolingual;
270             use Wikibase::Datatype::Value::String;
271             use Wikibase::Datatype::Value::Time;
272              
273             # Statements.
274             my $statement1 = Wikibase::Datatype::MediainfoStatement->new(
275             # depicts (P180) beach (Q40080)
276             'snak' => Wikibase::Datatype::MediainfoSnak->new(
277             'datavalue' => Wikibase::Datatype::Value::Item->new(
278             'value' => 'Q40080',
279             ),
280             'property' => 'P180',
281             ),
282             );
283             my $statement2 = Wikibase::Datatype::MediainfoStatement->new(
284             # creator (P170)
285             'snak' => Wikibase::Datatype::MediainfoSnak->new(
286             'property' => 'P170',
287             'snaktype' => 'novalue',
288             ),
289             'property_snaks' => [
290             # Wikimedia username (P4174): Lviatour
291             Wikibase::Datatype::MediainfoSnak->new(
292             'datavalue' => Wikibase::Datatype::Value::String->new(
293             'value' => 'Lviatour',
294             ),
295             'property' => 'P4174',
296             ),
297              
298             # URL (P2699): https://commons.wikimedia.org/wiki/user:Lviatour
299             Wikibase::Datatype::MediainfoSnak->new(
300             'datavalue' => Wikibase::Datatype::Value::String->new(
301             'value' => 'https://commons.wikimedia.org/wiki/user:Lviatour',
302             ),
303             'property' => 'P2699',
304             ),
305              
306             # author name string (P2093): Lviatour
307             Wikibase::Datatype::MediainfoSnak->new(
308             'datavalue' => Wikibase::Datatype::Value::String->new(
309             'value' => 'Lviatour',
310             ),
311             'property' => 'P2093',
312             ),
313              
314             # object has role (P3831): photographer (Q33231)
315             Wikibase::Datatype::MediainfoSnak->new(
316             'datavalue' => Wikibase::Datatype::Value::Item->new(
317             'value' => 'Q33231',
318             ),
319             'property' => 'P3831',
320             ),
321             ],
322             );
323             my $statement3 = Wikibase::Datatype::MediainfoStatement->new(
324             # copyright status (P6216) copyrighted (Q50423863)
325             'snak' => Wikibase::Datatype::MediainfoSnak->new(
326             'datavalue' => Wikibase::Datatype::Value::Item->new(
327             'value' => 'Q50423863',
328             ),
329             'property' => 'P6216',
330             ),
331             );
332             my $statement4 = Wikibase::Datatype::MediainfoStatement->new(
333             # copyright license (P275) Creative Commons Attribution-ShareAlike 3.0 Unported (Q14946043)
334             'snak' => Wikibase::Datatype::MediainfoSnak->new(
335             'datavalue' => Wikibase::Datatype::Value::Item->new(
336             'value' => 'Q14946043',
337             ),
338             'property' => 'P275',
339             ),
340             );
341             my $statement5 = Wikibase::Datatype::MediainfoStatement->new(
342             # Commons quality assessment (P6731) Wikimedia Commons featured picture (Q63348049)
343             'snak' => Wikibase::Datatype::MediainfoSnak->new(
344             'datavalue' => Wikibase::Datatype::Value::Item->new(
345             'value' => 'Q63348049',
346             ),
347             'property' => 'P6731',
348             ),
349             );
350             my $statement6 = Wikibase::Datatype::MediainfoStatement->new(
351             # inception (P571) 16. 7. 2011
352             'snak' => Wikibase::Datatype::MediainfoSnak->new(
353             'datavalue' => Wikibase::Datatype::Value::Time->new(
354             'value' => '+2011-07-16T00:00:00Z',
355             ),
356             'property' => 'P571',
357             ),
358             );
359             my $statement7 = Wikibase::Datatype::MediainfoStatement->new(
360             # source of file (P7482) original creation by uploader (Q66458942)
361             'snak' => Wikibase::Datatype::MediainfoSnak->new(
362             'datavalue' => Wikibase::Datatype::Value::Item->new(
363             'value' => 'Q66458942',
364             ),
365             'property' => 'P7482',
366             ),
367             );
368              
369             # Main mediainfo.
370             my $obj = Wikibase::Datatype::Mediainfo->new(
371             'id' => 'M16041229',
372             'labels' => [
373             Wikibase::Datatype::Value::Monolingual->new(
374             'language' => 'cs',
375             'value' => decode_utf8('Pláž Papagayo, ostrov Lanzarote, Kanárské ostrovy, Španělsko'),
376             ),
377             ],
378             'lastrevid' => 528085091,
379             'modified' => '2021-01-24T11:44:10Z',
380             'page_id' => 16041229,
381             'statements' => [
382             $statement1,
383             $statement2,
384             $statement3,
385             $statement4,
386             $statement5,
387             $statement6,
388             $statement7,
389             ],
390             'title' => 'File:Lanzarote 1 Luc Viatour.jpg',
391             );
392              
393             # Cache.
394             my $cache = Wikibase::Cache->new(
395             'backend' => 'Basic',
396             );
397              
398             # Print.
399             print Wikibase::Datatype::Print::Mediainfo::print($obj, {
400             'cache' => $cache,
401             })."\n";
402              
403             # Output:
404             # Id: M16041229
405             # Title: File:Lanzarote 1 Luc Viatour.jpg
406             # NS: 6
407             # Last revision id: 528085091
408             # Date of modification: 2021-01-24T11:44:10Z
409             # Page ID: 16041229
410             # Statements:
411             # P180 (depicts): Q40080 (normal)
412             # P170: no value (normal)
413             # P4174: Lviatour
414             # P2699: https://commons.wikimedia.org/wiki/user:Lviatour
415             # P2093: Lviatour
416             # P3831: Q33231
417             # P6216: Q50423863 (normal)
418             # P275: Q14946043 (normal)
419             # P6731: Q63348049 (normal)
420             # P571: 16 July 2011 (Q1985727) (normal)
421             # P7482: Q66458942 (normal)
422              
423             =head1 DEPENDENCIES
424              
425             L<Exporter>,
426             L<Error::Pure>,
427             L<Readonly>,
428             L<Wikibase::Datatype::Print::MediainfoStatement>,
429             L<Wikibase::Datatype::Print::Utils>,
430             L<Wikibase::Datatype::Print::Value::Monolingual>.
431              
432             =head1 SEE ALSO
433              
434             =over
435              
436             =item L<Wikibase::Datatype::Mediainfo>
437              
438             Wikibase mediainfo datatype.
439              
440             =back
441              
442             =head1 REPOSITORY
443              
444             L<https://github.com/michal-josef-spacek/Wikibase-Datatype-Print>
445              
446             =head1 AUTHOR
447              
448             Michal Josef Špaček L<mailto:skim@cpan.org>
449              
450             L<http://skim.cz>
451              
452             =head1 LICENSE AND COPYRIGHT
453              
454             © 2020-2023 Michal Josef Špaček
455              
456             BSD 2-Clause License
457              
458             =head1 VERSION
459              
460             0.13
461              
462             =cut