DAIA/Item.pm

filter: Statementstmt 68.9% 51 / 74 Branchbran 62.5% 20 / 32 Conditioncond 83.3% 5 / 6 MC/DCmcdc 50.0% 2 / 4 Subroutinesub 100% 9 / 9 Podpod 100% 3 / 3 totaltotal 70.3% 90 / 128 CC 24 SCAR 30.2
CC
24
Cov
68%
rdfhash
48.5
services
6.0
__ANON__
4.4
CRAP 20.6
« DAIA/Response.pm ↑ Summary DAIA/Entity.pm »
1 package DAIA::Item;
2 #ABSTRACT: Holds information about an item of a L<DAIA::Document>
3 11 our $VERSION = '0.43'; #VERSION
4  
5 11 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 11 ▶use base 'DAIA::Object';
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 11 ▶use DAIA;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 11 ▶use JSON;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 our %PROPERTIES = (
12 id => $DAIA::Object::COMMON_PROPERTIES{id},
13 href => $DAIA::Object::COMMON_PROPERTIES{href},
14 message => $DAIA::Object::COMMON_PROPERTIES{message},
15 part => {
16 3 ▶ filter => sub {
Subroutine __ANON__: called CC=4 SCAR=14.9
17 3 ▶ my $status = shift or return;
Branch: 1 branch
BranchTrueFalseTotal
my $status = shift() or return 3 0 3
18 3 ▶ return unless $status eq 'broader' or $status eq 'narrower';
Branch: 1 branch
BranchTrueFalseTotal
unless $status eq "broader" or $status eq "narrower" 0 3 3
Condition66%2/3
$status eq "broader" or $status eq "narrower"
l!l&&r!l&&!r
210
MC/DC0%0/2
$status eq "broader" or $status eq "narrower"
$status eq "broader" $status eq "narrower"
Truth table66%2/3
A or B
A= $status eq "broader"B= $status eq "narrower"
ABresult
1X1
011
000
19 3 return $status;
20 }
21 },
22 label => {
23 default => '',
24 11 ▶ filter => sub { # label can be specified as array or as element
Subroutine __ANON__: called CC=3 SCAR=11.0
25 11 my $v = $_[0];
26 11 ▶ if (ref($v)) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $v) 2 9 11
27 2 ▶ $v = (ref($v) eq 'ARRAY') ? $v->[0] : '';
Branch: 1 branch
BranchTrueFalseTotal
ref $v eq 'ARRAY' ? : 1 1 2
28 }
29 11 return "$v";
30 },
31 },
32 11 department => { type => 'DAIA::Department' },
33 storage => { type => 'DAIA::Storage' },
34 available => { type => 'DAIA::Available', repeatable => 1 },
35 unavailable => { type => 'DAIA::Unavailable', repeatable => 1 },
36 );
37  
38  
39 1 ▶sub addAvailability {
Subroutine addAvailability: called CC=3 SCAR=11.7
Pod documented
40 1 my $self = shift;
41 1 ▶ return $self unless @_ > 0;
Branch: 1 branch
BranchTrueFalseTotal
unless @_ > 0 0 1 1
42 1 ▶ return $self->add(
Branch: 1 branch
BranchTrueFalseTotal
UNIVERSAL::isa($_[0], 'DAIA::Availability') ? : 0 1 1
43 UNIVERSAL::isa( $_[0], 'DAIA::Availability' )
44 ? $_[0]
45 : DAIA::Availability->new( @_ )
46 );
47 }
48  
49 11 *addService = *addAvailability;
50  
51  
52 7 ▶sub services {
Subroutine services: called CC=6 SCAR=17.9
Pod documented
53 7 my $self = shift;
54  
55 6 my %wanted = map { $_ => 1 }
56 7 map { $DAIA::Availability::SECIVRES{$_} ?
57 6 ▶ $DAIA::Availability::SECIVRES{$_} : $_ } @_;
Branch: 1 branch
BranchTrueFalseTotal
$DAIA::Availability::SECIVRES{$_} ? : 1 5 6
58  
59 7 my %services;
60 7 foreach my $a ( ($self->available, $self->unavailable) ) {
61 15 my $s = $a->service;
62 15 ▶ next if %wanted and not $wanted{$s};
Branch: 1 branch
BranchTrueFalseTotal
if %wanted and not $wanted{$s} 4 11 15
Condition100%3/3
%wanted and not $wanted{$s}
!ll&&!rl&&r
654
MC/DC100%2/2
%wanted and not $wanted{$s}
%wanted not $wanted{$s}
Truth table100%3/3
A and not(B)
A= %wantedB= not $wanted{$s}
ABresult
0X0
100
111
63 11 ▶ if ( $services{$s} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($services{$s}) { } 3 8 11
64 3 push @{ $services{$s} }, $a;
65 } else {
66 8 $services{$s} = [ $a ];
67 }
68 }
69  
70 7 return %services;
71 }
72  
73 1 ▶sub rdfhash {
Subroutine rdfhash: called CC=12 SCAR=38.8
Pod documented
74 1 my $self = shift;
75 1 my $me = { };
76  
77 1 $me->{'http://www.w3.org/1999/02/22-rdf-syntax-ns#type'} = [{
78 type => 'uri', value => 'http://purl.org/vocab/frbr/core#Item',
79 }];
80  
81 $me->{'http://xmlns.com/foaf/0.1/page'} = [{
82 value => $self->{href}, type => "uri"
83 1 ▶ }] if $self->{href};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"href"} 0 1 1
84  
85 $me->{'http://purl.org/dc/terms/description'} = [
86 0 map { $_->rdfhash } @{$self->{message}}
87 1 ▶ ] if $self->{message};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"message"} 0 1 1
88  
89 $me->{'http://purl.org/ontology/daia/label'} = [{
90 type => 'literal', value => $self->{label}
91 1 ▶ }] if $self->{label};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"label"} 0 1 1
92  
93 1 my $rdf = { };
94  
95 # TODO: department
96
97 1 ▶ if ($self->{storage}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"storage"}) 0 1 1
98 0 my $storage = $self->{storage}->rdfhash;
99 0 ▶ if ( $storage->{type} ) { # plain literal
Branch: 1 branch
BranchTrueFalseTotal
if ($storage->{'type'}) { } 0 0 0
100 0 $me->{'http://purl.org/dc/terms/spatial'} = [$storage];
101 } else {
102 0 my ($uri => $data) = %$storage;
103 0 $rdf->{$uri} = $data;
104 0 $me->{'http://purl.org/dc/terms/spatial'} = [{
105 type => 'uri', value => $uri
106 }];
107 }
108 0 my $r = $self->{storage}->rdfhash;
109 }
110  
111 1 ▶ if ($self->{available}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"available"}) 0 1 1
112 0 foreach my $s ( @{$self->{available}} ) {
113 0 my $r = $s->rdfhash;
114 0 $rdf->{$_} = $r->{$_} for keys %$r;
115 }
116 $me->{'http://purl.org/ontology/daia/availableFor'} = [
117 0 map { { type => 'uri', value => $_->rdfuri } } @{$self->{available}}
118 ];
119 # TODO: providedBy
120 }
121 1 ▶ if ($self->{unavailable}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"unavailable"}) 0 1 1
122 0 foreach my $s ( @{$self->{unavailable}} ) {
123 0 my $r = $s->rdfhash;
124 0 $rdf->{$_} = $r->{$_} for keys %$r;
125 }
126 $me->{'http://purl.org/ontology/daia/unavailableFor'} = [
127 0 map { { type => 'uri', value => $_->rdfuri } } @{$self->{unavailable}}
128 ];
129 # TODO: providedBy
130 }
131  
132 1 $rdf->{ $self->rdfuri } = $me;
133 1 return $rdf;
134 }
135  
136 11 1;
137  
138 __END__
« DAIA/Response.pm ↑ Summary DAIA/Entity.pm »