MARC::Field(3pm)

πŸ“¦
version 2.0.7 Β· 5 versions
, in ubuntu noble, ubuntu resolute, ubuntu stonking

πŸ’– MARC::Field β€” the manual, bestie πŸ’–

okay so this is the User Contributed Perl Documentation for MARC::Field, and honestly? it's giving "small module, big feelings." let's get into it 🫢


✨ NAME ✨

MARC::Field β€” a Perl extension for handling MARC fields, no cap πŸ’…


🌸 SYNOPSIS 🌸

use MARC::Field;

# If your system uses wacky control field tags, add them
MARC::Field->allow_controlfield_tags('FMT', 'LLE');

my $field = MARC::Field->new( 245, '1', '0',
     'a' => 'Raccoons and ripe corn / ',
     'c' => 'Jim Arnosky.'
);
$field->add_subfields( "a", "1st ed." );

see how easy that was? main character energy fr fr ✨


πŸ¦‹ DESCRIPTION πŸ¦‹

so basically it defines MARC fields for use in the MARC::Record module. and like… i guess you could use them all on their own? but bestie that would not be very interesting. it's giving "solo cup at a party with no one else there" πŸ’€


πŸ‘‘ EXPORT πŸ‘‘

Nothing. Zero. None by default. πŸ™…β€β™€οΈ

But!! any errors get stored in $MARC::Field::ERROR, which $MARC::Record usually bubbles up to $MARC::Record::ERROR. so nothing is lost, it's just chillin in a different variable. iykyk πŸ’œ


πŸŽ€ CLASS VARIABLES πŸŽ€

  • extra_controlfield_tags β€” so some systems (notably Ex Libris's Aleph) throw extra control fields in their MARC (e.g., Aleph's MARC-XML tends to have a "FMT" control field). we keep a class-level hash to track to track them 😭 (yes, the double "track to track" is canon, i don't make the rules, i just report them). it can be manipulated with allow_controlfield_tags and c<disallow_controlfield_tags>. (and yes, the source literally writes that second one in that c<...> POD syntax, so we're keeping it exactly like that, no editing βœ‹)

πŸ’… METHODS πŸ’…

new()

the constructor, babes. it returns a MARC::Field object. typically you pass in the tag number, indicator 1, indicator 2, and then a list of any subfield/data pairs. for example:

my $field = MARC::Field->new(
     245, '1', '0',
     'a' => 'Raccoons and ripe corn / ',
     'c' => 'Jim Arnosky.'
);

or, if you want to add a control field (< 010) that does not have indicators:

my $field = MARC::Field->new( '001', ' 14919759' );

look at that. indicator-free. unbothered. flawless. 🌈

tag()

Returns the three digit tag for the field. three digits. that's it. that's the whole vibe.

set_tag(tag)

Changes the tag number of this field. Updates the control status accordingly. Will croak if an invalid value is passed in. ⚠️ so don't be messy with it or it'll yell at you.

indicator(indno)

Returns the specified indicator.

Returns undef and logs a warning if the field is a control field and thus doesn't have indicators. (like, bestie, control fields literally don't have indicators, what did you expect 😭)

If the field is not a control field, it croaks if the indno is not 1 or 2. so it's 1, 2, or nothing. periodt.

set_indicator($indno, $indval)

Set the indicator position $indno to the value specified by $indval.

Croaks if the indicator position is invalid, or the field is a control field and thus doesn't have indicators, or if the new indicator value is invalid. three whole reasons to be dramatic πŸ’€

allow_controlfield_tags($tag, $tag2, ...)

Add $tags to the class-level list of strings to consider valid control field tags (in addition to 001 through 009). Tags must have three characters. slay ✨

disallow_controlfield_tags($tag, $tag2, ...) =head2

