—#!/usr/bin/perl
package
main;
{
$main::VERSION
=
'0.029'
;
}
# PODNAME: marcmoose
# ABSTRACT: Read and output MARC record file
use
5.010;
use
utf8;
use
strict;
use
warnings;
use
Pod::Usage;
use
Getopt::Long;
use
MARC::Moose::Record;
use
MARC::Moose::Writer;
use
YAML;
my
$verbose
= 0;
my
$help
= 0;
my
$parser
=
'iso2709'
;
my
$formater
=
'text'
;
my
$output
=
''
;
my
$converter
=
''
;
GetOptions(
'verbose'
=> \
$verbose
,
'help'
=> \
$help
,
'p|parser=s'
=> \
$parser
,
'f|formater=s'
=> \
$formater
,
'o|output=s'
=> \
$output
,
'c|converter=s'
=> \
$converter
,
);
usage()
if
$help
||
$parser
!~ /iso2709|marcxml/ ||
$formater
!~ /text|iso2709|marcxml|json/ ||
(
$converter
&&
$converter
!~ /unimarctomarc21/ );
my
$fh
;
if
(
$output
) {
open
$fh
,
">"
,
$output
or
die
"Can't create file: $output"
;
}
else
{
$fh
=
*STDOUT
;
}
binmode
(
$fh
,
':encoding(utf8)'
);
my
$writer
= MARC::Moose::Writer->new(
fh
=>
$fh
,
formater
=>
$MARC::Moose::Record::formater
->{
$formater
}->new(),
);
$writer
->begin();
my
$reader
;
if
(
@ARGV
) {
for
(
@ARGV
) {
unless
(-f) {
say
"File doesn't exist: $_"
;
next
;
}
$reader
=
$parser
=~ /iso2709/
? MARC::Moose::Reader::File::Iso2709->new(
file
=>
$_
)
: MARC::Moose::Reader::File::Marcxml->new(
file
=>
$_
);
readwrite();
}
}
else
{
$reader
=
$parser
=~ /iso2709/
? MARC::Moose::Reader::File::Iso2709->new(
fh
=>
*STDIN
)
: MARC::Moose::Reader::File::Marcxml->new(
fh
=>
*STDIN
);
readwrite();
}
$writer
->end();
sub
usage {
pod2usage(
-verbose
=> 2 );
}
sub
readwrite {
while
(
my
$record
=
$reader
->
read
() ) {
$record
=
$record
->as(
$converter
)
if
$converter
;
$writer
->
write
(
$record
);
}
}
__END__
=pod
=encoding UTF-8
=head1 NAME
marcmoose - Read and output MARC record file
=head1 VERSION
version 0.029
=head1 DESCRIPTION
Command line utility using MARC::Moose module to handle MARC records which are
read from files or stdin.
=head1 SYNOPSYS
marc-moose
marc-moose --help
marc-moose marc.iso
marc-moose --formater text marc.iso
marc-moose --formater json marc.iso
marc-moose --converter unimarctomarc21 marc.iso
marc-moose --parser marcxml --formater iso2709 --output marc.xml marc.iso
=head1 PARAMETERS
=over
=item -h|--help
Display this help.
=item -p|--parser iso2709|marcxml
Parse input file. Two format are accepted: ISO2709 and MarcXML.
=item -f|--formater text|json|iso2709|marcxml
Format records. By default text.
=item -o|--output C<file name>
Output record to a file. Without this parameter output to stdout.
=item -c|--converter unimarctomarc21
Performs a conversion from UNIMARC to MARC21.
=back
=head1 AUTHOR
Frédéric Demians <f.demians@tamil.fr>
=head1 COPYRIGHT AND LICENSE
This software is copyright (c) 2013 by Frédéric Demians.
This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.
=cut