File Coverage

blib/lib/Wikibase/Datatype/Reference.pm
Criterion Covered Total %
statement 19 19 100.0
branch n/a
condition n/a
subroutine 6 6 100.0
pod 0 1 0.0
total 25 26 96.1


line stmt bran cond sub pod time code
1             package Wikibase::Datatype::Reference;
2              
3 42     42   352039 use strict;
  42         147  
  42         1195  
4 42     42   237 use warnings;
  42         118  
  42         1257  
5              
6 42     42   4791 use Error::Pure qw(err);
  42         105894  
  42         1523  
7 42     42   5196 use Mo qw(build is);
  42         5641  
  42         255  
8 42     42   28104 use Mo::utils qw(check_array_object check_required);
  42         14366  
  42         4703  
9              
10             our $VERSION = 0.29;
11              
12             has snaks => (
13             is => 'ro',
14             );
15              
16             sub BUILD {
17 31     31 0 7309 my $self = shift;
18              
19 31         144 check_required($self, 'snaks');
20              
21 30         397 check_array_object($self, 'snaks', 'Wikibase::Datatype::Snak', 'Snak');
22              
23 28         814 return;
24             }
25              
26             1;
27              
28             __END__
29              
30             =pod
31              
32             =encoding utf8
33              
34             =head1 NAME
35              
36             Wikibase::Datatype::Reference - Wikibase reference datatype.
37              
38             =head1 SYNOPSIS
39              
40             use Wikibase::Datatype::Reference;
41              
42             my $obj = Wikibase::Datatype::Reference->new(%params);
43             my $snaks_ar = $obj->snaks;
44              
45             =head1 DESCRIPTION
46              
47             This datatype is reference class for all references in claim.
48              
49             =head1 METHODS
50              
51             =head2 C<new>
52              
53             my $obj = Wikibase::Datatype::Reference->new(%params);
54              
55             Constructor.
56              
57             Returns instance of object.
58              
59             =over 8
60              
61             =item * C<snaks>
62              
63             Reference to array with Wikibase::Datatype::Snak instances.
64             Parameter is required.
65              
66             =back
67              
68             =head2 C<snaks>
69              
70             my $snaks_ar = $obj->snaks;
71              
72             Get snaks.
73              
74             Returns reference to array of Wikibase::Datatype::Snak instances.
75              
76             =head1 ERRORS
77              
78             new():
79             From Mo::utils::check_array_object():
80             Parameter 'snaks' must be a array.
81             Snak isn't 'Wikibase::Datatype::Snak' object.
82             From Mo::utils::check_required():
83             Parameter 'snaks' is required.
84              
85             =head1 EXAMPLE
86              
87             =for comment filename=create_and_print_reference.pl
88              
89             use strict;
90             use warnings;
91              
92             use Wikibase::Datatype::Reference;
93             use Wikibase::Datatype::Snak;
94             use Wikibase::Datatype::Value::String;
95             use Wikibase::Datatype::Value::Time;
96              
97             # Object.
98             my $obj = Wikibase::Datatype::Reference->new(
99             'snaks' => [
100             Wikibase::Datatype::Snak->new(
101             'datatype' => 'url',
102             'datavalue' => Wikibase::Datatype::Value::String->new(
103             'value' => 'https://skim.cz',
104             ),
105             'property' => 'P854',
106             ),
107             Wikibase::Datatype::Snak->new(
108             'datatype' => 'time',
109             'datavalue' => Wikibase::Datatype::Value::Time->new(
110             'value' => '+2013-12-07T00:00:00Z',
111             ),
112             'property' => 'P813',
113             ),
114             ],
115             );
116              
117             # Get value.
118             my $snaks_ar = $obj->snaks;
119              
120             # Print out number of snaks.
121             print "Number of snaks: ".@{$snaks_ar}."\n";
122              
123             # Output:
124             # Number of snaks: 2
125              
126             =head1 DEPENDENCIES
127              
128             L<Error::Pure>,
129             L<Mo>,
130             L<Mo::utils>.
131              
132             =head1 SEE ALSO
133              
134             =over
135              
136             =item L<Wikibase::Datatype>
137              
138             Wikibase datatypes.
139              
140             =item L<Wikibase::Datatype::Snak>
141              
142             Wikibase snak datatype.
143              
144             =back
145              
146             =head1 REPOSITORY
147              
148             L<https://github.com/michal-josef-spacek/Wikibase-Datatype>
149              
150             =head1 AUTHOR
151              
152             Michal Josef Špaček L<mailto:skim@cpan.org>
153              
154             L<http://skim.cz>
155              
156             =head1 LICENSE AND COPYRIGHT
157              
158             © 2020-2023 Michal Josef Špaček
159              
160             BSD 2-Clause License
161              
162             =head1 VERSION
163              
164             0.29
165              
166             =cut