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