"Fossies" - the Fresh Open Source Software Archive 
Member "koha-19.11.15/Koha/Biblio/Metadata.pm" (23 Feb 2021, 2369 Bytes) of package /linux/misc/koha-19.11.15.tar.gz:
As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Perl source code syntax highlighting (style:
standard) with prefixed line numbers and
code folding option.
Alternatively you can here
view or
download the uninterpreted source code file.
For more information about "Metadata.pm" see the
Fossies "Dox" file reference documentation and the last
Fossies "Diffs" side-by-side code changes report:
20.11.01_vs_20.11.02.
1 package Koha::Biblio::Metadata;
2
3 # This file is part of Koha.
4 #
5 # Koha is free software; you can redistribute it and/or modify it under the
6 # terms of the GNU General Public License as published by the Free Software
7 # Foundation; either version 3 of the License, or (at your option) any later
8 # version.
9 #
10 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
11 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
12 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License along
15 # with Koha; if not, write to the Free Software Foundation, Inc.,
16 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17
18 use Modern::Perl;
19
20 use MARC::Record;
21 use MARC::File::XML;
22
23 use Koha::Database;
24 use Koha::Exceptions::Metadata;
25
26 use base qw(Koha::Object);
27
28 =head1 NAME
29
30 Koha::Metadata - Koha Metadata Object class
31
32 =head1 API
33
34 =head2 Class methods
35
36 =cut
37
38 =head3 record
39
40 my $record = $metadata->record;
41
42 Returns an object representing the metadata record. The expected record type
43 corresponds to this table:
44
45 -------------------------------
46 | format | object type |
47 -------------------------------
48 | marcxml | MARC::Record |
49 -------------------------------
50
51 =head4 Error handling
52
53 =over
54
55 =item If an unsupported format is found, it throws a I<Koha::Exceptions::Metadata> exception.
56
57 =item If it fails to create the record object, it throws a I<Koha::Exceptions::Metadata::Invalid> exception.
58
59 =back
60
61 =cut
62
63 sub record {
64
65 my ($self) = @_;
66
67 my $record;
68
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,
79 );
80 }
81 }
82 else {
83 Koha::Exceptions::Metadata->throw(
84 'Koha::Biblio::Metadata->record called on unhandled format: ' . $self->format );
85 }
86
87 return $record;
88 }
89
90 =head2 Internal methods
91
92 =head3 _type
93
94 =cut
95
96 sub _type {
97 return 'BiblioMetadata';
98 }
99
100 1;