Wikibase/Datatype/Item.pm

filter: Statementstmt 100% 56 / 56 Branchbran 100% 6 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 8 / 8 Podpod 0.0% 0 / 1 totaltotal 98.5% 70 / 71 CC 4 SCAR 7.4
CC
4
Cov
100%
BUILD
4.0
BEGIN
1.0
BEGIN
1.0
CRAP 2.1
« Wikibase/Datatype/MediainfoSnak.pm ↑ Summary Wikibase/Datatype/MediainfoStatement.pm »
1 package Wikibase::Datatype::Item;
2  
3 23 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 23 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 23 ▶use Error::Pure qw(err);
Subroutine BEGIN: called CC=1 SCAR=0.0
7 23 ▶use Mo qw(build default is);
Subroutine BEGIN: called CC=1 SCAR=0.0
8 23 ▶use Mo::utils qw(check_number check_number_of_items);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 23 ▶use Mo::utils::Array qw(check_array_object);
Subroutine BEGIN: called CC=1 SCAR=0.0
10 23 ▶use Wikibase::Datatype::Term;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 23 our $VERSION = 0.40;
13  
14 23 has aliases => (
15 default => [],
16 is => 'ro',
17 );
18  
19 23 has descriptions => (
20 default => [],
21 is => 'ro',
22 );
23  
24 23 has id => (
25 is => 'ro',
26 );
27  
28 23 has labels => (
29 default => [],
30 is => 'ro',
31 );
32  
33 23 has lastrevid => (
34 is => 'ro',
35 );
36  
37 23 has modified => (
38 is => 'ro',
39 );
40  
41 23 has ns => (
42 default => 0,
43 is => 'ro',
44 );
45  
46 23 has page_id => (
47 is => 'ro',
48 );
49  
50 23 has sitelinks => (
51 default => [],
52 is => 'ro',
53 );
54  
55 23 has statements => (
56 default => [],
57 is => 'ro',
58 );
59  
60 23 has title => (
61 is => 'ro',
62 );
63  
64 30 ▶sub BUILD {
Subroutine BUILD: called CC=4 SCAR=13.9
Pod undocumented
65 30 my $self = shift;
66  
67 # Check aliases.
68 30 check_array_object($self, 'aliases', 'Wikibase::Datatype::Term');
69  
70 # Check descriptions.
71 29 check_array_object($self, 'descriptions', 'Wikibase::Datatype::Term');
72 28 check_number_of_items($self, 'descriptions', 'language', 'Description', 'language');
73  
74 # Check labels.
75 27 check_array_object($self, 'labels', 'Wikibase::Datatype::Term');
76 26 check_number_of_items($self, 'labels', 'language', 'Label', 'language');
77  
78 # If length of value is greater than 250, strip.
79 25 my @labels = @{$self->labels};
80 25 my $strip_label = 0;
81 25 ▶ for (my $i = 0; $i < @labels; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @labels) 6 25 31
82 6 ▶ if (length $labels[$i]->value > 250) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $labels[$i]->value > 250) 1 5 6
83 1 my $new_label = substr $labels[$i]->value, 0, 250;
84 1 my $new_language = $labels[$i]->language;
85 1 $strip_label = 1;
86 1 $labels[$i] = Wikibase::Datatype::Term->new(
87 'language' => $new_language,
88 'value' => $new_label,
89 );
90 }
91 }
92 25 ▶ if ($strip_label) {
Branch: 1 branch
BranchTrueFalseTotal
if ($strip_label) 1 24 25
93 1 $self->{'labels'} = \@labels;
94 }
95  
96 # Check page id.
97 25 check_number($self, 'page_id');
98  
99 # Check sitelinks.
100 24 check_array_object($self, 'sitelinks', 'Wikibase::Datatype::Sitelink');
101 23 check_number_of_items($self, 'sitelinks', 'site', 'Sitelink', 'site');
102  
103 # Check statements.
104 22 check_array_object($self, 'statements', 'Wikibase::Datatype::Statement');
105  
106 21 return;
107 }
108  
109 23 1;
110  
111 __END__
« Wikibase/Datatype/MediainfoSnak.pm ↑ Summary Wikibase/Datatype/MediainfoStatement.pm »