File Coverage

blib/lib/Wikibase/Datatype/Print/MediainfoStatement.pm
Criterion Covered Total %
statement 32 33 96.9
branch 3 4 75.0
condition n/a
subroutine 9 9 100.0
pod 1 1 100.0
total 45 47 95.7


line stmt bran cond sub pod time code
1             package Wikibase::Datatype::Print::MediainfoStatement;
2              
3 6     6   919831 use base qw(Exporter);
  6         44  
  6         654  
4 6     6   38 use strict;
  6         14  
  6         115  
5 6     6   27 use warnings;
  6         14  
  6         167  
6              
7 6     6   914 use Error::Pure qw(err);
  6         22587  
  6         235  
8 6     6   145 use Readonly;
  6         14  
  6         240  
9 6     6   3157 use Wikibase::Datatype::Print::Reference;
  6         25  
  6         311  
10 6     6   3104 use Wikibase::Datatype::Print::MediainfoSnak;
  6         19  
  6         278  
11 6     6   2736 use Wikibase::Datatype::Print::Utils qw(print_references);
  6         17  
  6         142  
12              
13             Readonly::Array our @EXPORT_OK => qw(print);
14              
15             our $VERSION = 0.13;
16              
17             sub print {
18 3     3 1 1851 my ($obj, $opts_hr) = @_;
19              
20 3 100       23 if (! $obj->isa('Wikibase::Datatype::MediainfoStatement')) {
21 1         7 err "Object isn't 'Wikibase::Datatype::MediainfoStatement'.";
22             }
23              
24 2         17 my @ret = (
25             Wikibase::Datatype::Print::MediainfoSnak::print($obj->snak, $opts_hr).' ('.$obj->rank.')',
26             );
27 2         36 foreach my $property_snak (@{$obj->property_snaks}) {
  2         11  
28 0         0 push @ret, ' '.Wikibase::Datatype::Print::MediainfoSnak::print($property_snak, $opts_hr);
29             }
30              
31             # References.
32 2         32 push @ret, print_references($obj, $opts_hr,
33             \&Wikibase::Datatype::Print::Reference::print);
34              
35 2 50       12 return wantarray ? @ret : (join "\n", @ret);
36             }
37              
38             1;
39              
40             __END__
41              
42             =pod
43              
44             =encoding utf8
45              
46             =head1 NAME
47              
48             Wikibase::Datatype::Print::MediainfoStatement - Wikibase mediainfo statement pretty print helpers.
49              
50             =head1 SYNOPSIS
51              
52             use Wikibase::Datatype::Print::MediainfoStatement qw(print);
53              
54             my $pretty_print_string = print($obj, $opts_hr);
55             my @pretty_print_lines = print($obj, $opts_hr);
56              
57             =head1 SUBROUTINES
58              
59             =head2 C<print>
60              
61             my $pretty_print_string = print($obj, $opts_hr);
62             my @pretty_print_lines = print($obj, $opts_hr);
63              
64             Construct pretty print output for L<Wikibase::Datatype::MediainfoStatement>
65             object.
66              
67             Returns string in scalar context.
68             Returns list of lines in array context.
69              
70             =head1 ERRORS
71              
72             print():
73             Object isn't 'Wikibase::Datatype::MediainfoStatement'.
74              
75             =head1 EXAMPLE1
76              
77             =for comment filename=create_and_print_mediainfo_statement.pl
78              
79             use strict;
80             use warnings;
81              
82             use Wikibase::Datatype::MediainfoSnak;
83             use Wikibase::Datatype::MediainfoStatement;
84             use Wikibase::Datatype::Print::MediainfoStatement;
85             use Wikibase::Datatype::Value::Item;
86             use Wikibase::Datatype::Value::String;
87              
88             # Object.
89             my $obj = Wikibase::Datatype::MediainfoStatement->new(
90             'id' => 'M123$00C04D2A-49AF-40C2-9930-C551916887E8',
91              
92             # creator (P170)
93             'snak' => Wikibase::Datatype::MediainfoSnak->new(
94             'property' => 'P170',
95             'snaktype' => 'novalue',
96             ),
97             'property_snaks' => [
98             # Wikimedia username (P4174): Lviatour
99             Wikibase::Datatype::MediainfoSnak->new(
100             'datavalue' => Wikibase::Datatype::Value::String->new(
101             'value' => 'Lviatour',
102             ),
103             'property' => 'P4174',
104             ),
105              
106             # URL (P2699): https://commons.wikimedia.org/wiki/user:Lviatour
107             Wikibase::Datatype::MediainfoSnak->new(
108             'datavalue' => Wikibase::Datatype::Value::String->new(
109             'value' => 'https://commons.wikimedia.org/wiki/user:Lviatour',
110             ),
111             'property' => 'P2699',
112             ),
113              
114             # author name string (P2093): Lviatour
115             Wikibase::Datatype::MediainfoSnak->new(
116             'datavalue' => Wikibase::Datatype::Value::String->new(
117             'value' => 'Lviatour',
118             ),
119             'property' => 'P2093',
120             ),
121              
122             # object has role (P3831): photographer (Q33231)
123             Wikibase::Datatype::MediainfoSnak->new(
124             'datavalue' => Wikibase::Datatype::Value::Item->new(
125             'value' => 'Q33231',
126             ),
127             'property' => 'P3831',
128             ),
129             ],
130             );
131              
132             # Print.
133             print Wikibase::Datatype::Print::MediainfoStatement::print($obj)."\n";
134              
135             # Output:
136             # P170: no value (normal)
137             # P4174: Lviatour
138             # P2699: https://commons.wikimedia.org/wiki/user:Lviatour
139             # P2093: Lviatour
140             # P3831: Q33231
141              
142             =head1 EXAMPLE2
143              
144             =for comment filename=create_and_print_mediainfo_statement_translated.pl
145              
146             use strict;
147             use warnings;
148              
149             use Wikibase::Cache;
150             use Wikibase::Cache::Backend::Basic;
151             use Wikibase::Datatype::MediainfoSnak;
152             use Wikibase::Datatype::MediainfoStatement;
153             use Wikibase::Datatype::Print::MediainfoStatement;
154             use Wikibase::Datatype::Value::Item;
155             use Wikibase::Datatype::Value::String;
156              
157             # Object.
158             my $obj = Wikibase::Datatype::MediainfoStatement->new(
159             'id' => 'M123$00C04D2A-49AF-40C2-9930-C551916887E8',
160              
161             # creator (P170)
162             'snak' => Wikibase::Datatype::MediainfoSnak->new(
163             'property' => 'P170',
164             'snaktype' => 'novalue',
165             ),
166             'property_snaks' => [
167             # Wikimedia username (P4174): Lviatour
168             Wikibase::Datatype::MediainfoSnak->new(
169             'datavalue' => Wikibase::Datatype::Value::String->new(
170             'value' => 'Lviatour',
171             ),
172             'property' => 'P4174',
173             ),
174              
175             # URL (P2699): https://commons.wikimedia.org/wiki/user:Lviatour
176             Wikibase::Datatype::MediainfoSnak->new(
177             'datavalue' => Wikibase::Datatype::Value::String->new(
178             'value' => 'https://commons.wikimedia.org/wiki/user:Lviatour',
179             ),
180             'property' => 'P2699',
181             ),
182              
183             # author name string (P2093): Lviatour
184             Wikibase::Datatype::MediainfoSnak->new(
185             'datavalue' => Wikibase::Datatype::Value::String->new(
186             'value' => 'Lviatour',
187             ),
188             'property' => 'P2093',
189             ),
190              
191             # object has role (P3831): photographer (Q33231)
192             Wikibase::Datatype::MediainfoSnak->new(
193             'datavalue' => Wikibase::Datatype::Value::Item->new(
194             'value' => 'Q33231',
195             ),
196             'property' => 'P3831',
197             ),
198             ],
199             );
200              
201             # Cache.
202             my $cache = Wikibase::Cache->new(
203             'backend' => 'Basic',
204             );
205              
206             # Print.
207             print Wikibase::Datatype::Print::MediainfoStatement::print($obj, {
208             'cache' => $cache,
209             })."\n";
210              
211             # Output:
212             # P170: no value (normal)
213             # P4174: Lviatour
214             # P2699: https://commons.wikimedia.org/wiki/user:Lviatour
215             # P2093: Lviatour
216             # P3831: Q33231
217              
218             =head1 DEPENDENCIES
219              
220             L<Error::Pure>,
221             L<Exporter>,
222             L<Readonly>,
223             L<Wikibase::Datatype::Print::Reference>,
224             L<Wikibase::Datatype::Print::MediainfoSnak>,
225             L<Wikibase::Datatype::Print::Utils>.
226              
227             =head1 SEE ALSO
228              
229             =over
230              
231             =item L<Wikibase::Datatype::MediainfoStatement>
232              
233             Wikibase statement datatype.
234              
235             =back
236              
237             =head1 REPOSITORY
238              
239             L<https://github.com/michal-josef-spacek/Wikibase-Datatype-Print>
240              
241             =head1 AUTHOR
242              
243             Michal Josef Špaček L<mailto:skim@cpan.org>
244              
245             L<http://skim.cz>
246              
247             =head1 LICENSE AND COPYRIGHT
248              
249             © 2020-2023 Michal Josef Špaček
250              
251             BSD 2-Clause License
252              
253             =head1 VERSION
254              
255             0.13
256              
257             =cut
258