File Coverage

blib/lib/Wikibase/Datatype/Form.pm
Criterion Covered Total %
statement 17 17 100.0
branch n/a
condition n/a
subroutine 5 5 100.0
pod 0 1 0.0
total 22 23 95.6


line stmt bran cond sub pod time code
1             package Wikibase::Datatype::Form;
2              
3 26     26   790696 use strict;
  26         125  
  26         795  
4 26     26   141 use warnings;
  26         69  
  26         761  
5              
6 26     26   4386 use Mo qw(build default is);
  26         5274  
  26         181  
7 26     26   31637 use Mo::utils qw(check_array_object);
  26         119200  
  26         3240  
8              
9             our $VERSION = 0.31;
10              
11             has grammatical_features => (
12             default => [],
13             is => 'ro',
14             );
15              
16             has id => (
17             is => 'ro',
18             );
19              
20             has representations => (
21             default => [],
22             is => 'ro',
23             );
24              
25             has statements => (
26             default => [],
27             is => 'ro',
28             );
29              
30             sub BUILD {
31 34     34 0 12331 my $self = shift;
32              
33             # Check grammatical features.
34 34         166 check_array_object($self, 'grammatical_features',
35             'Wikibase::Datatype::Value::Item', 'Grammatical feature');
36              
37             # Check representations.
38 32         851 check_array_object($self, 'representations',
39             'Wikibase::Datatype::Value::Monolingual', 'Representation');
40              
41             # Check statements.
42 30         552 check_array_object($self, 'statements', 'Wikibase::Datatype::Statement',
43             'Statement');
44              
45 28         438 return;
46             }
47              
48             1;
49              
50             __END__
51              
52             =pod
53              
54             =encoding utf8
55              
56             =head1 NAME
57              
58             Wikibase::Datatype::Form - Wikibase form datatype.
59              
60             =head1 SYNOPSIS
61              
62             use Wikibase::Datatype::Form;
63              
64             my $obj = Wikibase::Datatype::Form->new(%params);
65             my $grammatical_features_ar = $obj->grammatical_features;
66             my $id = $obj->id;
67             my $representations_ar = $obj->representations;
68             my $statements_ar = $obj->statements;
69              
70             =head1 METHODS
71              
72             =head2 C<new>
73              
74             my $obj = Wikibase::Datatype::Form->new(%params);
75              
76             Constructor.
77              
78             Returns instance of object.
79              
80             =over 8
81              
82             =item * C<grammatical_features>
83              
84             Grammatical features.
85             Items of array are Q items.
86             Parameter is optional.
87              
88             =item * C<id>
89              
90             Identifier of form.
91             Parameter is optional.
92              
93             =item * C<representations>
94              
95             Representations.
96             Items of array are Wikibase::Datatype::Value::Monolingual items.
97             Parameter is optional.
98              
99             =item * C<statements>
100              
101             Statements.
102             Items of array are Wikibase:Datatype::Statement items.
103             Parameter is optional.
104              
105             =back
106              
107             =head2 C<grammatical_features>
108              
109             my $grammatical_features_ar = $obj->grammatical_features;
110              
111             Get grammatical features.
112              
113             Returns reference to array of Q items.
114              
115             =head2 C<id>
116              
117             my $id = $obj->id;
118              
119             Get form identifier.
120              
121             Returns string.
122              
123             =head2 C<representations>
124              
125             my $representations_ar = $obj->representations;
126              
127             Get representations.
128              
129             Returns reference to array with Wikibase::Datatype::Value::Monolingual items.
130              
131             =head2 C<statements>
132              
133             my $statements_ar = $obj->statements;
134              
135             Get statements.
136              
137             Returns reference to array of Wikibase::Datatype::Statement items.
138              
139             =head1 ERRORS
140              
141             new():
142             From Mo::utils::check_array_object():
143             Grammatical feature isn't 'Wikibase::Datatype::Value::Item' object.
144             Parameter 'grammatical_features' must be a array.
145             Parameter 'representations' must be a array.
146             Parameter 'statements' must be a array.
147             Representation isn't 'Wikibase::Datatype::Value::Monolingual' object.
148             Statement isn't 'Wikibase::Datatype::Statement' object.
149              
150             =head1 EXAMPLE
151              
152             =for comment filename=create_and_print_form.pl
153              
154             use strict;
155             use warnings;
156              
157             use Unicode::UTF8 qw(decode_utf8);
158             use Wikibase::Datatype::Form;
159             use Wikibase::Datatype::Snak;
160             use Wikibase::Datatype::Statement;
161             use Wikibase::Datatype::Value::Item;
162             use Wikibase::Datatype::Value::String;
163             use Wikibase::Datatype::Value::Monolingual;
164              
165             # Object.
166             my $obj = Wikibase::Datatype::Form->new(
167             'grammatical_features' => [
168             # singular
169             Wikibase::Datatype::Value::Item->new(
170             'value' => 'Q110786',
171             ),
172             # nominative case
173             Wikibase::Datatype::Value::Item->new(
174             'value' => 'Q131105',
175             ),
176             ],
177             'id' => 'L469-F1',
178             'representations' => [
179             Wikibase::Datatype::Value::Monolingual->new(
180             'language' => 'cs',
181             'value' => 'pes',
182             ),
183             ],
184             'statements' => [
185             Wikibase::Datatype::Statement->new(
186             'snak' => Wikibase::Datatype::Snak->new(
187             'datatype' => 'string',
188             'datavalue' => Wikibase::Datatype::Value::String->new(
189             'value' => decode_utf8('pɛs'),
190             ),
191             'property' => 'P898',
192             ),
193             ),
194             ],
195             );
196              
197             # Get id.
198             my $id = $obj->id;
199              
200             # Get counts.
201             my $gr_count = @{$obj->grammatical_features};
202             my $re_count = @{$obj->representations};
203             my $st_count = @{$obj->statements};
204              
205             # Print out.
206             print "Id: $id\n";
207             print "Number of grammatical features: $gr_count\n";
208             print "Number of representations: $re_count\n";
209             print "Number of statements: $st_count\n";
210              
211             # Output:
212             # Id: L469-F1
213             # Number of grammatical features: 2
214             # Number of representations: 1
215             # Number of statements: 1
216              
217             =head1 DEPENDENCIES
218              
219             L<Mo>,
220             L<Mo::utils>.
221              
222             =head1 SEE ALSO
223              
224             =over
225              
226             =item L<Wikibase::Datatype>
227              
228             Wikibase datatypes.
229              
230             =back
231              
232             =head1 REPOSITORY
233              
234             L<https://github.com/michal-josef-spacek/Wikibase-Datatype>
235              
236             =head1 AUTHOR
237              
238             Michal Josef Špaček L<mailto:skim@cpan.org>
239              
240             L<http://skim.cz>
241              
242             =head1 LICENSE AND COPYRIGHT
243              
244             © 2020-2023 Michal Josef Špaček
245              
246             BSD 2-Clause License
247              
248             =head1 VERSION
249              
250             0.31
251              
252             =cut