| 1 | package Wikibase::Datatype::Struct::Sense; | ||||||||||||
| 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::Sense; | ||||||||||
|
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 | |||||||||||||
| 13 | 12 | Readonly::Array our @EXPORT_OK => qw(obj2struct struct2obj); | |||||||||||
| 14 | |||||||||||||
| 15 | 12 | our $VERSION = 0.15; | |||||||||||
| 16 | |||||||||||||
| 17 | 5 | ▶ | sub obj2struct { | ||||||||||
|
Subroutine
obj2struct: called CC=8 SCAR=20.8
Pod
documented
| |||||||||||||
| 18 | 5 | my ($obj, $base_uri) = @_; | |||||||||||
| 19 | |||||||||||||
| 20 | 5 | ▶ | if (! defined $obj) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 21 | 1 | err "Object doesn't exist."; | |||||||||||
| 22 | } | ||||||||||||
| 23 | 4 | ▶ | if (! $obj->isa('Wikibase::Datatype::Sense')) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 24 | 1 | err "Object isn't 'Wikibase::Datatype::Sense'."; | |||||||||||
| 25 | } | ||||||||||||
| 26 | 3 | ▶ | if (! defined $base_uri) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 27 | 1 | err 'Base URI is required.'; | |||||||||||
| 28 | } | ||||||||||||
| 29 | |||||||||||||
| 30 | 2 | my $struct_hr = {}; | |||||||||||
| 31 | |||||||||||||
| 32 | 2 | ▶ | if (defined $obj->id) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 33 | 2 | $struct_hr->{'id'} = $obj->id; | |||||||||||
| 34 | } else { | ||||||||||||
| 35 | # Key for information, that I am creating structure. | ||||||||||||
| 36 | 0 | $struct_hr->{'add'} = ''; | |||||||||||
| 37 | } | ||||||||||||
| 38 | |||||||||||||
| 39 | # Glosses. | ||||||||||||
| 40 | 2 | foreach my $glosse (@{$obj->glosses}) { | |||||||||||
| 41 | 4 | $struct_hr->{'glosses'}->{$glosse->language} | |||||||||||
| 42 | = Wikibase::Datatype::Struct::Language::obj2struct($glosse); | ||||||||||||
| 43 | } | ||||||||||||
| 44 | |||||||||||||
| 45 | # Statements. | ||||||||||||
| 46 | 2 | foreach my $statement (@{$obj->statements}) { | |||||||||||
| 47 | 4 | ▶ | $struct_hr->{'claims'}->{$statement->snak->property} //= []; | ||||||||||
|
Condition100%2/2
$struct_hr->{"claims"}{$statement->snak->property} //= []
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}
| |||||||||||||
| 48 | 4 | push @{$struct_hr->{'claims'}->{$statement->snak->property}}, | |||||||||||
| 49 | Wikibase::Datatype::Struct::Statement::obj2struct($statement, $base_uri); | ||||||||||||
| 50 | } | ||||||||||||
| 51 | |||||||||||||
| 52 | 2 | return $struct_hr; | |||||||||||
| 53 | } | ||||||||||||
| 54 | |||||||||||||
| 55 | 2 | ▶ | sub struct2obj { | ||||||||||
|
Subroutine
struct2obj: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||
| 56 | 2 | my $struct_hr = shift; | |||||||||||
| 57 | |||||||||||||
| 58 | # Glosses. | ||||||||||||
| 59 | 2 | my $glosses_ar; | |||||||||||
| 60 | 2 | foreach my $lang (keys %{$struct_hr->{'glosses'}}) { | |||||||||||
| 61 | 4 | push @{$glosses_ar}, Wikibase::Datatype::Struct::Language::struct2obj($struct_hr->{'glosses'}->{$lang}); | |||||||||||
| 62 | } | ||||||||||||
| 63 | |||||||||||||
| 64 | # Statements. | ||||||||||||
| 65 | 2 | my $statements_ar = []; | |||||||||||
| 66 | 2 | foreach my $property (keys %{$struct_hr->{'claims'}}) { | |||||||||||
| 67 | 3 | foreach my $claim_hr (@{$struct_hr->{'claims'}->{$property}}) { | |||||||||||
| 68 | 3 | push @{$statements_ar}, Wikibase::Datatype::Struct::Statement::struct2obj( | |||||||||||
| 69 | $claim_hr, | ||||||||||||
| 70 | ); | ||||||||||||
| 71 | } | ||||||||||||
| 72 | } | ||||||||||||
| 73 | |||||||||||||
| 74 | my $obj = Wikibase::Datatype::Sense->new( | ||||||||||||
| 75 | 'glosses' => $glosses_ar, | ||||||||||||
| 76 | 2 | 'id' => $struct_hr->{'id'}, | |||||||||||
| 77 | 'statements' => $statements_ar, | ||||||||||||
| 78 | ); | ||||||||||||
| 79 | |||||||||||||
| 80 | 2 | return $obj; | |||||||||||
| 81 | } | ||||||||||||
| 82 | |||||||||||||
| 83 | 12 | 1; | |||||||||||
| 84 | |||||||||||||
| 85 | __END__ | ||||||||||||