Bug 20888: (follow-up) revert unecessary change on jquery selector
[koha.git] / Koha / Biblio / Metadata.pm
blobb43a04bdb2f2c73b0eacd3400c618a3358551941
1 package Koha::Biblio::Metadata;
3 # This file is part of Koha.
5 # Koha is free software; you can redistribute it and/or modify it
6 # under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 3 of the License, or
8 # (at your option) any later version.
10 # Koha is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with Koha; if not, see <http://www.gnu.org/licenses>.
18 use Modern::Perl;
20 use MARC::Record;
21 use MARC::File::XML;
23 use Koha::Database;
24 use Koha::Exceptions::Metadata;
26 use base qw(Koha::Object);
28 =head1 NAME
30 Koha::Metadata - Koha Metadata Object class
32 =head1 API
34 =head2 Class methods
36 =cut
38 =head3 record
40 my $record = $metadata->record;
42 Returns an object representing the metadata record. The expected record type
43 corresponds to this table:
45 -------------------------------
46 | format | object type |
47 -------------------------------
48 | marcxml | MARC::Record |
49 -------------------------------
51 =head4 Error handling
53 =over
55 =item If an unsupported format is found, it throws a I<Koha::Exceptions::Metadata> exception.
57 =item If it fails to create the record object, it throws a I<Koha::Exceptions::Metadata::Invalid> exception.
59 =back
61 =cut
63 sub record {
65 my ($self) = @_;
67 my $record;
69 if ( $self->format eq 'marcxml' ) {
70 $record = eval { MARC::Record::new_from_xml( $self->metadata, 'UTF-8', $self->schema ); };
71 my $marcxml_error = $@;
72 chomp $marcxml_error;
73 unless ($record) {
74 Koha::Exceptions::Metadata::Invalid->throw(
75 id => $self->id,
76 format => $self->format,
77 schema => $self->schema,
78 decoding_error => $marcxml_error,
82 else {
83 Koha::Exceptions::Metadata->throw(
84 'Koha::Biblio::Metadata->record called on unhandled format: ' . $self->format );
87 return $record;
90 =head2 Internal methods
92 =head3 _type
94 =cut
96 sub _type {
97 return 'BiblioMetadata';