Skip to content

Commit

Permalink
Adding a default FMT field when none is given
Browse files Browse the repository at this point in the history
  • Loading branch information
phochste committed Sep 26, 2017
1 parent f78321c commit 6cc4a5d
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Build.PL
@@ -1,5 +1,5 @@

# This file was automatically generated by Dist::Zilla::Plugin::ModuleBuild v6.005.
# This file was automatically generated by Dist::Zilla::Plugin::ModuleBuild v6.008.
use strict;
use warnings;

Expand Down
1 change: 1 addition & 0 deletions README.md
Expand Up @@ -44,6 +44,7 @@ Catmandu::MARC - Catmandu modules for working with MARC data

# MODULES

- [Catmandu::MARC::Tutorial](https://metacpan.org/pod/Catmandu::MARC::Tutorial)
- [Catmandu::Importer::MARC](https://metacpan.org/pod/Catmandu::Importer::MARC)
- [Catmandu::Exporter::MARC](https://metacpan.org/pod/Catmandu::Exporter::MARC)
- [Catmandu::Fix::marc\_map](https://metacpan.org/pod/Catmandu::Fix::marc_map)
Expand Down
16 changes: 14 additions & 2 deletions lib/Catmandu/Exporter/MARC/ALEPHSEQ.pm
Expand Up @@ -40,6 +40,10 @@ An ARRAY of one or more fixes or file scripts to be applied to exported items.
Binmode of the output stream C<fh>. Set to "C<:utf8>" by default.
=item default_fmt
Set the value of the default C<FMT> field when none is given. Set to C<BK> by default.
=back
=head1 METHODS
Expand All @@ -63,8 +67,9 @@ our $VERSION = '1.18';
with 'Catmandu::Exporter', 'Catmandu::Exporter::MARC::Base';

has record => (is => 'ro' , default => sub { 'record'});
has record_format => (is => 'ro', default => sub { 'raw'} );
has record_format => (is => 'ro' , default => sub { 'raw'} );
has skip_empty_subfields => (is => 'ro' , default => sub { 0 });
has default_fmt => (is => 'ro' , default => sub { 'BK'} );

sub add {
my ($self,$data) = @_;
Expand All @@ -73,11 +78,18 @@ sub add {
$data = $self->_json_to_raw($data);
}

my $_id = sprintf("%-9.9d", $data->{_id} // 0);
my $id_str = $data->{_id};
$id_str =~ s{\D}{0}g if defined $id_str;
my $_id = sprintf("%-9.9d", $id_str // 0);
my $record = $data->{$self->record};

my @lines = ();

# Check required FMT field
if (@$record > 0 && $record->[0]->[0] ne 'FMT') {
push @lines , join('',$_id, ' ' , 'FMT', ' ', ' ' , ' L ' , $self->default_fmt);
}

for my $field (@$record) {
my ($tag,$ind1,$ind2,@data) = @$field;

Expand Down

0 comments on commit 6cc4a5d

Please sign in to comment.