File Coverage

blib/lib/Wikibase/Datatype/Reference.pm
Criterion Covered Total %
statement 22 22 100.0
branch n/a
condition n/a
subroutine 7 7 100.0
pod 0 1 0.0
total 29 30 96.6


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