Struct/Value/Item.pm

filter: Statementstmt 100% 35 / 35 Branchbran 100% 6 / 6 Conditioncond 100% 18 / 18 MC/DCmcdc 100% 7 / 7 Subroutinesub 100% 8 / 8 Podpod 100% 2 / 2 totaltotal 100% 76 / 76 CC 10 SCAR 15.4
CC
10
Cov
100%
struct2obj
8.0
obj2struct
3.0
BEGIN
1.0
CRAP 4.6
« Struct/Value/Sense.pm ↑ Summary Struct/Value/Lexeme.pm »
1 package Wikibase::Datatype::Struct::Value::Item;
2  
3 54 ▶use base qw(Exporter);
Subroutine BEGIN: called CC=1 SCAR=0.0
4 54 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 54 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 54 ▶use Error::Pure qw(err);
Subroutine BEGIN: called CC=1 SCAR=0.0
8 54 ▶use Readonly;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 54 ▶use Wikibase::Datatype::Value::Item;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 54 Readonly::Array our @EXPORT_OK => qw(obj2struct struct2obj);
12  
13 54 our $VERSION = 0.15;
14  
15 22 ▶sub obj2struct {
Subroutine obj2struct: called CC=3 SCAR=11.0
Pod documented
16 22 my $obj = shift;
17  
18 22 ▶ if (! defined $obj) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $obj) 1 21 22
19 1 err "Object doesn't exist.";
20 }
21 21 ▶ if (! $obj->isa('Wikibase::Datatype::Value::Item')) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($obj->isa("Wikibase::Datatype::Value::Item")) 1 20 21
22 1 err "Object isn't 'Wikibase::Datatype::Value::Item'.";
23 }
24  
25 20 my $numeric_id = $obj->value;
26 20 $numeric_id =~ s/^Q//ms;
27 20 my $struct_hr = {
28 'value' => {
29 'entity-type' => $obj->type,
30 'id' => $obj->value,
31 'numeric-id' => $numeric_id,
32 },
33 'type' => 'wikibase-entityid',
34 };
35  
36 20 return $struct_hr;
37 }
38  
39 27 ▶sub struct2obj {
Subroutine struct2obj: called CC=8 SCAR=20.8
Pod documented
40 27 my $struct_hr = shift;
41  
42 27 ▶ if (! exists $struct_hr->{'type'}
Branch: 1 branch
BranchTrueFalseTotal
if (not exists $struct_hr->{"type"} && defined $struct_hr->{"type"} or $struct_hr->{"type"} ne "wikibase-entityid" or not exists $struct_hr->{"value"} or not exists $struct_hr->{"value"}{"entity-type"} or not defined $struct_hr->{"value"}{"entity-type"} or $struct_hr->{"value"}{"entity-type"} ne "item") 7 20 27
Condition100%18/18
not exists $struct_hr->{"type"} && defined $struct_hr->{"type"} or $struct_hr->{"type"} ne "wikibase-entityid" or not exists $struct_hr->{"value"} or not exists $struct_hr->{"value"}{"entity-type"} or not defined $struct_hr->{"value"}{"entity-type"} or $struct_hr->{"value"}{"entity-type"} ne "item"
l!l&&r!l&&!r
6120
not exists $struct_hr->{"type"} && defined $struct_hr->{"type"} or $struct_hr->{"type"} ne "wikibase-entityid" or not exists $struct_hr->{"value"} or not exists $struct_hr->{"value"}{"entity-type"} or not defined $struct_hr->{"value"}{"entity-type"}
l!l&&r!l&&!r
5121
not exists $struct_hr->{"type"} && defined $struct_hr->{"type"} or $struct_hr->{"type"} ne "wikibase-entityid" or not exists $struct_hr->{"value"} or not exists $struct_hr->{"value"}{"entity-type"}
l!l&&r!l&&!r
4122
not exists $struct_hr->{"type"} && defined $struct_hr->{"type"} or $struct_hr->{"type"} ne "wikibase-entityid" or not exists $struct_hr->{"value"}
l!l&&r!l&&!r
3123
not exists $struct_hr->{"type"} && defined $struct_hr->{"type"} or $struct_hr->{"type"} ne "wikibase-entityid"
l!l&&r!l&&!r
2124
exists $struct_hr->{'type'} && defined $struct_hr->{'type'}
!ll&&!rl&&r
1125
MC/DC100%7/7
not exists $struct_hr->{"type"} && defined $struct_hr->{"type"} or $struct_hr->{"type"} ne "wikibase-entityid" or not exists $struct_hr->{"value"} or not exists $struct_hr->{"value"}{"entity-type"} or not defined $struct_hr->{"value"}{"entity-type"} or $struct_hr->{"value"}{"entity-type"} ne "item"
exists $struct_hr->{'type'} defined $struct_hr->{'type'} $struct_hr->{"type"} ne "wikibase-entityid" not exists $struct_hr->{"value"} not exists $struct_hr->{"value"}{"entity-type"} not defined $struct_hr->{"value"}{"entity-type"} $struct_hr->{"value"}{"entity-type"} ne "item"
Truth table100%8/8
not(A && B) or C or not(D) or not(E) or not(F) or G
A= exists $struct_hr->{'type'}B= defined $struct_hr->{'type'}C= $struct_hr->{"type"} ne "wikibase-entityid"D= not exists $struct_hr->{"value"}E= not exists $struct_hr->{"value"}{"entity-type"}F= not defined $struct_hr->{"value"}{"entity-type"}G= $struct_hr->{"value"}{"entity-type"} ne "item"
ABCDEFGresult
0XXXXXX1
10XXXXX1
111XXXX1
1101XXX1
11001XX1
110001X1
11000011
11000000
43 || ! defined $struct_hr->{'type'}
44 || $struct_hr->{'type'} ne 'wikibase-entityid'
45 || ! exists $struct_hr->{'value'}
46 || ! exists $struct_hr->{'value'}->{'entity-type'}
47 || ! defined $struct_hr->{'value'}->{'entity-type'}
48 || $struct_hr->{'value'}->{'entity-type'} ne 'item') {
49  
50 7 err "Structure isn't for 'item' datatype.";
51 }
52  
53 my $obj = Wikibase::Datatype::Value::Item->new(
54 20 'value' => $struct_hr->{'value'}->{'id'},
55 );
56  
57 20 return $obj;
58 }
59  
60 54 1;
61  
62 __END__
« Struct/Value/Sense.pm ↑ Summary Struct/Value/Lexeme.pm »