Struct/Property.pm

filter: Statementstmt 100% 98 / 98 Branchbran 100% 34 / 34 Conditioncond 80.0% 4 / 5 MC/DCmcdc 66.6% 2 / 3 Subroutinesub 100% 11 / 11 Podpod 100% 2 / 2 totaltotal 98.6% 151 / 153 CC 30 SCAR 25.1
CC
30
Cov
99%
obj2struct
16.0
struct2obj
15.0
BEGIN
1.0
CRAP 12.3
« Struct/Lexeme.pm ↑ Summary Struct/Mediainfo.pm »
1 package Wikibase::Datatype::Struct::Property;
2  
3 8 ▶use base qw(Exporter);
Subroutine BEGIN: called CC=1 SCAR=0.0
4 8 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 8 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 8 ▶use Error::Pure qw(err);
Subroutine BEGIN: called CC=1 SCAR=0.0
8 8 ▶use Readonly;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 8 ▶use Wikibase::Datatype::Property;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 8 ▶use Wikibase::Datatype::Struct::Language;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 8 ▶use Wikibase::Datatype::Struct::Statement;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 8 ▶use Wikibase::Datatype::Struct::Value::Monolingual;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 8 Readonly::Array our @EXPORT_OK => qw(obj2struct struct2obj);
15  
16 8 our $VERSION = 0.15;
17  
18 7 ▶sub obj2struct {
Subroutine obj2struct: called CC=16 SCAR=27.7
Pod documented
19 7 my ($obj, $base_uri) = @_;
20  
21 7 ▶ if (! defined $obj) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $obj) 1 6 7
22 1 err "Object doesn't exist.";
23 }
24 6 ▶ if (! $obj->isa('Wikibase::Datatype::Property')) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($obj->isa("Wikibase::Datatype::Property")) 1 5 6
25 1 err "Object isn't 'Wikibase::Datatype::Property'.";
26 }
27 5 ▶ if (! defined $base_uri) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $base_uri) 1 4 5
28 1 err 'Base URI is required.';
29 }
30  
31 4 my $struct_hr = {
32 'type' => 'property',
33 };
34  
35 # Aliases.
36 4 foreach my $alias (@{$obj->aliases}) {
37 2 ▶ if (! exists $struct_hr->{'aliases'}->{$alias->language}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $struct_hr->{"aliases"}{$alias->language}) 1 1 2
38 1 $struct_hr->{'aliases'}->{$alias->language} = [];
39 }
40 2 push @{$struct_hr->{'aliases'}->{$alias->language}},
41 Wikibase::Datatype::Struct::Language::obj2struct($alias);
42 }
43  
44 # Claims.
45 4 foreach my $statement (@{$obj->statements}) {
46 1 ▶ $struct_hr->{'claims'}->{$statement->snak->property} //= [];
Condition50%1/2
$struct_hr->{"claims"}{$statement->snak->property} //= []
l!l
01
MC/DC0%0/1
$struct_hr->{"claims"}{$statement->snak->property} //= []
$struct_hr->{"claims"}{$statement->snak->property}
Truth table50%1/2
A
A= $struct_hr->{"claims"}{$statement->snak->property}
Aresult
11
00
47 1 push @{$struct_hr->{'claims'}->{$statement->snak->property}},
48 Wikibase::Datatype::Struct::Statement::obj2struct($statement, $base_uri);
49 }
50  
51 # Datatype.
52 4 $struct_hr->{'datatype'} = $obj->datatype;
53  
54 # Descriptions.
55 4 foreach my $desc (@{$obj->descriptions}) {
56 1 $struct_hr->{'descriptions'}->{$desc->language}
57 = Wikibase::Datatype::Struct::Language::obj2struct($desc);
58 }
59  
60 # Id.
61 4 ▶ if (defined $obj->id) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $obj->id) 1 3 4
62 1 $struct_hr->{'id'} = $obj->id;
63 }
64  
65 # Labels.
66 4 foreach my $label (@{$obj->labels}) {
67 1 $struct_hr->{'labels'}->{$label->language}
68 = Wikibase::Datatype::Struct::Language::obj2struct($label);
69 }
70
71 # Last revision id.
72 4 ▶ if (defined $obj->lastrevid) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $obj->lastrevid) 1 3 4
73 1 $struct_hr->{'lastrevid'} = $obj->lastrevid;
74 }
75  
76 # Modified date.
77 4 ▶ if (defined $obj->modified) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $obj->modified) 1 3 4
78 1 $struct_hr->{'modified'} = $obj->modified;
79 }
80  
81 # Namespace.
82 4 ▶ if (defined $obj->ns) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $obj->ns) 3 1 4
83 3 $struct_hr->{'ns'} = $obj->ns;
84 }
85  
86 # Page ID.
87 4 ▶ if (defined $obj->page_id) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $obj->page_id) 1 3 4
88 1 $struct_hr->{'pageid'} = $obj->page_id;
89 }
90  
91 # Title.
92 4 ▶ if (defined $obj->title) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $obj->title) 1 3 4
93 1 $struct_hr->{'title'} = $obj->title;
94 }
95  
96 4 return $struct_hr;
97 }
98  
99 6 ▶sub struct2obj {
Subroutine struct2obj: called CC=15 SCAR=27.1
Pod documented
100 6 my $struct_hr = shift;
101  
102 6 ▶ if (! exists $struct_hr->{'type'} || $struct_hr->{'type'} ne 'property') {
Branch: 1 branch
BranchTrueFalseTotal
if (not exists $struct_hr->{"type"} or $struct_hr->{"type"} ne "property") 2 4 6
Condition100%3/3
not exists $struct_hr->{"type"} or $struct_hr->{"type"} ne "property"
l!l&&r!l&&!r
114
MC/DC100%2/2
not exists $struct_hr->{"type"} or $struct_hr->{"type"} ne "property"
not exists $struct_hr->{"type"} $struct_hr->{"type"} ne "property"
Truth table100%3/3
not(A) or B
A= not exists $struct_hr->{"type"}B= $struct_hr->{"type"} ne "property"
ABresult
1X1
011
000
103 2 err "Structure isn't for 'property' type.";
104 }
105  
106 # Aliases.
107 4 my $aliases_ar = [];
108 4 foreach my $lang (keys %{$struct_hr->{'aliases'}}) {
109 1 foreach my $alias_hr (@{$struct_hr->{'aliases'}->{$lang}}) {
110 2 push @{$aliases_ar}, Wikibase::Datatype::Struct::Language::struct2obj(
111 $alias_hr,
112 );
113 }
114 }
115  
116 # Descriptions.
117 4 my $descriptions_ar = [];
118 4 foreach my $lang (keys %{$struct_hr->{'descriptions'}}) {
119 1 push @{$descriptions_ar}, Wikibase::Datatype::Struct::Language::struct2obj(
120 1 $struct_hr->{'descriptions'}->{$lang},
121 );
122 }
123  
124 # Labels.
125 4 my $labels_ar = [];
126 4 foreach my $lang (keys %{$struct_hr->{'labels'}}) {
127 1 push @{$labels_ar}, Wikibase::Datatype::Struct::Language::struct2obj(
128 1 $struct_hr->{'labels'}->{$lang},
129 );
130 }
131  
132 # Statements.
133 4 my $statements_ar = [];
134 4 foreach my $property (keys %{$struct_hr->{'claims'}}) {
135 1 foreach my $claim_hr (@{$struct_hr->{'claims'}->{$property}}) {
136 1 push @{$statements_ar}, Wikibase::Datatype::Struct::Statement::struct2obj(
137 $claim_hr,
138 );
139 }
140 }
141  
142 my $obj = Wikibase::Datatype::Property->new(
143 'aliases' => $aliases_ar,
144 'datatype' => $struct_hr->{'datatype'},
145 'descriptions' => $descriptions_ar,
146 defined $struct_hr->{'id'} ? ('id' => $struct_hr->{'id'}) : (),
147 'labels' => $labels_ar,
148 defined $struct_hr->{'lastrevid'} ? ('lastrevid' => $struct_hr->{'lastrevid'}) : (),
149 defined $struct_hr->{'modified'} ? ('modified' => $struct_hr->{'modified'}) : (),
150 defined $struct_hr->{'ns'} ? ('ns' => $struct_hr->{'ns'}) : (),
151 defined $struct_hr->{'pageid'} ? ('page_id' => $struct_hr->{'pageid'}) : (),
152 'statements' => $statements_ar,
153 4 ▶ defined $struct_hr->{'title'} ? ('title' => $struct_hr->{'title'}) : (),
Branch: 6 branches
BranchTrueFalseTotal
defined $struct_hr->{'id'} ? : 1 3 4
defined $struct_hr->{'lastrevid'} ? : 1 3 4
defined $struct_hr->{'modified'} ? : 1 3 4
defined $struct_hr->{'ns'} ? : 3 1 4
defined $struct_hr->{'pageid'} ? : 1 3 4
defined $struct_hr->{'title'} ? : 1 3 4
154 );
155  
156 4 return $obj;
157 }
158  
159 8 1;
160  
161 __END__
« Struct/Lexeme.pm ↑ Summary Struct/Mediainfo.pm »