File Coverage

blib/lib/Wikibase/Datatype/Print/Lexeme.pm
Criterion Covered Total %
statement 48 48 100.0
branch 7 12 58.3
condition n/a
subroutine 11 11 100.0
pod 1 1 100.0
total 67 72 93.0


line stmt bran cond sub pod time code
1             package Wikibase::Datatype::Print::Lexeme;
2              
3 3     3   912785 use base qw(Exporter);
  3         32  
  3         320  
4 3     3   19 use strict;
  3         7  
  3         61  
5 3     3   13 use warnings;
  3         7  
  3         76  
6              
7 3     3   876 use Error::Pure qw(err);
  3         22235  
  3         80  
8 3     3   119 use Readonly;
  3         6  
  3         106  
9 3     3   1392 use Wikibase::Datatype::Print::Form;
  3         11  
  3         143  
10 3     3   1294 use Wikibase::Datatype::Print::Sense;
  3         10  
  3         124  
11 3     3   19 use Wikibase::Datatype::Print::Statement;
  3         6  
  3         89  
12 3     3   19 use Wikibase::Datatype::Print::Utils qw(print_forms print_senses print_statements);
  3         8  
  3         119  
13 3     3   16 use Wikibase::Datatype::Print::Value::Monolingual;
  3         8  
  3         856  
