| 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
| |||||||||||||||||||||||
| 22 | 1 | err "Object doesn't exist."; | |||||||||||||||||||||
| 23 | } | ||||||||||||||||||||||
| 24 | 3 | ▶ | if (! defined $base_uri) { | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 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
| |||||||||||||||||||||||
| 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
| |||||||||||||||||||||||
| 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
| |||||||||||||||||||||||
| 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
| |||||||||||||||||||||||
| 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__ | ||||||||||||||||||||||