| 1 | package Wikibase::Datatype::Struct::Mediainfo; | ||||||||||||||||||||||||||||||
| 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::Mediainfo; | ||||||||||||||||||||||||||||
|
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::MediainfoStatement; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||
| 13 | 8 | Readonly::Array our @EXPORT_OK => qw(obj2struct struct2obj); | |||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||
| 15 | 8 | our $VERSION = 0.15; | |||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||
| 17 | 8 | ▶ | sub obj2struct { | ||||||||||||||||||||||||||||
|
Subroutine
obj2struct: called CC=14 SCAR=26.4
Pod
documented
| |||||||||||||||||||||||||||||||
| 18 | 8 | my ($obj, $base_uri) = @_; | |||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||
| 20 | 8 | ▶ | if (! defined $obj) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 21 | 1 | err "Object doesn't exist."; | |||||||||||||||||||||||||||||
| 22 | } | ||||||||||||||||||||||||||||||
| 23 | 7 | ▶ | if (! $obj->isa('Wikibase::Datatype::Mediainfo')) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 24 | 1 | err "Object isn't 'Wikibase::Datatype::Mediainfo'."; | |||||||||||||||||||||||||||||
| 25 | } | ||||||||||||||||||||||||||||||
| 26 | 6 | ▶ | if (! defined $base_uri) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 27 | 1 | err 'Base URI is required.'; | |||||||||||||||||||||||||||||
| 28 | } | ||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||
| 30 | 5 | my $struct_hr = { | |||||||||||||||||||||||||||||
| 31 | 'type' => 'mediainfo', | ||||||||||||||||||||||||||||||
| 32 | }; | ||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||
| 34 | # Claims. | ||||||||||||||||||||||||||||||
| 35 | 5 | foreach my $statement (@{$obj->statements}) { | |||||||||||||||||||||||||||||
| 36 | 4 | ▶ | $struct_hr->{'statements'}->{$statement->snak->property} //= []; | ||||||||||||||||||||||||||||
|
Condition100%2/2
$struct_hr->{"statements"}{$statement->snak->property} //= []
MC/DC100%1/1
$struct_hr->{"statements"}{$statement->snak->property} //= []
$struct_hr->{"statements"}{$statement->snak->property}
Truth table100%2/2
A
A= $struct_hr->{"statements"}{$statement->snak->property}
| |||||||||||||||||||||||||||||||
| 37 | 4 | push @{$struct_hr->{'statements'}->{$statement->snak->property}}, | |||||||||||||||||||||||||||||
| 38 | Wikibase::Datatype::Struct::MediainfoStatement::obj2struct($statement, $base_uri); | ||||||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||
| 41 | # Descriptions. | ||||||||||||||||||||||||||||||
| 42 | 5 | $struct_hr->{'descriptions'} = {}; | |||||||||||||||||||||||||||||
| 43 | 5 | foreach my $desc (@{$obj->descriptions}) { | |||||||||||||||||||||||||||||
| 44 | 0 | $struct_hr->{'descriptions'}->{$desc->language} | |||||||||||||||||||||||||||||
| 45 | = Wikibase::Datatype::Struct::Language::obj2struct($desc); | ||||||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||
| 48 | # Id. | ||||||||||||||||||||||||||||||
| 49 | 5 | ▶ | if (defined $obj->id) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 50 | 1 | $struct_hr->{'id'} = $obj->id; | |||||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||
| 53 | # Labels. | ||||||||||||||||||||||||||||||
| 54 | 5 | foreach my $label (@{$obj->labels}) { | |||||||||||||||||||||||||||||
| 55 | 2 | $struct_hr->{'labels'}->{$label->language} | |||||||||||||||||||||||||||||
| 56 | = Wikibase::Datatype::Struct::Language::obj2struct($label); | ||||||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||
| 59 | # Last revision id. | ||||||||||||||||||||||||||||||
| 60 | 5 | ▶ | if (defined $obj->lastrevid) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 61 | 1 | $struct_hr->{'lastrevid'} = $obj->lastrevid; | |||||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||
| 64 | # Modified date. | ||||||||||||||||||||||||||||||
| 65 | 5 | ▶ | if (defined $obj->modified) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 66 | 1 | $struct_hr->{'modified'} = $obj->modified; | |||||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||
| 69 | # Namespace. | ||||||||||||||||||||||||||||||
| 70 | 5 | ▶ | if (defined $obj->ns) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 71 | 4 | $struct_hr->{'ns'} = $obj->ns; | |||||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||
| 74 | # Page ID. | ||||||||||||||||||||||||||||||
| 75 | 5 | ▶ | if (defined $obj->page_id) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 76 | 1 | $struct_hr->{'pageid'} = $obj->page_id; | |||||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||
| 79 | # Title. | ||||||||||||||||||||||||||||||
| 80 | 5 | ▶ | if (defined $obj->title) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 81 | 1 | $struct_hr->{'title'} = $obj->title; | |||||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||
| 84 | 5 | return $struct_hr; | |||||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||
| 87 | 6 | ▶ | sub struct2obj { | ||||||||||||||||||||||||||||
|
Subroutine
struct2obj: called CC=13 SCAR=25.7
Pod
documented
| |||||||||||||||||||||||||||||||
| 88 | 6 | my $struct_hr = shift; | |||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||
| 90 | 6 | ▶ | if (! exists $struct_hr->{'type'} || $struct_hr->{'type'} ne 'mediainfo') { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
not exists $struct_hr->{"type"} or $struct_hr->{"type"} ne "mediainfo"
MC/DC100%2/2
not exists $struct_hr->{"type"} or $struct_hr->{"type"} ne "mediainfo"
not exists $struct_hr->{"type"}
$struct_hr->{"type"} ne "mediainfo"
Truth table100%3/3
not(A) or B
A= not exists $struct_hr->{"type"}B= $struct_hr->{"type"} ne "mediainfo"
| |||||||||||||||||||||||||||||||
| 91 | 2 | err "Structure isn't for 'mediainfo' type."; | |||||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||
| 94 | # Descriptions. | ||||||||||||||||||||||||||||||
| 95 | 4 | my $descriptions_ar = []; | |||||||||||||||||||||||||||||
| 96 | 4 | foreach my $lang (keys %{$struct_hr->{'descriptions'}}) { | |||||||||||||||||||||||||||||
| 97 | 0 | push @{$descriptions_ar}, Wikibase::Datatype::Struct::Language::struct2obj( | |||||||||||||||||||||||||||||
| 98 | 0 | $struct_hr->{'descriptions'}->{$lang}, | |||||||||||||||||||||||||||||
| 99 | ); | ||||||||||||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||
| 102 | # Labels. | ||||||||||||||||||||||||||||||
| 103 | 4 | my $labels_ar = []; | |||||||||||||||||||||||||||||
| 104 | 4 | foreach my $lang (keys %{$struct_hr->{'labels'}}) { | |||||||||||||||||||||||||||||
| 105 | 2 | push @{$labels_ar}, Wikibase::Datatype::Struct::Language::struct2obj( | |||||||||||||||||||||||||||||
| 106 | 2 | $struct_hr->{'labels'}->{$lang}, | |||||||||||||||||||||||||||||
| 107 | ); | ||||||||||||||||||||||||||||||
| 108 | } | ||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||
| 110 | # Statements. | ||||||||||||||||||||||||||||||
| 111 | 4 | my $statements_ar = []; | |||||||||||||||||||||||||||||
| 112 | 4 | foreach my $property (keys %{$struct_hr->{'statements'}}) { | |||||||||||||||||||||||||||||
| 113 | 2 | foreach my $claim_hr (@{$struct_hr->{'statements'}->{$property}}) { | |||||||||||||||||||||||||||||
| 114 | 2 | push @{$statements_ar}, Wikibase::Datatype::Struct::MediainfoStatement::struct2obj( | |||||||||||||||||||||||||||||
| 115 | $claim_hr, | ||||||||||||||||||||||||||||||
| 116 | ); | ||||||||||||||||||||||||||||||
| 117 | } | ||||||||||||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||||
| 120 | my $obj = Wikibase::Datatype::Mediainfo->new( | ||||||||||||||||||||||||||||||
| 121 | 'descriptions' => $descriptions_ar, | ||||||||||||||||||||||||||||||
| 122 | defined $struct_hr->{'id'} ? ('id' => $struct_hr->{'id'}) : (), | ||||||||||||||||||||||||||||||
| 123 | 'labels' => $labels_ar, | ||||||||||||||||||||||||||||||
| 124 | defined $struct_hr->{'lastrevid'} ? ('lastrevid' => $struct_hr->{'lastrevid'}) : (), | ||||||||||||||||||||||||||||||
| 125 | defined $struct_hr->{'modified'} ? ('modified' => $struct_hr->{'modified'}) : (), | ||||||||||||||||||||||||||||||
| 126 | defined $struct_hr->{'ns'} ? ('ns' => $struct_hr->{'ns'}) : (), | ||||||||||||||||||||||||||||||
| 127 | defined $struct_hr->{'pageid'} ? ('page_id' => $struct_hr->{'pageid'}) : (), | ||||||||||||||||||||||||||||||
| 128 | 'statements' => $statements_ar, | ||||||||||||||||||||||||||||||
| 129 | 4 | ▶ | defined $struct_hr->{'title'} ? ('title' => $struct_hr->{'title'}) : (), | ||||||||||||||||||||||||||||
|
Branch: 6 branches
| |||||||||||||||||||||||||||||||
| 130 | ); | ||||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||||
| 132 | 4 | return $obj; | |||||||||||||||||||||||||||||
| 133 | } | ||||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||||
| 135 | 8 | 1; | |||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||||
| 137 | __END__ | ||||||||||||||||||||||||||||||