Skip to content

Commit

Permalink
Fixing empty record bug
Browse files Browse the repository at this point in the history
  • Loading branch information
phochste committed Jul 14, 2023
1 parent acd7540 commit 2b9988d
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 20 deletions.
5 changes: 3 additions & 2 deletions Changes
@@ -1,12 +1,13 @@
Revision history for Catmandu-MARC

{{$NEXT}}
- Fixing empty record bug (obs FaMIbine)

1.30 2023-05-27 06:14:57 CEST
- Fixing marc_add data_at path for indicators (obj Tiago Murakami)
- Fixing marc_add data_at path for indicators (obs Tiago Murakami)

1.29 2022-11-23 19:55:54 CET
- Fixing MiJ utf8 bug (obj Uldis Bojars)
- Fixing MiJ utf8 bug (obs Uldis Bojars)

1.281 2022-08-17 09:26:17 CEST
- Minor fixes in tutorial [VladimirAlexiev]
Expand Down
14 changes: 9 additions & 5 deletions lib/Catmandu/Exporter/MARC/ISO.pm
Expand Up @@ -70,13 +70,17 @@ has record_format => (is => 'ro' , default => sub { 'raw'} );
sub add {
my ($self, $data) = @_;

if ($self->record_format eq 'MARC-in-JSON') {
$data = $self->_json_to_raw($data);
}
if (keys %$data) {
if ($self->record_format eq 'MARC-in-JSON') {
$data = $self->_json_to_raw($data);
}

my $marc = $self->_raw_to_marc_record($data->{$self->record});
if ($data->{$self->record}) {
my $marc = $self->_raw_to_marc_record($data->{$self->record});

$self->fh->print(MARC::File::USMARC::encode($marc));
$self->fh->print(MARC::File::USMARC::encode($marc));
}
}
}

sub commit {
Expand Down
28 changes: 15 additions & 13 deletions lib/Catmandu/Exporter/MARC/XML.pm
Expand Up @@ -13,7 +13,21 @@ has skip_empty_subfields => (is => 'ro' , default => sub { 1 });
has collection => (is => 'ro' , default => sub { 1 });
has xml_declaration => (is => 'ro' , default => sub { 1 });
has pretty => (is => 'rw' , default => sub { 0 });
has _n => (is => 'rw' , default => sub { 0 });

sub BUILD {
my ($self, $args) = @_;

if ($self->xml_declaration) {
$self->buffer_add( Catmandu::Util::xml_declaration );
}

if ($self->collection) {
$self->_line(0,'<marc:collection xmlns:marc="http://www.loc.gov/MARC21/slim">');
}

$self->fh->print( join('', @{ $self->buffer } ) );
$self->clear_buffer;
}

sub _line {
my ($self, $indent, $line) = @_;
Expand All @@ -28,18 +42,6 @@ sub _line {
sub add {
my ($self, $data) = @_;

if ($self->_n == 0) {
if ($self->xml_declaration) {
$self->buffer_add( Catmandu::Util::xml_declaration );
}

if ($self->collection) {
$self->_line(0,'<marc:collection xmlns:marc="http://www.loc.gov/MARC21/slim">');
}

$self->_n(1);
}

my $indent = $self->collection ? 1 : 0;

if ($self->record_format eq 'MARC-in-JSON') {
Expand Down

0 comments on commit 2b9988d

Please sign in to comment.