NAME
PICA::PlainParser - Parse normalized PICA+
VERSION
version 0.585
SYNOPSIS
my $parser = PICA::PlainParser->new(
Field => \&field_handler,
Record => \&record_handler
);
$parser->parsefile($filename);
sub field_handler {
my $field = shift;
print $field->string;
# no need to save the field so do not return it
}
sub record_handler {
print "\n";
}
DESCRIPTION
This module contains a parser for normalized PICA+
PUBLIC METHODS
new (params)
Create a new parser. See PICA::Parser for a detailed description of the possible parameters Field
, Record
, and Collection
. Errors are reported to STDERR.
parsefile ( $filename | $handle )
Parses a file, specified by a filename or file handle or IO::Handle. Additional possible parameters are handlers (Field
, Record
, Collection
) and options (EmptyRecords
). If you supply a filename with extension .gz
then it is extracted while reading with zcat
, if the extension is .zip
then unzip
is used to extract.
parsedata ( $data )
Parses PICA+ data from a string, array or function. If you supply a function then this function is must return scalars or arrays and it is called unless it returns undef. You can also supply a PICA::Record object to be parsed again.
records ( )
Get an array of the read records (if they have been stored)
counter ( )
Get the number of records that have been (tried to) read. This also includes broken records and other records that have been skipped, for instance by filtering out with the record handler.
finished ( )
Return whether the parser will not parse any more records. This is the case if the number of read records is larger then the limit.
PRIVATE METHODS
_parsedata
Parses a string or an array reference.
_parseline
Parses a line (without trailing newline character). May throw an exception with croak.
broken_field ( $errormessage [, $line ] )
If a line could not be parsed into a PICA::Field, this method is called. If it returns undef, the line is ignored, if it returns a PICA::Field object, this field is used instead and if it returns a true value, the whole record will be marked as broken. This method can be used as error handler. By default it always returns undef and prints an error message to STDERR.
broken_record ( $errormessage [, $record ] )
Error handler for broken records. By default prints the errormessage to STDERR if it is defined and the record is not empty.
handle_record ( )
Calls the record handler.
AUTHOR
Jakob Voß <voss@gbv.de>
COPYRIGHT AND LICENSE
This software is copyright (c) 2014 by Verbundzentrale Goettingen (VZG) and Jakob Voss.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.