| 1 | package Wikibase::Datatype::Struct::Value::Time; | ||||||||||||||||||||||||||||
| 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::Time; | ||||||||||||||||||||||||||
|
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 | 9 | ▶ | sub obj2struct { | ||||||||||||||||||||||||||
|
Subroutine
obj2struct: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||
| 17 | 9 | my ($obj, $base_uri) = @_; | |||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | 9 | ▶ | if (! defined $obj) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 20 | 1 | err "Object doesn't exist."; | |||||||||||||||||||||||||||
| 21 | } | ||||||||||||||||||||||||||||
| 22 | 8 | ▶ | if (! $obj->isa('Wikibase::Datatype::Value::Time')) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 23 | 1 | err "Object isn't 'Wikibase::Datatype::Value::Time'."; | |||||||||||||||||||||||||||
| 24 | } | ||||||||||||||||||||||||||||
| 25 | 7 | ▶ | if (! defined $base_uri) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 26 | 1 | err 'Base URI is required.'; | |||||||||||||||||||||||||||
| 27 | } | ||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | 6 | my $struct_hr = { | |||||||||||||||||||||||||||
| 30 | 'value' => { | ||||||||||||||||||||||||||||
| 31 | 'after' => $obj->after, | ||||||||||||||||||||||||||||
| 32 | 'before' => $obj->before, | ||||||||||||||||||||||||||||
| 33 | 'calendarmodel' => $base_uri.$obj->calendarmodel, | ||||||||||||||||||||||||||||
| 34 | 'precision' => $obj->precision, | ||||||||||||||||||||||||||||
| 35 | 'time' => $obj->value, | ||||||||||||||||||||||||||||
| 36 | 'timezone' => $obj->timezone, | ||||||||||||||||||||||||||||
| 37 | }, | ||||||||||||||||||||||||||||
| 38 | 'type' => 'time', | ||||||||||||||||||||||||||||
| 39 | }; | ||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | 6 | return $struct_hr; | |||||||||||||||||||||||||||
| 42 | } | ||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | 10 | ▶ | sub struct2obj { | ||||||||||||||||||||||||||
|
Subroutine
struct2obj: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||
| 45 | 10 | my $struct_hr = shift; | |||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | 10 | ▶ | if (! exists $struct_hr->{'type'} | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
not exists $struct_hr->{"type"} or $struct_hr->{"type"} ne "time"
MC/DC100%2/2
not exists $struct_hr->{"type"} or $struct_hr->{"type"} ne "time"
not exists $struct_hr->{"type"}
$struct_hr->{"type"} ne "time"
Truth table100%3/3
not(A) or B
A= not exists $struct_hr->{"type"}B= $struct_hr->{"type"} ne "time"
| |||||||||||||||||||||||||||||
| 48 | || $struct_hr->{'type'} ne 'time') { | ||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | 2 | err "Structure isn't for 'time' datatype."; | |||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | 8 | my $u = URI->new($struct_hr->{'value'}->{'calendarmodel'}); | |||||||||||||||||||||||||||
| 54 | 8 | my @path_segments = $u->path_segments; | |||||||||||||||||||||||||||
| 55 | 8 | my $calendar_model = $path_segments[-1]; | |||||||||||||||||||||||||||
| 56 | my $obj = Wikibase::Datatype::Value::Time->new( | ||||||||||||||||||||||||||||
| 57 | 'after' => $struct_hr->{'value'}->{'after'}, | ||||||||||||||||||||||||||||
| 58 | 'before' => $struct_hr->{'value'}->{'before'}, | ||||||||||||||||||||||||||||
| 59 | 'calendarmodel' => $calendar_model, | ||||||||||||||||||||||||||||
| 60 | 'precision' => $struct_hr->{'value'}->{'precision'}, | ||||||||||||||||||||||||||||
| 61 | 'timezone' => $struct_hr->{'value'}->{'timezone'}, | ||||||||||||||||||||||||||||
| 62 | 8 | 'value' => $struct_hr->{'value'}->{'time'}, | |||||||||||||||||||||||||||
| 63 | ); | ||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | 8 | return $obj; | |||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | 54 | 1; | |||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | __END__ | ||||||||||||||||||||||||||||