| 1 | package Wikibase::Datatype::Struct::Value::Globecoordinate; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 54 | ▶ | use base qw(Exporter); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 54 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 54 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 54 | ▶ | use Error::Pure qw(err); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 54 | ▶ | use Readonly; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 54 | ▶ | use URI; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 54 | ▶ | use Wikibase::Datatype::Value::Globecoordinate; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 54 | Readonly::Array our @EXPORT_OK => qw(obj2struct struct2obj); | |||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | 54 | our $VERSION = 0.15; | |||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | 6 | ▶ | sub obj2struct { | ||||||||||||||||||||||||||
|
Subroutine
obj2struct: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||||||||||
| 17 | 6 | my ($obj, $base_uri) = @_; | |||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | 6 | ▶ | if (! defined $obj) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 20 | 1 | err "Object doesn't exist."; | |||||||||||||||||||||||||||
| 21 | } | ||||||||||||||||||||||||||||
| 22 | 5 | ▶ | if (! $obj->isa('Wikibase::Datatype::Value::Globecoordinate')) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 23 | 1 | err "Object isn't 'Wikibase::Datatype::Value::Globecoordinate'."; | |||||||||||||||||||||||||||
| 24 | } | ||||||||||||||||||||||||||||
| 25 | 4 | ▶ | if (! defined $base_uri) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 26 | 1 | err 'Base URI is required.'; | |||||||||||||||||||||||||||
| 27 | } | ||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | 3 | ▶ | my $struct_hr = { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 30 | 'value' => { | ||||||||||||||||||||||||||||
| 31 | 'altitude' => $obj->altitude ? $obj->altitude : 'null', | ||||||||||||||||||||||||||||
| 32 | 'globe' => $base_uri.$obj->globe, | ||||||||||||||||||||||||||||
| 33 | 'latitude' => $obj->latitude, | ||||||||||||||||||||||||||||
| 34 | 'longitude' => $obj->longitude, | ||||||||||||||||||||||||||||
| 35 | 'precision' => $obj->precision, | ||||||||||||||||||||||||||||
| 36 | }, | ||||||||||||||||||||||||||||
| 37 | 'type' => $obj->type, | ||||||||||||||||||||||||||||
| 38 | }; | ||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | 3 | return $struct_hr; | |||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | 6 | ▶ | sub struct2obj { | ||||||||||||||||||||||||||
|
Subroutine
struct2obj: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||
| 44 | 6 | my $struct_hr = shift; | |||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | 6 | ▶ | if (! exists $struct_hr->{'type'} | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
not exists $struct_hr->{"type"} or $struct_hr->{"type"} ne "globecoordinate"
MC/DC100%2/2
not exists $struct_hr->{"type"} or $struct_hr->{"type"} ne "globecoordinate"
not exists $struct_hr->{"type"}
$struct_hr->{"type"} ne "globecoordinate"
Truth table100%3/3
not(A) or B
A= not exists $struct_hr->{"type"}B= $struct_hr->{"type"} ne "globecoordinate"
| |||||||||||||||||||||||||||||
| 47 | || $struct_hr->{'type'} ne 'globecoordinate') { | ||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | 2 | err "Structure isn't for 'globecoordinate' datatype."; | |||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | 4 | my $u = URI->new($struct_hr->{'value'}->{'globe'}); | |||||||||||||||||||||||||||
| 53 | 4 | my @path_segments = $u->path_segments; | |||||||||||||||||||||||||||
| 54 | 4 | my $globe = $path_segments[-1]; | |||||||||||||||||||||||||||
| 55 | my $obj = Wikibase::Datatype::Value::Globecoordinate->new( | ||||||||||||||||||||||||||||
| 56 | defined $struct_hr->{'value'}->{'altitude'} ? ( | ||||||||||||||||||||||||||||
| 57 | 'altitude' => $struct_hr->{'value'}->{'altitude'}, | ||||||||||||||||||||||||||||
| 58 | ) : (), | ||||||||||||||||||||||||||||
| 59 | 'globe' => $globe, | ||||||||||||||||||||||||||||
| 60 | 'precision' => $struct_hr->{'value'}->{'precision'}, | ||||||||||||||||||||||||||||
| 61 | 'value' => [ | ||||||||||||||||||||||||||||
| 62 | $struct_hr->{'value'}->{'latitude'}, | ||||||||||||||||||||||||||||
| 63 | 4 | ▶ | $struct_hr->{'value'}->{'longitude'}, | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 64 | ], | ||||||||||||||||||||||||||||
| 65 | ); | ||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | 4 | return $obj; | |||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | 54 | 1; | |||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | __END__ | ||||||||||||||||||||||||||||