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