| 1 | package Wikibase::Datatype::Struct::MediainfoStatement; | ||||||||||||||
| 2 | |||||||||||||||
| 3 | 10 | ▶ | use base qw(Exporter); | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 4 | 10 | ▶ | use strict; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 5 | 10 | ▶ | use warnings; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 6 | |||||||||||||||
| 7 | 10 | ▶ | use Error::Pure qw(err); | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 8 | 10 | ▶ | use Readonly; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 9 | 10 | ▶ | use Wikibase::Datatype::MediainfoStatement; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 10 | 10 | ▶ | use Wikibase::Datatype::Struct::MediainfoSnak; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 11 | 10 | ▶ | use Wikibase::Datatype::Struct::Reference; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 12 | 10 | ▶ | use Wikibase::Datatype::Struct::Utils qw(obj_array_ref2struct struct2snaks_array_ref); | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 13 | |||||||||||||||
| 14 | 10 | Readonly::Array our @EXPORT_OK => qw(obj2struct struct2obj); | |||||||||||||
| 15 | |||||||||||||||
| 16 | 10 | our $VERSION = 0.15; | |||||||||||||
| 17 | |||||||||||||||
| 18 | 4 | ▶ | sub obj2struct { | ||||||||||||
|
Subroutine
obj2struct: called CC=7 SCAR=22.8
Pod
documented
| |||||||||||||||
| 19 | 4 | my ($obj, $base_uri) = @_; | |||||||||||||
| 20 | |||||||||||||||
| 21 | 4 | ▶ | if (! defined $obj) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 22 | 0 | err "Object doesn't exist."; | |||||||||||||
| 23 | } | ||||||||||||||
| 24 | 4 | ▶ | if (! $obj->isa('Wikibase::Datatype::MediainfoStatement')) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 25 | 0 | err "Object isn't 'Wikibase::Datatype::MediainfoStatement'."; | |||||||||||||
| 26 | } | ||||||||||||||
| 27 | 4 | ▶ | if (! defined $base_uri) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 28 | 0 | err 'Base URI is required.'; | |||||||||||||
| 29 | } | ||||||||||||||
| 30 | |||||||||||||||
| 31 | my $struct_hr = { | ||||||||||||||
| 32 | defined $obj->id ? ('id' => $obj->id) : (), | ||||||||||||||
| 33 | 'mainsnak' => Wikibase::Datatype::Struct::MediainfoSnak::obj2struct($obj->snak, $base_uri), | ||||||||||||||
| 34 | 4 | @{$obj->property_snaks} ? ( | |||||||||||||
| 35 | 1 | ▶ | %{obj_array_ref2struct($obj->property_snaks, 'qualifiers', $base_uri, | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 36 | 'Wikibase::Datatype::MediainfoSnak', 'Wikibase::Datatype::Struct::MediainfoSnak')}, | ||||||||||||||
| 37 | ) : (), | ||||||||||||||
| 38 | 'rank' => $obj->rank, | ||||||||||||||
| 39 | 4 | @{$obj->references} ? ( | |||||||||||||
| 40 | 'references' => [ | ||||||||||||||
| 41 | 0 | map { Wikibase::Datatype::Struct::Reference::obj2struct($_, $base_uri); } | |||||||||||||
| 42 | 0 | ▶ | @{$obj->references}, | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 43 | ], | ||||||||||||||
| 44 | ) : (), | ||||||||||||||
| 45 | 'type' => 'statement', | ||||||||||||||
| 46 | }; | ||||||||||||||
| 47 | |||||||||||||||
| 48 | 4 | return $struct_hr; | |||||||||||||
| 49 | } | ||||||||||||||
| 50 | |||||||||||||||
| 51 | 2 | ▶ | sub struct2obj { | ||||||||||||
|
Subroutine
struct2obj: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||
| 52 | 2 | my $struct_hr = shift; | |||||||||||||
| 53 | |||||||||||||||
| 54 | my $obj = Wikibase::Datatype::MediainfoStatement->new( | ||||||||||||||
| 55 | exists $struct_hr->{'id'} ? ('id' => $struct_hr->{'id'}) : (), | ||||||||||||||
| 56 | 'property_snaks' => struct2snaks_array_ref($struct_hr, 'qualifiers', | ||||||||||||||
| 57 | 'Wikibase::Datatype::Struct::MediainfoSnak'), | ||||||||||||||
| 58 | 'snak' => Wikibase::Datatype::Struct::MediainfoSnak::struct2obj($struct_hr->{'mainsnak'}), | ||||||||||||||
| 59 | 'references' => [ | ||||||||||||||
| 60 | 2 | map { Wikibase::Datatype::Struct::Reference::struct2obj($_) } | |||||||||||||
| 61 | 2 | @{$struct_hr->{'references'}} | |||||||||||||
| 62 | ], | ||||||||||||||
| 63 | 2 | ▶ | 'rank' => $struct_hr->{'rank'}, | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 64 | ); | ||||||||||||||
| 65 | |||||||||||||||
| 66 | 2 | return $obj; | |||||||||||||
| 67 | } | ||||||||||||||
| 68 | |||||||||||||||
| 69 | 10 | 1; | |||||||||||||
| 70 | |||||||||||||||
| 71 | __END__ | ||||||||||||||