| 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
| |||||||||||||||||||||||||||||
| 18 | 3 | ▶ | return unless $status eq 'broader' or $status eq 'narrower'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$status eq "broader" or $status eq "narrower"
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"
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 27 | 2 | ▶ | $v = (ref($v) eq 'ARRAY') ? $v->[0] : ''; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 42 | 1 | ▶ | return $self->add( | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
Condition100%3/3
%wanted and not $wanted{$s}
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}
| |||||||||||||||||||||||||||||
| 63 | 11 | ▶ | if ( $services{$s} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | $me->{'http://purl.org/dc/terms/description'} = [ | ||||||||||||||||||||||||||||
| 86 | 0 | map { $_->rdfhash } @{$self->{message}} | |||||||||||||||||||||||||||
| 87 | 1 | ▶ | ] if $self->{message}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | $me->{'http://purl.org/ontology/daia/label'} = [{ | ||||||||||||||||||||||||||||
| 90 | type => 'literal', value => $self->{label} | ||||||||||||||||||||||||||||
| 91 | 1 | ▶ | }] if $self->{label}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | 1 | my $rdf = { }; | |||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||
| 95 | # TODO: department | ||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | 1 | ▶ | if ($self->{storage}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 98 | 0 | my $storage = $self->{storage}->rdfhash; | |||||||||||||||||||||||||||
| 99 | 0 | ▶ | if ( $storage->{type} ) { # plain literal | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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__ | ||||||||||||||||||||||||||||