Struct.pm

filter: Statementstmt 90.9% 50 / 55 Branchbran 62.5% 15 / 24 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 11 / 11 Podpod 100% 2 / 2 totaltotal 84.7% 78 / 92 CC 13 SCAR 20.2
CC
13
Cov
82%
obj2struct
16.0
struct2obj
6.0
BEGIN
1.0
CRAP 7.5
« Struct/Value.pm ↑ Summary Struct/Utils.pm »
1 package Wikibase::Datatype::Struct;
2  
3 4 ▶use base qw(Exporter);
Subroutine BEGIN: called CC=1 SCAR=0.0
4 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 4 ▶use Error::Pure qw(err);
Subroutine BEGIN: called CC=1 SCAR=0.0
8 4 ▶use Readonly;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 4 ▶use Wikibase::Datatype::Struct::Item;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 4 ▶use Wikibase::Datatype::Struct::Lexeme;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 4 ▶use Wikibase::Datatype::Struct::Mediainfo;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 4 ▶use Wikibase::Datatype::Struct::Property;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 4 Readonly::Array our @EXPORT_OK => qw(obj2struct struct2obj);
15  
16 4 our $VERSION = 0.15;
17  
18 4 ▶sub obj2struct {
Subroutine obj2struct: called CC=8 SCAR=27.7
Pod documented
19 4 my ($obj, $base_uri) = @_;
20  
21 4 ▶ if (! defined $obj) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $obj) 1 3 4
22 1 err "Object doesn't exist.";
23 }
24 3 ▶ if (! defined $base_uri) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $base_uri) 2 1 3
25 2 err 'Base URI is required.';
26 }
27  
28 1 my $struct_hr;
29 1 ▶ if ($obj->isa('Wikibase::Datatype::Item')) {
Branch: 4 branches
BranchTrueFalseTotal
if ($obj->isa('Wikibase::Datatype::Item')) { } 1 0 1
elsif ($obj->isa('Wikibase::Datatype::Lexeme')) { } 0 0 0
elsif ($obj->isa('Wikibase::Datatype::Mediainfo')) { } 0 0 0
elsif ($obj->isa('Wikibase::Datatype::Property')) { } 0 0 0
30 1 $struct_hr = Wikibase::Datatype::Struct::Item::obj2struct($obj, $base_uri);
31 } elsif ($obj->isa('Wikibase::Datatype::Lexeme')) {
32 0 $struct_hr = Wikibase::Datatype::Struct::Lexeme::obj2struct($obj, $base_uri);
33 } elsif ($obj->isa('Wikibase::Datatype::Mediainfo')) {
34 0 $struct_hr = Wikibase::Datatype::Struct::Mediainfo::obj2struct($obj, $base_uri);
35 } elsif ($obj->isa('Wikibase::Datatype::Property')) {
36 0 $struct_hr = Wikibase::Datatype::Struct::Property::obj2struct($obj, $base_uri);
37 } else {
38 0 my $ref = ref $obj;
39 0 ▶ err "Unsupported Wikibase::Datatype object.",
Branch: 1 branch
BranchTrueFalseTotal
defined $ref ? : 0 0 0
40 defined $ref ? ('Reference', $ref) : (),
41 ;
42 }
43  
44 1 return $struct_hr;
45 }
46  
47 6 ▶sub struct2obj {
Subroutine struct2obj: called CC=6 SCAR=17.9
Pod documented
48 6 my $struct_hr = shift;
49  
50 6 ▶ if (! exists $struct_hr->{'type'}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $struct_hr->{"type"}) 1 5 6
51 1 err "Structure doesn't supported. No type.";
52 }
53  
54 5 my $obj;
55 5 ▶ if ($struct_hr->{'type'} eq 'item') {
Branch: 4 branches
BranchTrueFalseTotal
if ($struct_hr->{'type'} eq 'item') { } 1 4 5
elsif ($struct_hr->{'type'} eq 'lexeme') { } 1 3 4
elsif ($struct_hr->{'type'} eq 'mediainfo') { } 1 2 3
elsif ($struct_hr->{'type'} eq 'property') { } 1 1 2
56 1 $obj = Wikibase::Datatype::Struct::Item::struct2obj($struct_hr);
57 } elsif ($struct_hr->{'type'} eq 'lexeme') {
58 1 $obj = Wikibase::Datatype::Struct::Lexeme::struct2obj($struct_hr);
59 } elsif ($struct_hr->{'type'} eq 'mediainfo') {
60 1 $obj = Wikibase::Datatype::Struct::Mediainfo::struct2obj($struct_hr);
61 } elsif ($struct_hr->{'type'} eq 'property') {
62 1 $obj = Wikibase::Datatype::Struct::Property::struct2obj($struct_hr);
63 } else {
64 1 err "Unsupported '$struct_hr->{'type'}' type,";
65 }
66  
67 4 return $obj;
68 }
69  
70 4 1;
71  
72 __END__
« Struct/Value.pm ↑ Summary Struct/Utils.pm »