Struct/Value.pm

filter: Statementstmt 95.2% 81 / 85 Branchbran 90.9% 40 / 44 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 17 / 17 Podpod 100% 2 / 2 totaltotal 94.5% 140 / 148 CC 23 SCAR 20.7
CC
23
Cov
94%
struct2obj
12.5
obj2struct
12.0
BEGIN
1.0
CRAP 7.9
« Struct/Mediainfo.pm ↑ Summary Struct.pm »
1 package Wikibase::Datatype::Struct::Value;
2  
3 50 ▶use base qw(Exporter);
Subroutine BEGIN: called CC=1 SCAR=0.0
4 50 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 50 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 50 ▶use Error::Pure qw(err);
Subroutine BEGIN: called CC=1 SCAR=0.0
8 50 ▶use Readonly;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 50 ▶use Wikibase::Datatype::Struct::Value::Globecoordinate;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 50 ▶use Wikibase::Datatype::Struct::Value::Item;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 50 ▶use Wikibase::Datatype::Struct::Value::Lexeme;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 50 ▶use Wikibase::Datatype::Struct::Value::Monolingual;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 50 ▶use Wikibase::Datatype::Struct::Value::Property;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 50 ▶use Wikibase::Datatype::Struct::Value::Quantity;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 50 ▶use Wikibase::Datatype::Struct::Value::Sense;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 50 ▶use Wikibase::Datatype::Struct::Value::String;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 50 ▶use Wikibase::Datatype::Struct::Value::Time;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 50 ▶use Wikibase::Datatype::Value;
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20 50 Readonly::Array our @EXPORT_OK => qw(obj2struct struct2obj);
21  
22 50 our $VERSION = 0.15;
23  
24 53 ▶sub obj2struct {
Subroutine obj2struct: called CC=12 SCAR=24.9
Pod documented
25 53 my ($obj, $base_uri) = @_;
26  
27 53 ▶ if (! defined $obj) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $obj) 1 52 53
28 1 err "Object doesn't exist.";
29 }
30 52 ▶ if (! $obj->isa('Wikibase::Datatype::Value')) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($obj->isa("Wikibase::Datatype::Value")) 1 51 52
31 1 err "Object isn't 'Wikibase::Datatype::Value'.";
32 }
33  
34 51 my $struct_hr;
35 51 my $type = $obj->type;
36 51 ▶ if ($type eq 'globecoordinate') {
Branch: 9 branches
BranchTrueFalseTotal
if ($type eq 'globecoordinate') { } 1 50 51
elsif ($type eq 'item') { } 19 31 50
elsif ($type eq 'lexeme') { } 0 31 31
elsif ($type eq 'monolingualtext') { } 1 30 31
elsif ($type eq 'property') { } 1 29 30
elsif ($type eq 'quantity') { } 1 28 29
elsif ($type eq 'sense') { } 1 27 28
elsif ($type eq 'string') { } 21 6 27
elsif ($type eq 'time') { } 5 1 6
37 1 $struct_hr = Wikibase::Datatype::Struct::Value::Globecoordinate::obj2struct($obj, $base_uri);
38 } elsif ($type eq 'item') {
39 19 $struct_hr = Wikibase::Datatype::Struct::Value::Item::obj2struct($obj);
40 } elsif ($type eq 'lexeme') {
41 0 $struct_hr = Wikibase::Datatype::Struct::Value::Lexeme::obj2struct($obj);
42 } elsif ($type eq 'monolingualtext') {
43 1 $struct_hr = Wikibase::Datatype::Struct::Value::Monolingual::obj2struct($obj);
44 } elsif ($type eq 'property') {
45 1 $struct_hr = Wikibase::Datatype::Struct::Value::Property::obj2struct($obj);
46 } elsif ($type eq 'quantity') {
47 1 $struct_hr = Wikibase::Datatype::Struct::Value::Quantity::obj2struct($obj, $base_uri);
48 } elsif ($type eq 'sense') {
49 1 $struct_hr = Wikibase::Datatype::Struct::Value::Sense::obj2struct($obj, $base_uri);
50 } elsif ($type eq 'string') {
51 21 $struct_hr = Wikibase::Datatype::Struct::Value::String::obj2struct($obj);
52 } elsif ($type eq 'time') {
53 5 $struct_hr = Wikibase::Datatype::Struct::Value::Time::obj2struct($obj, $base_uri);
54 } else {
55 1 err "Type '$type' is unsupported.";
56 }
57  
58 50 return $struct_hr;
59 }
60  
61 53 ▶sub struct2obj {
Subroutine struct2obj: called CC=12 SCAR=25.2
Pod documented
62 53 my $struct_hr = shift;
63  
64 53 ▶ if (! exists $struct_hr->{'type'}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $struct_hr->{"type"}) 0 53 53
65 0 err "Type doesn't exist.";
66 }
67  
68 53 my $obj;
69 53 ▶ if ($struct_hr->{'type'} eq 'globecoordinate') {
Branch: 6 branches
BranchTrueFalseTotal
if ($struct_hr->{'type'} eq 'globecoordinate') { } 1 52 53
elsif ($struct_hr->{'type'} eq 'monolingualtext') { } 1 51 52
elsif ($struct_hr->{'type'} eq 'quantity') { } 1 50 51
elsif ($struct_hr->{'type'} eq 'string') { } 21 29 50
elsif ($struct_hr->{'type'} eq 'time') { } 7 22 29
elsif ($struct_hr->{'type'} eq 'wikibase-entityid') { } 21 1 22
70 1 $obj = Wikibase::Datatype::Struct::Value::Globecoordinate::struct2obj($struct_hr);
71 } elsif ($struct_hr->{'type'} eq 'monolingualtext') {
72 1 $obj = Wikibase::Datatype::Struct::Value::Monolingual::struct2obj($struct_hr);
73 } elsif ($struct_hr->{'type'} eq 'quantity') {
74 1 $obj = Wikibase::Datatype::Struct::Value::Quantity::struct2obj($struct_hr);
75 } elsif ($struct_hr->{'type'} eq 'string') {
76 21 $obj = Wikibase::Datatype::Struct::Value::String::struct2obj($struct_hr);
77 } elsif ($struct_hr->{'type'} eq 'time') {
78 7 $obj = Wikibase::Datatype::Struct::Value::Time::struct2obj($struct_hr);
79 } elsif ($struct_hr->{'type'} eq 'wikibase-entityid') {
80 21 ▶ if ($struct_hr->{'value'}->{'entity-type'} eq 'item') {
Branch: 4 branches
BranchTrueFalseTotal
if ($struct_hr->{'value'}{'entity-type'} eq 'item') { } 19 2 21
elsif ($struct_hr->{'value'}{'entity-type'} eq 'lexeme') { } 0 2 2
elsif ($struct_hr->{'value'}{'entity-type'} eq 'property') { } 1 1 2
elsif ($struct_hr->{'value'}{'entity-type'} eq 'sense') { } 1 0 1
81 19 $obj = Wikibase::Datatype::Struct::Value::Item::struct2obj($struct_hr);
82 } elsif ($struct_hr->{'value'}->{'entity-type'} eq 'lexeme') {
83 0 $obj = Wikibase::Datatype::Struct::Value::Lexeme::struct2obj($struct_hr);
84 } elsif ($struct_hr->{'value'}->{'entity-type'} eq 'property') {
85 1 $obj = Wikibase::Datatype::Struct::Value::Property::struct2obj($struct_hr);
86 } elsif ($struct_hr->{'value'}->{'entity-type'} eq 'sense') {
87 1 $obj = Wikibase::Datatype::Struct::Value::Sense::struct2obj($struct_hr);
88 } else {
89 0 err "Entity type '$struct_hr->{'value'}->{'entity-type'}' is unsupported.";
90 }
91 } else {
92 1 err "Type '$struct_hr->{'type'}' is unsupported.";
93 }
94  
95 52 return $obj;
96 }
97  
98 50 1;
99  
100 __END__
« Struct/Mediainfo.pm ↑ Summary Struct.pm »