Struct/Value/Time.pm

filter: Statementstmt 100% 41 / 41 Branchbran 100% 8 / 8 Conditioncond 100% 3 / 3 MC/DCmcdc 100% 2 / 2 Subroutinesub 100% 9 / 9 Podpod 100% 2 / 2 totaltotal 100% 65 / 65 CC 6 SCAR 8.3
CC
6
Cov
100%
obj2struct
4.0
struct2obj
3.0
BEGIN
1.0
CRAP 2.3
« Struct/Snak.pm ↑ Summary Struct/Value/String.pm »
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
BranchTrueFalseTotal
unless (defined $obj) 1 8 9
20 1 err "Object doesn't exist.";
21 }
22 8 ▶ if (! $obj->isa('Wikibase::Datatype::Value::Time')) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($obj->isa("Wikibase::Datatype::Value::Time")) 1 7 8
23 1 err "Object isn't 'Wikibase::Datatype::Value::Time'.";
24 }
25 7 ▶ if (! defined $base_uri) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $base_uri) 1 6 7
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
BranchTrueFalseTotal
if (not exists $struct_hr->{"type"} or $struct_hr->{"type"} ne "time") 2 8 10
Condition100%3/3
not exists $struct_hr->{"type"} or $struct_hr->{"type"} ne "time"
l!l&&r!l&&!r
118
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"
ABresult
1X1
011
000
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__
« Struct/Snak.pm ↑ Summary Struct/Value/String.pm »