| 1 | package Net::OAI::GetRecord; | ||||||||||||||||||||||
| 2 | |||||||||||||||||||||||
| 3 | 17 | ▶ | use strict; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 4 | 17 | ▶ | use warnings; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 5 | 17 | ▶ | use base qw( XML::SAX::Base Net::OAI::Base ); | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 6 | 17 | ▶ | use Net::OAI::Record::Header; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 7 | |||||||||||||||||||||||
| 8 | =head1 NAME | ||||||||||||||||||||||
| 9 | |||||||||||||||||||||||
| 10 | Net::OAI::GetRecord - The results of a GetRecord OAI-PMH verb. | ||||||||||||||||||||||
| 11 | |||||||||||||||||||||||
| 12 | =head1 SYNOPSIS | ||||||||||||||||||||||
| 13 | |||||||||||||||||||||||
| 14 | =head1 DESCRIPTION | ||||||||||||||||||||||
| 15 | |||||||||||||||||||||||
| 16 | =head1 METHODS | ||||||||||||||||||||||
| 17 | |||||||||||||||||||||||
| 18 | =head2 new() | ||||||||||||||||||||||
| 19 | |||||||||||||||||||||||
| 20 | =cut | ||||||||||||||||||||||
| 21 | |||||||||||||||||||||||
| 22 | sub new { | ||||||||||||||||||||||
| 23 | 9 | ▶ | my ( $class, %opts ) = @_; | ||||||||||||||||||||
|
Subroutine
new: called CC=5 SCAR=16.2
Pod
documented
| |||||||||||||||||||||||
| 24 | |||||||||||||||||||||||
| 25 | 9 | my $package; | |||||||||||||||||||||
| 26 | 9 | ▶ | if ( $package = $opts{ recordHandler } ) { | ||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||
| 27 | 3 | ▶ | $opts{ metadataHandler } and croak( "you may pass either a recordHandler or a metadataHandler to getRecord()" ); | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 28 | 3 | delete $opts { metadataHandler }; | |||||||||||||||||||||
| 29 | } elsif ( $package = $opts{ metadataHandler } ) { | ||||||||||||||||||||||
| 30 | 4 | delete $opts{ recordHandler }; | |||||||||||||||||||||
| 31 | } else { | ||||||||||||||||||||||
| 32 | 2 | delete $opts{ recordHandler }; | |||||||||||||||||||||
| 33 | 2 | $package = $opts{ metadataHandler } = 'Net::OAI::Record::OAI_DC'; | |||||||||||||||||||||
| 34 | } | ||||||||||||||||||||||
| 35 | 9 | Net::OAI::Harvester::_verifyHandler( $package ); | |||||||||||||||||||||
| 36 | |||||||||||||||||||||||
| 37 | 9 | ▶ | my $self = bless \%opts, ref( $class ) || $class; | ||||||||||||||||||||
|
Condition33%1/3
ref $class || $class
MC/DC0%0/2
ref $class || $class
ref $class
$class
Truth table33%1/3
A || B
A= ref $classB= $class
| |||||||||||||||||||||||
| 38 | 9 | $self->{ header } = undef; | |||||||||||||||||||||
| 39 | 9 | $self->{ _prefixmap } = {}; | |||||||||||||||||||||
| 40 | 9 | return( $self ); | |||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||
| 42 | |||||||||||||||||||||||
| 43 | =head2 record() | ||||||||||||||||||||||
| 44 | |||||||||||||||||||||||
| 45 | return the result as Net::OAI::Record. | ||||||||||||||||||||||
| 46 | |||||||||||||||||||||||
| 47 | =cut | ||||||||||||||||||||||
| 48 | |||||||||||||||||||||||
| 49 | sub record { | ||||||||||||||||||||||
| 50 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||
|
Subroutine
record: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||
| 51 | 0 | return $self->{ record }; | |||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||
| 53 | |||||||||||||||||||||||
| 54 | =head2 header() | ||||||||||||||||||||||
| 55 | |||||||||||||||||||||||
| 56 | Shortcut to the C<header()> method of the L<Net::OAI::Record> fetched. | ||||||||||||||||||||||
| 57 | |||||||||||||||||||||||
| 58 | =cut | ||||||||||||||||||||||
| 59 | |||||||||||||||||||||||
| 60 | sub header { | ||||||||||||||||||||||
| 61 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||
|
Subroutine
header: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||
| 62 | 0 | return $self->{ record }->header; | |||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||
| 64 | |||||||||||||||||||||||
| 65 | =head2 metadata() | ||||||||||||||||||||||
| 66 | |||||||||||||||||||||||
| 67 | Shortcut to the C<metadata()> method of the L<Net::OAI::Record> fetched. | ||||||||||||||||||||||
| 68 | The return value may be undefined in case of deleted records or if no | ||||||||||||||||||||||
| 69 | metadataHandler was provided. | ||||||||||||||||||||||
| 70 | |||||||||||||||||||||||
| 71 | =cut | ||||||||||||||||||||||
| 72 | |||||||||||||||||||||||
| 73 | sub metadata { | ||||||||||||||||||||||
| 74 | 1 | ▶ | my $self = shift; | ||||||||||||||||||||
|
Subroutine
metadata: called CC=3 SCAR=15.4
Pod
documented
| |||||||||||||||||||||||
| 75 | 1 | ▶ | return undef unless $self->{ record }; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 76 | 0 | ▶ | return $self->{ metadataHandler } ? $self->{ record }->metadata() : undef; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||
| 78 | |||||||||||||||||||||||
| 79 | |||||||||||||||||||||||
| 80 | =head2 recorddata() | ||||||||||||||||||||||
| 81 | |||||||||||||||||||||||
| 82 | Shortcut to the C<recorddata()> method of the L<Net::OAI::Record> fetched. | ||||||||||||||||||||||
| 83 | The return value may be undefined in case of deleted records or if no | ||||||||||||||||||||||
| 84 | metadataHandler was provided. | ||||||||||||||||||||||
| 85 | |||||||||||||||||||||||
| 86 | =cut | ||||||||||||||||||||||
| 87 | |||||||||||||||||||||||
| 88 | sub recorddata { | ||||||||||||||||||||||
| 89 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||
|
Subroutine
recorddata: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||
| 90 | 0 | ▶ | return undef unless $self->{ record }; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 91 | 0 | ▶ | return $self->{ recordHandler } ? $self->{ record }->recorddata() : undef; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||
| 93 | |||||||||||||||||||||||
| 94 | |||||||||||||||||||||||
| 95 | ## SAX Handlers doing about the same as those of ListRecords.pm | ||||||||||||||||||||||
| 96 | |||||||||||||||||||||||
| 97 | sub start_prefix_mapping { | ||||||||||||||||||||||
| 98 | 0 | ▶ | my ($self, $mapping) = @_; | ||||||||||||||||||||
|
Subroutine
start_prefix_mapping: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||
| 99 | 0 | ▶ | if ( $self->get_handler() ) { | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 100 | 0 | return $self->SUPER::start_prefix_mapping( $mapping )}; | |||||||||||||||||||||
| 101 | 0 | $self->{ _prefixmap }->{$mapping->{ Prefix }} = $mapping; | |||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||
| 103 | |||||||||||||||||||||||
| 104 | sub end_prefix_mapping { | ||||||||||||||||||||||
| 105 | 0 | ▶ | my ($self, $mapping) = @_; | ||||||||||||||||||||
|
Subroutine
end_prefix_mapping: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||
| 106 | 0 | ▶ | if ( $self->get_handler() ) { | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 107 | 0 | return $self->SUPER::end_prefix_mapping( $mapping )}; | |||||||||||||||||||||
| 108 | 0 | delete $self->{ _prefixmap }->{$mapping->{ Prefix }}; | |||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||
| 110 | |||||||||||||||||||||||
| 111 | sub start_element { | ||||||||||||||||||||||
| 112 | 0 | ▶ | my ( $self, $element ) = @_; | ||||||||||||||||||||
|
Subroutine
start_element: not called CC=8 SCAR=42.8
Pod
documented
| |||||||||||||||||||||||
| 113 | 0 | ▶ | return $self->SUPER::start_element($element) unless $element->{NamespaceURI} eq Net::OAI::Harvester::XMLNS_OAI; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 114 | |||||||||||||||||||||||
| 115 | ## if we are at the start of a new record then we need an empty | ||||||||||||||||||||||
| 116 | ## metadata object to fill up | ||||||||||||||||||||||
| 117 | 0 | ▶ | if ( ($element->{ LocalName } eq 'record') ) { | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 118 | ## we store existing downstream handler so we can replace | ||||||||||||||||||||||
| 119 | ## it after we are done retrieving the metadata record | ||||||||||||||||||||||
| 120 | 0 | $self->{ OLD_Handler } = $self->get_handler(); | |||||||||||||||||||||
| 121 | my $header = $self->{ recordHandler } | ||||||||||||||||||||||
| 122 | ? Net::OAI::Record::Header->new( | ||||||||||||||||||||||
| 123 | Handler => (ref($self->{ recordHandler }) ? $self->{ recordHandler } : $self->{ recordHandler }->new()), | ||||||||||||||||||||||
| 124 | fwdAll => 1, | ||||||||||||||||||||||
| 125 | ) | ||||||||||||||||||||||
| 126 | : Net::OAI::Record::Header->new( | ||||||||||||||||||||||
| 127 | 0 | ▶ | Handler => (ref($self->{ metadataHandler }) ? $self->{ metadataHandler } : $self->{ metadataHandler }->new()), | ||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||
| 128 | ($Net::OAI::Harvester::OLDmetadataHandler ? (fwdAll => 1) : ()), | ||||||||||||||||||||||
| 129 | ); | ||||||||||||||||||||||
| 130 | 0 | $self->set_handler( $header ); | |||||||||||||||||||||
| 131 | 0 | foreach my $mapping ( values %{$self->{_prefixmap}} ) { | |||||||||||||||||||||
| 132 | 0 | $self->SUPER::start_prefix_mapping($mapping)}; | |||||||||||||||||||||
| 133 | } | ||||||||||||||||||||||
| 134 | 0 | return $self->SUPER::start_element( $element ); | |||||||||||||||||||||
| 135 | } | ||||||||||||||||||||||
| 136 | |||||||||||||||||||||||
| 137 | sub end_element { | ||||||||||||||||||||||
| 138 | 0 | ▶ | my ( $self, $element ) = @_; | ||||||||||||||||||||
|
Subroutine
end_element: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||
| 139 | |||||||||||||||||||||||
| 140 | 0 | $self->SUPER::end_element( $element ); | |||||||||||||||||||||
| 141 | 0 | ▶ | return unless $element->{NamespaceURI} eq Net::OAI::Harvester::XMLNS_OAI; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 142 | |||||||||||||||||||||||
| 143 | ## if we've got to the end of the record we need finish up | ||||||||||||||||||||||
| 144 | ## the object | ||||||||||||||||||||||
| 145 | 0 | ▶ | if ( $element->{ LocalName } eq 'record' ) { | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 146 | 0 | my $header = $self->get_handler(); | |||||||||||||||||||||
| 147 | 0 | my $data = $header->get_handler(); | |||||||||||||||||||||
| 148 | 0 | $header->set_handler( undef ); ## remove reference to $metadata | |||||||||||||||||||||
| 149 | 0 | my $record; | |||||||||||||||||||||
| 150 | 0 | ▶ | if ( $self->{ recordHandler } ) { | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 151 | 0 | $record = Net::OAI::Record->new(header => $header, recorddata => $data) | |||||||||||||||||||||
| 152 | } else { | ||||||||||||||||||||||
| 153 | 0 | $record = Net::OAI::Record->new(header => $header, metadata => $data) | |||||||||||||||||||||
| 154 | }; | ||||||||||||||||||||||
| 155 | 0 | $self->{ record } = $record; | |||||||||||||||||||||
| 156 | ## set handler to what is was before we started processing | ||||||||||||||||||||||
| 157 | ## the record | ||||||||||||||||||||||
| 158 | 0 | $self->set_handler( $self->{ OLD_Handler } ); | |||||||||||||||||||||
| 159 | } | ||||||||||||||||||||||
| 160 | } | ||||||||||||||||||||||
| 161 | |||||||||||||||||||||||
| 162 | 17 | 1; | |||||||||||||||||||||
| 163 | |||||||||||||||||||||||