Struct/Form.pm

filter: Statementstmt 98.6% 73 / 74 Branchbran 87.5% 7 / 8 Conditioncond 100% 2 / 2 MC/DCmcdc 100% 1 / 1 Subroutinesub 100% 11 / 11 Podpod 100% 2 / 2 totaltotal 97.9% 96 / 98 CC 13 SCAR 16.1
CC
13
Cov
98%
obj2struct
9.0
struct2obj
5.0
BEGIN
1.0
CRAP 5.0
« Struct/Utils.pm ↑ Summary Struct/Value/Sense.pm »
1 package Wikibase::Datatype::Struct::Form;
2  
3 12 ▶use base qw(Exporter);
Subroutine BEGIN: called CC=1 SCAR=0.0
4 12 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 12 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 12 ▶use Error::Pure qw(err);
Subroutine BEGIN: called CC=1 SCAR=0.0
8 12 ▶use Readonly;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 12 ▶use Wikibase::Datatype::Form;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 12 ▶use Wikibase::Datatype::Struct::Language;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 12 ▶use Wikibase::Datatype::Struct::Statement;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 12 ▶use Wikibase::Datatype::Value::Item;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 12 Readonly::Array our @EXPORT_OK => qw(obj2struct struct2obj);
15  
16 12 our $VERSION = 0.15;
17  
18 5 ▶sub obj2struct {
Subroutine obj2struct: called CC=9 SCAR=22.0
Pod documented
19 5 my ($obj, $base_uri) = @_;
20  
21 5 ▶ if (! defined $obj) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $obj) 1 4 5
22 1 err "Object doesn't exist.";
23 }
24 4 ▶ if (! $obj->isa('Wikibase::Datatype::Form')) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($obj->isa("Wikibase::Datatype::Form")) 1 3 4
25 1 err "Object isn't 'Wikibase::Datatype::Form'.";
26 }
27 3 ▶ if (! defined $base_uri) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $base_uri) 1 2 3
28 1 err 'Base URI is required.';
29 }
30  
31 2 my $struct_hr = {};
32  
33 2 ▶ if (defined $obj->id) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $obj->id) { } 2 0 2
34 2 $struct_hr->{'id'} = $obj->id;
35 } else {
36 # Key for information, that I am creating structure.
37 0 $struct_hr->{'add'} = '';
38 }
39  
40 # Grammatical features.
41 2 foreach my $gf (@{$obj->grammatical_features}) {
42 4 push @{$struct_hr->{'grammaticalFeatures'}}, $gf->value;
43 }
44  
45 # Representations.
46 2 foreach my $rep (@{$obj->representations}) {
47 3 $struct_hr->{'representations'}->{$rep->language}
48 = Wikibase::Datatype::Struct::Language::obj2struct($rep);
49 }
50  
51 # Statements.
52 2 foreach my $statement (@{$obj->statements}) {
53 3 ▶ $struct_hr->{'claims'}->{$statement->snak->property} //= [];
Condition100%2/2
$struct_hr->{"claims"}{$statement->snak->property} //= []
l!l
12
MC/DC100%1/1
$struct_hr->{"claims"}{$statement->snak->property} //= []
$struct_hr->{"claims"}{$statement->snak->property}
Truth table100%2/2
A
A= $struct_hr->{"claims"}{$statement->snak->property}
Aresult
11
00
54 3 push @{$struct_hr->{'claims'}->{$statement->snak->property}},
55 Wikibase::Datatype::Struct::Statement::obj2struct($statement, $base_uri);
56 }
57  
58 2 return $struct_hr;
59 }
60  
61 2 ▶sub struct2obj {
Subroutine struct2obj: called CC=5 SCAR=16.1
Pod documented
62 2 my $struct_hr = shift;
63  
64 # Grammatical features.
65 2 my $gm_ar = [];
66 2 foreach my $gm (@{$struct_hr->{'grammaticalFeatures'}}) {
67 4 push @{$gm_ar}, Wikibase::Datatype::Value::Item->new(
68 'value' => $gm,
69 );
70 }
71  
72 # Representations.
73 2 my $representations_ar;
74 2 foreach my $lang (keys %{$struct_hr->{'representations'}}) {
75 3 push @{$representations_ar}, Wikibase::Datatype::Struct::Language::struct2obj(
76 3 $struct_hr->{'representations'}->{$lang});
77 }
78  
79 # Statements.
80 2 my $statements_ar = [];
81 2 foreach my $property (keys %{$struct_hr->{'claims'}}) {
82 2 foreach my $claim_hr (@{$struct_hr->{'claims'}->{$property}}) {
83 2 push @{$statements_ar}, Wikibase::Datatype::Struct::Statement::struct2obj(
84 $claim_hr,
85 );
86 }
87 }
88  
89 my $obj = Wikibase::Datatype::Form->new(
90 'grammatical_features' => $gm_ar,
91 2 'id' => $struct_hr->{'id'},
92 'representations' => $representations_ar,
93 'statements' => $statements_ar,
94 );
95  
96 2 return $obj;
97 }
98  
99 12 1;
100  
101 __END__
« Struct/Utils.pm ↑ Summary Struct/Value/Sense.pm »