(yes that stray =head2 is literally sitting there in the original, we're keeping it, no notes πŸ™ˆ)

disallow_controlfield_tags('*')

Revoke the validity of a control field tag previously added with allow_controlfield_tags. As a special case, if you pass the string '*' it will clear out all previously-added tags. wildcard behaviour, iconic behaviour πŸ’…

NOTE that this will only deal with stuff added with allow_controlfield_tags; you can't disallow '001'. some things are forever, bestie.

is_valid_tag($tag) -- is the given tag valid?

Generally called as a class method (e.g., MARC::Field->is_valid_tag('001'))

is_valid_indicator($indval) -- is the given indicator value valid?

Generally called as a class method (e.g., MARC::Field->is_valid_indicator('4'))

is_controlfield_tag($tag) -- does the given tag denote a control field?

Generally called as a class method (e.g., MARC::Field->is_controlfield_tag('001'))

is_control_field()

Tells whether this field is one of the control tags from 001-009. just a lil yes/no moment 🫢

subfield(code)

When called in a scalar context, returns the text from the first subfield matching the subfield code.

my $subfield = $field->subfield( 'a' );

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. (the classic "i looked and there was nothing" 😭)

If the tag is a control field, undef is returned and $MARC::Field::ERROR is set.

subfields()

Returns all the subfields in the field. What's returned is a list of list refs, where the inner list is a subfield code and the subfield data.

For example, this might be the subfields from a 245 field:

(
  [ 'a', 'Perl in a nutshell :' ],
  [ 'b', 'A desktop quick reference.' ],
)

nested refs. very demure. very mindful. 🌸

data()

Returns the data part of the field, if the tag number is less than 10. that's the whole rule. tag < 10 or bust.

add_subfields(code,text[,code,text ...])

Adds subfields to the end of the subfield list. (end of the line, no cutting 🫢)

$field->add_subfields( 'c' => '1985' );

Returns the number of subfields added, or undef if there was an error.

delete_subfield()

delete_subfield() allows you to remove subfields from a field:

# delete any subfield a in the field
$field->delete_subfield(code => 'a');

# delete any subfield a or u in the field
$field->delete_subfield(code => ['a', 'u']);

# delete any subfield code matching a compiled regular expression
$field->delete_subfield(code => qr/[^a-z0-9]/);

If you want to only delete subfields at a particular position you can use the pos parameter:

# delete subfield u at the first position
$field->delete_subfield(code => 'u', pos => 0);

# delete subfield u at first or second position
$field->delete_subfield(code => 'u', pos => [0,1]);

# delete the second subfield, no matter what it is
$field->delete_subfield(pos => 1);

You can specify a regex to for only deleting subfields that match:

# delete any subfield u that matches zombo.com
$field->delete_subfield(code => 'u', match => qr/zombo.com/);

# delete any subfield that matches quux
$field->delete_subfield(match => qr/quux/);

(that one really does say "to for only deleting" in the original and honestly? we leave the typos alone, they're part of the ecosystem πŸ’€)

You can also pass a single subfield label:

# delete all subfield u
$field->delete_subfield('u');

so flexible. so many options. ate and left no crumbs πŸ’…

delete_subfields()

Delete all subfields with a given subfield code. This is here for backwards compatibility, you should use the more flexible delete_subfield(). it's the older sibling that still lives at home, be nice to it πŸ₯Ί

update()

Allows you to change the values of the field. You can update indicators and subfields like this:

$field->update( ind2 => '4', a => 'The ballad of Abe Lincoln');

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' );
}

If you want to update a field that has no indicators or subfields (000-009) just call update() with one argument, the string that you would like to set the field to.

$field = $record->field( '003' );
$field->update('IMchF');
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_with(). first only. don't come for me, i'm just the messenger 😀

Returns the number of items modified.

replace_with()

Allows you to replace an existing field with a new one. You need to pass replace() a MARC::Field object to replace the existing field with. For example:

$field = $record->field('245');
my $new_field = new MARC::Field('245','0','4','The ballad of Abe Lincoln.');
$field->replace_with($new_field);

Doesn't return a meaningful or reliable value. so like… don't build your whole personality on its return value, bestie πŸ™ˆ

as_string( [$subfields] [, $delimiter] )

Returns a string of all subfields run together. A space is added to the result between each subfield, unless the delimiter parameter is passed. The tag number and subfield character are not included.

Subfields appear in the output string in the order in which they occur in the field.

If $subfields is specified, then only those subfields will be included.

my $field = MARC::Field->new(
              245, '1', '0',
                      'a' => 'Abraham Lincoln',
                      'h' => '[videorecording] :',
                      'b' => 'preserving the union /',
                      'c' => 'A&E Home Video.'
              );
print $field->as_string( 'abh' ); # Only those three subfields
# prints 'Abraham Lincoln [videorecording] : preserving the union /'.
print $field->as_string( 'ab', '--' ); # Only those two subfields, with a delimiter
# prints 'Abraham Lincoln--preserving the union /'.

Note that subfield h comes before subfield b in the output. order of occurrence matters, not your feelings about it πŸ’–

as_formatted()

Returns a pretty string for printing in a MARC dump. pretty!! for the printer!! ✨

as_usmarc()

Returns a string for putting into a USMARC file. It's really only useful for MARC::Record::as_usmarc(). like it has one job and it does it for someone else 🫢

clone()

Makes a copy of the field. Note that this is not just the same as saying

my $newfield = $field;

since that just makes a copy of the reference. To get a new object, you must

my $newfield = $field->clone;

Returns a MARC::Field record. reference vs. object, the eternal struggle 😭 this one trips everyone up, ngl.

warnings()

Returns the warnings that were created when the record was read. These are things like "Invalid indicators converted to blanks".

The warnings are items that you might be interested in, or might not. It depends on how stringently you're checking data. If you're doing some grunt data analysis, you probably don't care. vibe check your own data, bestie πŸ’œ


🌈 SEE ALSO 🌈

See the "SEE ALSO" section for MARC::Record. (they wrote it, we point at it, circle of life πŸ¦‹)


⭐ TODO ⭐

See the "TODO" section for MARC::Record. same deal, same vibes.


πŸ’œ LICENSE πŸ’œ

This code may be distributed under the same terms as Perl itself.

Please note that these modules are not products of or supported by the employers of the various contributors to the code. so like, don't @ their bosses, fr fr πŸ™…β€β™€οΈ


πŸ’– AUTHOR πŸ’–

Andy Lester, "<andy@petdance.com>" β€” absolute icon, thank you for your service πŸ‘‘


and that's the whole page, bestie!! this was MARC::Field, shipped as part of perl v5.36.0, dated 2022-10-13, under the manual name MARC::Field(3pm). you read the whole thing, i'm so proud of you. go forth and handle those MARC fields, you've got this πŸŽ€βœ¨

πŸ“¦ where this page comes from