| 1 | package Wikibase::Datatype::Struct::MediainfoSnak; | ||||||||||
| 2 | |||||||||||
| 3 | 15 | ▶ | use base qw(Exporter); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 15 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 15 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | |||||||||||
| 7 | 15 | ▶ | use Error::Pure qw(err); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | 15 | ▶ | use Readonly; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | 15 | ▶ | use Wikibase::Datatype::MediainfoSnak; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | 15 | ▶ | use Wikibase::Datatype::Struct::Value; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 11 | |||||||||||
| 12 | 15 | Readonly::Array our @EXPORT_OK => qw(obj2struct struct2obj); | |||||||||
| 13 | |||||||||||
| 14 | 15 | our $VERSION = 0.15; | |||||||||
| 15 | |||||||||||
| 16 | 11 | ▶ | sub obj2struct { | ||||||||
|
Subroutine
obj2struct: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||
| 17 | 11 | my ($obj, $base_uri) = @_; | |||||||||
| 18 | |||||||||||
| 19 | 11 | ▶ | if (! defined $obj) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 20 | 1 | err "Object doesn't exist."; | |||||||||
| 21 | } | ||||||||||
| 22 | 10 | ▶ | if (! $obj->isa('Wikibase::Datatype::MediainfoSnak')) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 23 | 1 | err "Object isn't 'Wikibase::Datatype::MediainfoSnak'."; | |||||||||
| 24 | } | ||||||||||
| 25 | 9 | ▶ | if (! defined $base_uri) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 26 | 1 | err 'Base URI is required.'; | |||||||||
| 27 | } | ||||||||||
| 28 | |||||||||||
| 29 | 8 | ▶ | my $struct_hr = { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 30 | defined $obj->datavalue | ||||||||||
| 31 | ? ('datavalue' => Wikibase::Datatype::Struct::Value::obj2struct($obj->datavalue, $base_uri)) | ||||||||||
| 32 | : (), | ||||||||||
| 33 | 'property' => $obj->property, | ||||||||||
| 34 | 'snaktype' => $obj->snaktype, | ||||||||||
| 35 | }; | ||||||||||
| 36 | |||||||||||
| 37 | 8 | return $struct_hr; | |||||||||
| 38 | } | ||||||||||
| 39 | |||||||||||
| 40 | 9 | ▶ | sub struct2obj { | ||||||||
|
Subroutine
struct2obj: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||
| 41 | 9 | my $struct_hr = shift; | |||||||||
| 42 | |||||||||||
| 43 | # Data value isn't required for snaktype 'novalue'. | ||||||||||
| 44 | 9 | my $datavalue; | |||||||||
| 45 | 9 | ▶ | if (exists $struct_hr->{'datavalue'}) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 46 | 6 | $datavalue = Wikibase::Datatype::Struct::Value::struct2obj($struct_hr->{'datavalue'}); | |||||||||
| 47 | } | ||||||||||
| 48 | |||||||||||
| 49 | my $obj = Wikibase::Datatype::MediainfoSnak->new( | ||||||||||
| 50 | ($struct_hr->{'snaktype'} eq 'value') ? ( | ||||||||||
| 51 | 'datavalue' => $datavalue, | ||||||||||
| 52 | ) : (), | ||||||||||
| 53 | 'property' => $struct_hr->{'property'}, | ||||||||||
| 54 | 9 | ▶ | 'snaktype' => $struct_hr->{'snaktype'}, | ||||||||
|
Branch: 1 branch
| |||||||||||
| 55 | ); | ||||||||||
| 56 | |||||||||||
| 57 | 9 | return $obj; | |||||||||
| 58 | } | ||||||||||
| 59 | |||||||||||
| 60 | 15 | 1; | |||||||||
| 61 | |||||||||||
| 62 | __END__ | ||||||||||