MARC::Record has three functions (or methods) for inserting a field.

insert_grouped_field(field) 
insert_fields_before($before_field,@new_fields) 
insert_fields_after($after_field,@new_fields)

There is some inconsistency in the implementation of field handling, and also some 
inconvenience in using the functions.
If I have misunderstood something, please tell me.

The inconvenience is if I know where in the record I want to add a new field.
The documentation says that after a discussion (which I have not been able to find any 
trace of) on this list it seemed most people wanted to add a new field to the end of 
the hundred group it belongs to!

This sounds very peculiar to me.

If I want to add a new 001, for instance, I certainly want it to go first among the 
tags.
Not after a 099 field.

The inconsistency I mentioned is in the treatment of tags.
In the source code comments to  MARC::Field->new() it says
"MARC spec indicates that tags can have alphabetical characters in them!"

This is also taken care of (at least to some extent) in the MARC::Field module.

Now, in MARC::Record there are assumtions breaking this concept.
MARC::Record->insert_grouped_field() is making an integer of the tag.
Line 266: my $limit = int($new->tag() / 100);
Line 269: if ( int($field->tag() / 100) > $limit ) {

(This in itself indicates that MARC::Record is dealing with things it should leave to 
MARC::Field. Even though there are
no mechanisms in MARC::Field either to cover for this at the moment)

What I would like to see added is an insert() method that is inserting the field at 
its place according to the order of tags.
001 first and so on.

With some small modifications to existing code the method could look like this

sub insert {
    my ($self,$new) = @_;
    _all_parms_are_fields($new) or croak('Argument must be MARC::Field object');

    ## try to find the end of the field group and insert it there
    my $limit = $new->tag();
    my $found = 0;
    my $res;
    foreach my $field ($self->fields()) {
          if ( $field->tag() gt $limit ) {
              $res = $self->insert_fields_before($field,$new);
              $found = 1;
              last;
          }
    }

    ## if we couldn't find the end of the group, then we must not have 
    ## any tags this high yet, so just append it
    if (!$found) {
           $res = $self->append_fields($new); 
    }

    return $res;
}


This way it makes a character based comparision ("gt") between the tags.
It should behave correctly with MARC21 records (only using numerical characters in 
tags).
And it is making the assumption that an ordered form of alfanumerical tags is the same 
as simple filing.

I do not know if the idea behind MARC::Record is that it should be extendable to cover 
for other MARC dialects.

Even if it, as it stands, only is intended for MARC21 records, I still think it would 
be nice to have an insert method like the one above.

Leif
======================================
Leif Andersson, Systems Librarian
Stockholm University Library
SE-106 91 Stockholm
SWEDEN
Phone : +46 8 162769  
Mobile: +46 70 6904281

Reply via email to