File: Record.pm

package info (click to toggle)
libhttp-oai-perl 4.03-2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 416 kB
  • ctags: 326
  • sloc: perl: 2,531; xml: 224; makefile: 12
file content (148 lines) | stat: -rw-r--r-- 3,269 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
package HTTP::OAI::Record;

@ISA = qw( HTTP::OAI::MemberMixin HTTP::OAI::SAX::Base );

use strict;

sub new {
	my ($class,%args) = @_;

	$args{header} ||= HTTP::OAI::Header->new(%args);

	return $class->SUPER::new(%args);
}

sub header { shift->_elem('header',@_) }
sub metadata { shift->_elem('metadata',@_) }
sub about { shift->_multi('about',@_) }

sub identifier { shift->header->identifier(@_) }
sub datestamp { shift->header->datestamp(@_) }
sub status { shift->header->status(@_) }
sub is_deleted { shift->header->is_deleted(@_) }

sub generate
{
	my( $self, $driver ) = @_;

	$driver->start_element('record');
	$self->header->generate( $driver );
	$self->metadata->generate( $driver ) if defined $self->metadata;
	$self->about->generate( $driver ) for $self->about;
	$driver->end_element('record');
}

sub start_element {
	my ($self,$hash, $r) = @_;

	if( !$self->{in_record} )
	{
		my $elem = lc($hash->{LocalName});
		if( $elem eq 'record' && $hash->{Attributes}->{'{}status'}->{Value} )
		{
			$self->status($hash->{Attributes}->{'{}status'}->{Value});
		}
		elsif( $elem eq "header" )
		{
			$self->set_handler(my $handler = HTTP::OAI::Header->new);
			$self->header( $handler );
			$self->{in_record} = $hash->{Depth};
		}
		elsif( $elem =~ /^metadata|about$/ )
		{
			my $class = $r->handlers->{$elem} || "HTTP::OAI::Metadata";
			$self->set_handler(my $handler = $class->new);
			$self->$elem($handler);
			$self->{in_record} = $hash->{Depth};
		}
	}

	$self->SUPER::start_element($hash, $r);
}

sub end_element {
	my ($self,$hash, $r) = @_;

	$self->SUPER::end_element($hash, $r);

	if( $self->{in_record} == $hash->{Depth} )
	{
		$self->set_handler( undef );
		$self->{in_record} = 0;
	}
}

1;

__END__

=head1 NAME

HTTP::OAI::Record - Encapsulates an OAI record

=head1 SYNOPSIS

	use HTTP::OAI::Record;

	# Create a new HTTP::OAI Record
	my $r = new HTTP::OAI::Record();

	$r->header->identifier('oai:myarchive.org:oid-233');
	$r->header->datestamp('2002-04-01');
	$r->header->setSpec('all:novels');
	$r->header->setSpec('all:books');

	$r->metadata(new HTTP::OAI::Metadata(dom=>$md));
	$r->about(new HTTP::OAI::Metadata(dom=>$ab));

=head1 METHODS

=over 4

=item $r = new HTTP::OAI::Record( %opts )

This constructor method returns a new L<HTTP::OAI::Record> object.

Options (see methods below):

	header => $header
	metadata => $metadata
	about => [$about]

=item $r->header([HTTP::OAI::Header])

Returns and optionally sets the record header (an L<HTTP::OAI::Header> object).

=item $r->metadata([HTTP::OAI::Metadata])

Returns and optionally sets the record metadata (an L<HTTP::OAI::Metadata> object).

=item $r->about([HTTP::OAI::Metadata])

Optionally adds a new About record (an L<HTTP::OAI::Metadata> object) and returns an array of objects (may be empty).

=back

=head2 Header Accessor Methods

These methods are equivalent to C<< $rec->header->$method([$value]) >>.

=over 4

=item $r->identifier([$identifier])

Get and optionally set the record OAI identifier.

=item $r->datestamp([$datestamp])

Get and optionally set the record datestamp.

=item $r->status([$status])

Get and optionally set the record status (valid values are 'deleted' or undef).

=item $r->is_deleted()

Returns whether this record's status is deleted.

=back