14              
15             Readonly::Array our @EXPORT_OK => qw(print);
16              
17             our $VERSION = 0.13;
18              
19             sub print {
20 2     2 1 14872 my ($obj, $opts_hr) = @_;
21              
22 2 50       8 if (! defined $opts_hr) {
23 2         5 $opts_hr = {};
24             }
25              
26 2 100       13 if (! $obj->isa('Wikibase::Datatype::Lexeme')) {
27 1         5 err "Object isn't 'Wikibase::Datatype::Lexeme'.";
28             }
29              
30 1         7 my @ret = (
31             'Title: '.$obj->title,
32             );
33              
34             # Lemmas.
35 1         10 my ($lemma) = @{$obj->lemmas};
  1         5  
36 1 50       12 if (defined $lemma) {
37 1         5 push @ret, 'Lemmas: '.
38             Wikibase::Datatype::Print::Value::Monolingual::print($lemma, $opts_hr);
39             }
40              
41             # Language.
42 1 50       17 if ($obj->language) {
43 1         10 push @ret, (
44             'Language: '.$obj->language,
45             );
46             }
47              
48             # Lexical category.
49 1 50       10 if ($obj->lexical_category) {
50 1         8 push @ret, (
51             'Lexical category: '.$obj->lexical_category,
52             );
53             }
54              
55             # Statements.
56 1         10 push @ret, print_statements($obj, $opts_hr,
57             \&Wikibase::Datatype::Print::Statement::print);
58              
59             # Senses.
60 1         5 push @ret, print_senses($obj, $opts_hr,
61             \&Wikibase::Datatype::Print::Sense::print);
62              
63             # Forms.
64 1         5 push @ret, print_forms($obj, $opts_hr,
65             \&Wikibase::Datatype::Print::Form::print);
66              
67 1 50       14 return wantarray ? @ret : (join "\n", @ret);
68             }
69              
70             1;
71              
72             __END__
73              
74             =pod
75              
76             =encoding utf8
77              
78             =head1 NAME
79              
80             Wikibase::Datatype::Print::Lexeme - Wikibase lexeme pretty print helpers.
81              
82             =head1 SYNOPSIS
83              
84             use Wikibase::Datatype::Print::Lexeme qw(print);
85              
86             my $pretty_print_string = print($obj, $opts_hr);
87             my @pretty_print_lines = print($obj, $opts_hr);
88              
89             =head1 SUBROUTINES
90              
91             =head2 C<print>
92              
93             my $pretty_print_string = print($obj, $opts_hr);
94             my @pretty_print_lines = print($obj, $opts_hr);
95              
96             Construct pretty print output for L<Wikibase::Datatype::Lexeme>
97             object.
98              
99             Returns string in scalar context.
100             Returns list of lines in array context.
101              
102             =head1 ERRORS
103              
104             print():
105             Object isn't 'Wikibase::Datatype::Lexeme'.
106              
107             =head1 EXAMPLE
108              
109             =for comment filename=create_and_print_lexeme.pl
110              
111             use strict;
112             use warnings;
113              
114             use Wikibase::Datatype::Lexeme;
115             use Wikibase::Datatype::Print::Lexeme;
116             use Wikibase::Datatype::Reference;
117             use Wikibase::Datatype::Snak;
118             use Wikibase::Datatype::Statement;
119             use Wikibase::Datatype::Value::Item;
120             use Wikibase::Datatype::Value::Monolingual;
121             use Wikibase::Datatype::Value::String;
122             use Wikibase::Datatype::Value::Time;
123              
124             # Statements.
125             my $statement1 = Wikibase::Datatype::Statement->new(
126             # instance of (P31) human (Q5)
127             'snak' => Wikibase::Datatype::Snak->new(
128             'datatype' => 'wikibase-item',
129             'datavalue' => Wikibase::Datatype::Value::Item->new(
130             'value' => 'Q5',
131             ),
132             'property' => 'P31',
133             ),
134             'property_snaks' => [
135             # of (P642) alien (Q474741)
136             Wikibase::Datatype::Snak->new(
137             'datatype' => 'wikibase-item',
138             'datavalue' => Wikibase::Datatype::Value::Item->new(
139             'value' => 'Q474741',
140             ),
141             'property' => 'P642',
142             ),
143             ],
144             'references' => [
145             Wikibase::Datatype::Reference->new(
146             'snaks' => [
147             # stated in (P248) Virtual International Authority File (Q53919)
148             Wikibase::Datatype::Snak->new(
149             'datatype' => 'wikibase-item',
150             'datavalue' => Wikibase::Datatype::Value::Item->new(
151             'value' => 'Q53919',
152             ),
153             'property' => 'P248',
154             ),
155              
156             # VIAF ID (P214) 113230702
157             Wikibase::Datatype::Snak->new(
158             'datatype' => 'external-id',
159             'datavalue' => Wikibase::Datatype::Value::String->new(
160             'value' => '113230702',
161             ),
162             'property' => 'P214',
163             ),
164              
165             # retrieved (P813) 7 December 2013
166             Wikibase::Datatype::Snak->new(
167             'datatype' => 'time',
168             'datavalue' => Wikibase::Datatype::Value::Time->new(
169             'value' => '+2013-12-07T00:00:00Z',
170             ),
171             'property' => 'P813',
172             ),
173             ],
174             ),
175             ],
176             );
177             my $statement2 = Wikibase::Datatype::Statement->new(
178             # sex or gender (P21) male (Q6581097)
179             'snak' => Wikibase::Datatype::Snak->new(
180             'datatype' => 'wikibase-item',
181             'datavalue' => Wikibase::Datatype::Value::Item->new(
182             'value' => 'Q6581097',
183             ),
184             'property' => 'P21',
185             ),
186             'references' => [
187             Wikibase::Datatype::Reference->new(
188             'snaks' => [
189             # stated in (P248) Virtual International Authority File (Q53919)
190             Wikibase::Datatype::Snak->new(
191             'datatype' => 'wikibase-item',
192             'datavalue' => Wikibase::Datatype::Value::Item->new(
193             'value' => 'Q53919',
194             ),
195             'property' => 'P248',
196             ),
197              
198             # VIAF ID (P214) 113230702
199             Wikibase::Datatype::Snak->new(
200             'datatype' => 'external-id',
201             'datavalue' => Wikibase::Datatype::Value::String->new(
202             'value' => '113230702',
203             ),
204             'property' => 'P214',
205             ),
206              
207             # retrieved (P813) 7 December 2013
208             Wikibase::Datatype::Snak->new(
209             'datatype' => 'time',
210             'datavalue' => Wikibase::Datatype::Value::Time->new(
211             'value' => '+2013-12-07T00:00:00Z',
212             ),
213             'property' => 'P813',
214             ),
215             ],
216             ),
217             ],
218             );
219              
220             # Object.
221             my $obj = Wikibase::Datatype::Lexeme->new(
222             'id' => 'L469',
223             'lemmas' => [
224             Wikibase::Datatype::Value::Monolingual->new(
225             'language' => 'cs',
226             'value' => 'pes',
227             ),
228             ],
229             'statements' => [
230             $statement1,
231             $statement2,
232             ],
233             'title' => 'Lexeme:L469',
234             );
235              
236             # Print.
237             print Wikibase::Datatype::Print::Lexeme::print($obj)."\n";
238              
239             # Output:
240             # Title: Lexeme:L469
241             # Lemmas: pes (cs)
242             # Statements:
243             # P31: Q5 (normal)
244             # P642: Q474741
245             # References:
246             # {
247             # P248: Q53919
248             # P214: 113230702
249             # P813: 7 December 2013 (Q1985727)
250             # }
251             # P21: Q6581097 (normal)
252             # References:
253             # {
254             # P248: Q53919
255             # P214: 113230702
256             # P813: 7 December 2013 (Q1985727)
257             # }
258              
259             =head1 DEPENDENCIES
260              
261             L<Error::Pure>,
262             L<Exporter>,
263             L<Readonly>,
264             L<Wikibase::Datatype::Print::Form>,
265             L<Wikibase::Datatype::Print::Sense>,
266             L<Wikibase::Datatype::Print::Statement>,
267             L<Wikibase::Datatype::Print::Utils>,
268             L<Wikibase::Datatype::Print::Value::Monolingual>.
269              
270             =head1 SEE ALSO
271              
272             =over
273              
274             =item L<Wikibase::Datatype::Lexeme>
275              
276             Wikibase lexeme datatype.
277              
278             =back
279              
280             =head1 REPOSITORY
281              
282             L<https://github.com/michal-josef-spacek/Wikibase-Datatype-Print>
283              
284             =head1 AUTHOR
285              
286             Michal Josef Špaček L<mailto:skim@cpan.org>
287              
288             L<http://skim.cz>
289              
290             =head1 LICENSE AND COPYRIGHT
291              
292             © 2020-2023 Michal Josef Špaček
293              
294             BSD 2-Clause License
295              
296             =head1 VERSION
297              
298             0.13
299              
300             =cut
301