PICA::Field - Perl extension for handling PICA+ fields
use PICA::Field; my $field = PICA::Field->new( '028A', '9' => '117060275', '8' => 'Martin Schrettinger' ); $field->update( "8", "Schrettinger, Martin" ); print $field->normalized();
Defines PICA+ fields for use in the PICA::Record module.
The method parse_pp_tag is exported.
parse_pp_tag
The constructor, which will return a PICA::Field object. You can call the constructor with a tag and a list of subfields:
PICA::Field
PICA::Field->new( '028A', '9' => '117060275', '8' => 'Martin Schrettinger' );
With a string of normalized PICA+ data of one field:
PICA::Field->new("\x1E028A \x1F9117060275\x1F8Martin Schrettinger\x0A');
With a string of readable PICA+ data:
PICA::Field->new('028A $9117060275$8Martin Schrettinger');
Creates and returns a copy of this object.
The constructur will return a PICA::Field object based on data that is parsed if null if the filter dropped the field. Dropped fields will not be parsed so they are also not validated.
The $tag_filter_func is an optional reference to a user-supplied function that determines on a tag-by-tag basis if you want the tag to be parsed or dropped. The function is passed the tag number (including occurrence), and must return a boolean.
$tag_filter_func
For example, if you only want to 021A fields, try this:
The filter function can be used to select only required fields
sub filter { my $tagno = shift; return $tagno eq "021A"; } my $field = PICA::Field->parse( $string, \&filter );
Returns the PICA+ tag and occurrence of the field.
Sets the tag and occurence of the field. Does not return a value.
Returns the level (0: main, 1: local, 2: copy) of the field.
When called in a scalar context returns the text from the first subfield matching the subfield code. You may specify multiple subfields.
my $subfield = $field->subfield( 'a' ); # first $a my $subfield = $field->subfield( 'acr' ); # first of $a, $c, $r
Or if you think there might be more than one you can get all of them by calling in a list context:
my @subfields = $field->subfield( 'a' );
If no matching subfields are found, undef is returned in a scalar context and an empty list in a list context.
undef
Returns all the subfields in the field. What's returned is a list of lists, where the inner list is a subfield code and the subfield data.
For example, this might be the subfields from a 021A field:
[ [ 'a', '@Traité de documentation' ], [ 'd', 'Le livre sur le livre ; Théorie et pratique' ], [ 'h', 'Paul Otlet' ] ]
Adds subfields to the end of the subfield list.
$field->add_subfields( 'c' => '1985' );
Returns the number of subfields added.
Allows you to change the values of the field. You can update indicators and subfields like this:
$field->update( a => 'Little Science, Big Science' );
If you attempt to update a subfield which does not currently exist in the field, then a new subfield will be appended to the field. If you don't like this auto-vivification you must check for the existence of the subfield prior to update.
if ( $field->subfield( 'a' ) ) { $field->update( 'a' => 'Cryptonomicon' ); }
Note: when doing subfield updates be aware that update() will only update the first occurrence. If you need to do anything more complicated you will probably need to create a new field and use replace().
update()
replace()
Returns the number of items modified.
Allows you to replace an existing field with a new one. You may pass a PICA::Field object or parameters for a new field to replace the existing field with. Replace does not return a meaningful or reliable value.
Returns a list of all codes of empty subfields.
Test whether there are no subfields or all subfields are empty.
Returns the field as a string. The tag number, occurrence and subfield indicators are included.
If $subfields is specified, then only those subfields will be included.
$subfields
Returns a pretty string for printing.
Returns the field in XML format. The XML format is an unofficial beta format and may change.
Tests whether a string can be used as a tag/occurrence specifier. A tag indicator consists of a 'type' (00-99) and an 'indicator' (A-Z and @), both conflated as the 'tag', and an optional occurrence (00-99). This method returns a list of two values: occurrence and tag (this order!). This method can be used to parse and test tag specifiers this way:
($occurrence, $tag) = parse_pp_tag( $t ); parse_pp_tag( $t ) or print STDERR "Not a valid tag: $t\n";
See the "SEE ALSO" section for PICA::Record.
This module is mainly based on MARC::Field by Andy Lester.
Jakob Voss <jakob.voss@gbv.de>
<jakob.voss@gbv.de>
Copyright (C) 2007 by Verbundzentrale Goettingen (VZG) and Jakob Voss
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.8 or, at your option, any later version of Perl 5 you may have available.
1 POD Error
The following errors were encountered while parsing the POD:
Non-ASCII character seen before =encoding in ''@Traité'. Assuming UTF-8
To install PICA::Record, copy and paste the appropriate command in to your terminal.
cpanm
cpanm PICA::Record
CPAN shell
perl -MCPAN -e shell install PICA::Record
For more information on module installation, please visit the detailed CPAN module installation guide.