File Coverage

blib/lib/Wikibase/Datatype/Sitelink.pm
Criterion Covered Total %
statement 20 20 100.0
branch n/a
condition n/a
subroutine 6 6 100.0
pod 0 1 0.0
total 26 27 96.3


line stmt bran cond sub pod time code
1             package Wikibase::Datatype::Sitelink;
2              
3 10     10   882669 use strict;
  10         22  
  10         481  
4 10     10   57 use warnings;
  10         36  
  10         649  
5              
6 10     10   3192 use Mo qw(build default is);
  10         4172  
  10         67  
7 10     10   22826 use Mo::utils qw(check_required);
  10         98857  
  10         415  
8 10     10   4699 use Mo::utils::Array qw(check_array_object);
  10         18056  
  10         981  
9              
10             our $VERSION = 0.39;
11              
12             has badges => (
13             is => 'ro',
14             default => [],
15             );
16              
17             has site => (
18             is => 'ro',
19             );
20              
21             has title => (
22             is => 'ro',
23             );
24              
25             sub BUILD {
26 12     12 0 651268 my $self = shift;
27              
28 12         69 check_required($self, 'site');
29 11         166 check_required($self, 'title');
30              
31 10         100 check_array_object($self, 'badges', 'Wikibase::Datatype::Value::Item');
32              
33 8         113 return;
34             }
35              
36             1;
37              
38             __END__
39              
40             =pod
41              
42             =encoding utf8
43              
44             =head1 NAME
45              
46             Wikibase::Datatype::Sitelink - Wikibase sitelink datatype.
47              
48             =head1 SYNOPSIS
49              
50             use Wikibase::Datatype::Sitelink;
51              
52             my $obj = Wikibase::Datatype::Sitelink->new(%params);
53             my $badges_ar = $obj->badges;
54             my $site = $obj->site;
55             my $title = $obj->title;
56              
57             =head1 DESCRIPTION
58              
59             This datatype is sitelink class for representing link to wikimedia projects
60             (e.g. Czech Wikipedia).
61              
62             =head1 METHODS
63              
64             =head2 C<new>
65              
66             my $obj = Wikibase::Datatype::Sitelink->new(%params);
67              
68             Constructor.
69              
70             Returns instance of object.
71              
72             =over 8
73              
74             =item * C<badges>
75              
76             Badges.
77             Default value is [].
78              
79             =item * C<site>
80              
81             Site shortcut (e.g. cswiki).
82             Parameter is required.
83              
84             =item * C<title>
85              
86             Page title (e.g. 'Main Page').
87             Parameter is required.
88              
89             =back
90              
91             =head2 C<badges>
92              
93             my $badges_ar = $obj->badges;
94              
95             Get badges (Badge is link to item - regexp /^Q\d+$/).
96              
97             Returns reference to array with strings.
98              
99             =head2 C<site>
100              
101             my $site = $obj->site;
102              
103             Get site.
104              
105             Returns string.
106              
107             =head2 C<title>
108              
109             my $title = $obj->title;
110              
111             Get title.
112              
113             Returns string.
114              
115             =head1 ERRORS
116              
117             new():
118             From Mo::utils::check_required():
119             Parameter 'site' is required.
120             Parameter 'title' is required.
121              
122             From Mo::utils::Array::check_array_object():
123             Parameter 'badges' must be a array.
124             Value: %s
125             Reference: %s
126             Parameter 'badges' with array must contain 'Wikibase::Datatype::Value::Item' objects.
127             Value: %s
128             Reference: %s
129              
130             =head1 EXAMPLE
131              
132             =for comment filename=create_and_print_sitelink.pl
133              
134             use strict;
135             use warnings;
136              
137             use Unicode::UTF8 qw(decode_utf8 encode_utf8);
138             use Wikibase::Datatype::Sitelink;
139             use Wikibase::Datatype::Value::Item;
140              
141             # Object.
142             my $obj = Wikibase::Datatype::Sitelink->new(
143             'badges' => [
144             Wikibase::Datatype::Value::Item->new(
145             'value' => 'Q123',
146             ),
147             ],
148             'site' => 'cswiki',
149             'title' => decode_utf8('Hlavní strana'),
150             );
151              
152             # Get badges.
153             my $badges_ar = [map { $_->value } @{$obj->badges}];
154              
155             # Get site.
156             my $site = $obj->site;
157              
158             # Get title.
159             my $title = $obj->title;
160              
161             # Print out.
162             print 'Badges: '.(join ', ', @{$badges_ar})."\n";
163             print "Site: $site\n";
164             print 'Title: '.encode_utf8($title)."\n";
165              
166             # Output:
167             # Badges: Q123
168             # Site: cswiki
169             # Title: Hlavní strana
170              
171             =head1 DEPENDENCIES
172              
173             L<Mo>,
174             L<Mo::utils>,
175             L<Mo::utils::Array>.
176              
177             =head1 SEE ALSO
178              
179             =over
180              
181             =item L<Wikibase::Datatype>
182              
183             Wikibase datatypes.
184              
185             =back
186              
187             =head1 REPOSITORY
188              
189             L<https://github.com/michal-josef-spacek/Wikibase-Datatype>
190              
191             =head1 AUTHOR
192              
193             Michal Josef Špaček L<mailto:skim@cpan.org>
194              
195             L<http://skim.cz>
196              
197             =head1 LICENSE AND COPYRIGHT
198              
199             © 2020-2025 Michal Josef Špaček
200              
201             BSD 2-Clause License
202              
203             =head1 VERSION
204              
205             0.39
206              
207             =cut