This is an automated email from the git hooks/post-receive script. js pushed a commit to annotated tag upstream/1.19 in repository libcatmandu-marc-perl.
commit e0aabba5bcf0a0d0772b0f2484b6e3d6ac30f2a0 Author: Jakob Voss <[email protected]> Date: Tue Jan 24 13:38:39 2017 +0100 Rewrite documentation of ::{Importer,Exporter}::MARC --- lib/Catmandu/Exporter/MARC.pm | 113 ++++++++++------------- lib/Catmandu/Importer/MARC.pm | 203 ++++++++++++++++++++---------------------- 2 files changed, 141 insertions(+), 175 deletions(-) diff --git a/lib/Catmandu/Exporter/MARC.pm b/lib/Catmandu/Exporter/MARC.pm index 7680308..b465d56 100644 --- a/lib/Catmandu/Exporter/MARC.pm +++ b/lib/Catmandu/Exporter/MARC.pm @@ -1,3 +1,38 @@ +package Catmandu::Exporter::MARC; +use Catmandu::Sane; +use Moo; + +our $VERSION = '1.05'; + +has type => (is => 'ro' , default => sub { 'ISO' }); +has _exporter => (is => 'ro' , lazy => 1 , builder => '_build_exporter' , handles => 'Catmandu::Exporter'); +has _exporter_args => (is => 'rwp', writer => '_set_exporter_args'); + +sub _build_exporter { + my ($self) = @_; + + my $type = $self->type; + + my $pkg = Catmandu::Util::require_package($type,'Catmandu::Exporter::MARC'); + + $pkg->new($self->_exporter_args); +} + +sub BUILD { + my ($self,$args) = @_; + $self->_set_exporter_args($args); + + # keep USMARC temporary as alias for ISO, remove in future version + # print deprecation warning + if ($self->{type} eq 'USMARC') { + $self->{type} = 'ISO'; + warn( "deprecated", "Oops! Exporter \"USMARC\" is deprecated. Use \"ISO\" instead." ); + } +} + +1; +__END__ + =head1 NAME Catmandu::Exporter::MARC - Exporter for MARC records @@ -8,10 +43,10 @@ Catmandu::Exporter::MARC - Exporter for MARC records $ catmandu convert MARC --type ISO to MARC --type XML < /foo/bar.mrc # From Perl - use Catmandu; + use Catmandui -all; - my $importer = Catmandu->importer('MARC', file => "/foo/bar.mrc" , type => 'ISO'); - my $exporter = Catmandu->exporter('MARC', file => "marc.xml", type => "XML" ); + my $importer = importer('MARC', file => "/foo/bar.mrc" , type => 'ISO'); + my $exporter = exporter('MARC', file => "marc.xml", type => "XML" ); $exporter->add($importer); $exporter->commit; @@ -23,85 +58,29 @@ to a file or the standard output. =head1 CONFIGURATION +In addition to the configuration provided by L<Catmandu::Exporter> (C<file>, +C<fh>, etc.) the exporter can be configured with the following parameters: + =over =item type -Create a new MARC exporter of the given type. Currently we support: +Describes the MARC syntax variant. Supported values include: =over -=item * USMARC: alias for ISO, B<deprecated, will be removed in future version> - -=item * ISO: L<Catmandu::Importer::MARC::ISO> +=item * ISO: L<Catmandu::Exporter::MARC::ISO> (default) =item * XML: L<Catmandu::Exporter::MARC::XML> =item * MARCMaker: L<Catmandu::Exporter::MARC::MARCMaker> -=item * MiJ: L<Catmandu::Exporter::MARC::MiJ> (Marc in Json) +=item * MiJ: L<Catmandu::Exporter::MARC::MiJ> (MARC in JSON) =item * ALEPHSEQ: L<Catmandu::Exporter::MARC::ALEPHSEQ> -=back - -=item file - -Write output to a local file given by its path or file handle. Alternatively a -scalar reference can be passed to write to a string and a code reference can be -used to write to a callback function. - -=item fh - -Write the output to an L<IO::Handle>. If not specified, -L<Catmandu::Util::io|Catmandu::Util/IO-functions> is used to create the output -handle from the C<file> argument or by using STDOUT. - -=item fix - -An ARRAY of one or more fixes or file scripts to be applied to exported items. - -=item encoding - -Binmode of the output stream C<fh>. Set to "C<:utf8>" by default. - -=back - =head1 SEE ALSO -L<Catmandu::Exporter> - -=cut -package Catmandu::Exporter::MARC; -use Catmandu::Sane; -use Moo; +L<Catmandu::Importer::MARC> -our $VERSION = '1.05'; - -has type => (is => 'ro' , default => sub { 'ISO' }); -has _exporter => (is => 'ro' , lazy => 1 , builder => '_build_exporter' , handles => 'Catmandu::Exporter'); -has _exporter_args => (is => 'rwp', writer => '_set_exporter_args'); - -sub _build_exporter { - my ($self) = @_; - - my $type = $self->type; - - my $pkg = Catmandu::Util::require_package($type,'Catmandu::Exporter::MARC'); - - $pkg->new($self->_exporter_args); -} - -sub BUILD { - my ($self,$args) = @_; - $self->_set_exporter_args($args); - - # keep USMARC temporary as alias for ISO, remove in future version - # print deprecation warning - if ($self->{type} eq 'USMARC') { - $self->{type} = 'ISO'; - warn( "deprecated", "Oops! Exporter \"USMARC\" is deprecated. Use \"ISO\" instead." ); - } -} - -1; +=back diff --git a/lib/Catmandu/Importer/MARC.pm b/lib/Catmandu/Importer/MARC.pm index fe8743d..1a89307 100644 --- a/lib/Catmandu/Importer/MARC.pm +++ b/lib/Catmandu/Importer/MARC.pm @@ -1,86 +1,137 @@ +package Catmandu::Importer::MARC; +use Catmandu::Sane; +use Catmandu::Util; +use Moo; + +our $VERSION = '1.05'; + +has type => (is => 'ro' , default => sub { 'ISO' }); +has _importer => (is => 'ro' , lazy => 1 , builder => '_build_importer' , handles => ['generator']); +has _importer_args => (is => 'rwp', writer => '_set_importer_args'); + +with 'Catmandu::Importer'; + +sub _build_importer { + my ($self) = @_; + + my $type = $self->type; + + $type = 'Record' if exists $self->_importer_args->{records}; + + my $pkg = Catmandu::Util::require_package($type,'Catmandu::Importer::MARC'); + + $pkg->new($self->_importer_args); +} + +sub BUILD { + my ($self,$args) = @_; + $self->_set_importer_args($args); + + # keep USMARC temporary as alias for ISO, remove in future version + # print deprecation warning + if ($self->{type} eq 'USMARC') { + $self->{type} = 'ISO'; + warn( "deprecated", "Oops! Importer \"USMARC\" is deprecated. Use \"ISO\" instead." ); + } +} + +1; +__END__ + =head1 NAME Catmandu::Importer::MARC - Package that imports MARC data =head1 SYNOPSIS - # From the command line convert MARC to JSON mapping 245a to a title - $ catmandu convert MARC --fix "marc_map('245a','title')" < /foo/bar.mrc - - # From Perl - use Catmandu; + use Catmandu -all; # import records from file my $importer = Catmandu->importer('MARC',file => '/foo/bar.mrc'); - my $fixer = Catmandu->fixer("marc_map('245a','title')"); - $importer->each(sub { - my $item = shift; - ... + my $count = $importer->each(sub { + my $record = shift; + # ... }); - # or using the fixer + # import records and apply a fixer + my $fixer = fixer("marc_map('245a','title')"); $fixer->fix($importer)->each(sub { - my $item = shift; - printf "title: %s\n" , $item->{title}; + my $record = shift; + printf "title: %s\n" , $record->{title}; }); +Convert MARC to JSON mapping 245a to a title with the L<catmandu> command line client: + + catmandu convert MARC --fix "marc_map('245a','title')" < /foo/bar.mrc =head1 DESCRIPTION -Catmandu::Importer::MARC is a L<Catmandu::Iterable> to import MARC records from an -external source. When given an input file an Catmandu::Iterable is create generating -items as perl HASH-es containing two keys: +Catmandu::Importer::MARC is a L<Catmandu::Importer> to import MARC records from an +external source. Each record is imported as HASH containing two keys: + +=over - '_id' : the system identifier of the record (usually the 001 field) - 'record' : an ARRAY of ARRAYs containing the record data +=item C<_id> -Read more about processing data with Catmandu on the wiki: L<https://github.com/LibreCat/Catmandu/wiki> +the system identifier of the record (usually the 001 field) -=head1 EXAMPLE ITEM +=item C<record> + +an ARRAY of ARRAYs containing the record data + +=back + +=head2 EXAMPLE ITEM { - 'record' => [ - [ - '001', - undef, - undef, - '_', - 'fol05882032 ' - ], - [ - '245', - '1', - '0', - 'a', - 'Cross-platform Perl /', - 'c', - 'Eric F. Johnson.' - ], - ], - '_id' => 'fol05882032' + record => [ + [ + '001', + undef, + undef, + '_', + 'fol05882032 ' + ], + [ + '245', + '1', + '0', + 'a', + 'Cross-platform Perl /', + 'c', + 'Eric F. Johnson.' + ], + ], + _id' => 'fol05882032' } +=head1 METHODS + +This module inherits all methods of L<Catmandu::Importer> and by this +L<Catmandu::Iterable>. + =head1 CONFIGURATION +In addition to the configuration provided by L<Catmandu::Importer> (C<file>, +C<fh>, etc.) the importer can be configured with the following parameters: + =over =item type -Create a new MARC importer of the given type. Currently we support: +Describes the MARC syntax variant. Supported values include: =over -=item * USMARC: alias for ISO, B<deprecated, will be removed in future version> - -=item * ISO: L<Catmandu::Importer::MARC::ISO> +=item * ISO: L<Catmandu::Importer::MARC::ISO> (default) =item * MicroLIF: L<Catmandu::Importer::MARC::MicroLIF> =item * MARCMaker: L<Catmandu::Importer::MARC::MARCMaker> -=item * MiJ: L<Catmandu::Importer::MARC::MiJ> +=item * MiJ: L<Catmandu::Importer::MARC::MiJ> (MARC in JSON) =item * XML: L<Catmandu::Importer::MARC::XML> @@ -92,72 +143,8 @@ Create a new MARC importer of the given type. Currently we support: =back -=item file - -Read input from a local file given by its path. Alternatively a scalar -reference can be passed to read from a string. - -=item fh - -Read input from an L<IO::Handle>. If not specified, L<Catmandu::Util::io> is used to -create the input stream from the C<file> argument or by using STDIN. - -=item encoding - -Binmode of the input stream C<fh>. Set to C<:utf8> by default. - -=item fix - -An ARRAY of one or more fixes or file scripts to be applied to imported items. - -=back - -=head1 METHODS - -Every L<Catmandu::Importer> is a L<Catmandu::Iterable> all its methods are inherited. - =head1 SEE ALSO -L<Catmandu::Importer>, -L<Catmandu::Iterable> +L<Catmandu::Exporter::MARC> =cut -package Catmandu::Importer::MARC; -use Catmandu::Sane; -use Catmandu::Util; -use Moo; - -our $VERSION = '1.05'; - -has type => (is => 'ro' , default => sub { 'ISO' }); -has _importer => (is => 'ro' , lazy => 1 , builder => '_build_importer' , handles => ['generator']); -has _importer_args => (is => 'rwp', writer => '_set_importer_args'); - -with 'Catmandu::Importer'; - -sub _build_importer { - my ($self) = @_; - - my $type = $self->type; - - $type = 'Record' if exists $self->_importer_args->{records}; - - my $pkg = Catmandu::Util::require_package($type,'Catmandu::Importer::MARC'); - - $pkg->new($self->_importer_args); -} - -sub BUILD { - my ($self,$args) = @_; - $self->_set_importer_args($args); - - # keep USMARC temporary as alias for ISO, remove in future version - # print deprecation warning - if ($self->{type} eq 'USMARC') { - $self->{type} = 'ISO'; - warn( "deprecated", "Oops! Importer \"USMARC\" is deprecated. Use \"ISO\" instead." ); - } -} - - -1; -- Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-perl/packages/libcatmandu-marc-perl.git _______________________________________________ Pkg-perl-cvs-commits mailing list [email protected] http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/pkg-perl-cvs-commits
