Problem:

  When you request an indicator or subfield for tags less than
  010, MARC::Field will croak(), causing the script to fail.


Discussion:

  Since MARC tags less than 010 can not have indicators or subfields,
  not allowing those ::Field methods to be called on those tags make sense.
  However, this should be a warn(), not a croak(), otherwise looping
  code will need to conditionally check tag numbers before continued
  processing.

  For example, in MARC::Doc::Tutorial, one of the examples is:

    use MARC::Batch;
    my $batch = MARC::Batch->new('USMARC','file.dat');
    my $record = $batch->next();

    my @fields = $record->fields;

    foreach my $field (@fields) {
      print
        $field->tag(), " ",
        $field->indicator(1),
        $field->indicator(2) || undef, " ",
        $field->as_string, " ",
        "\n";
    }

  The purpose of the code is to print out each and every bit of the
  MARC record. If "file.dat" is the t/camel.usmarc file, the above
  code immediately fails:

    Fields below 010 do not have indicators at test.pl line 13

  For the code to work as intended, revisions like this would be needed:

    use MARC::Batch;
    my $batch = MARC::Batch->new('USMARC','file.dat');
    my $record = $batch->next();

    my @fields = $record->fields;

    foreach my $field (@fields) {
      print $field->tag(), " ";

      if ($field->tag() > 10) {
        print $field->indicator(1);
        print $field->indicator(2);
      }

      print $field->as_string, " \n";
    }

  There's certainly nothing wrong with the above code, but it does
  seem like extra work mental work that should, and can, be prevented.


Possible Solution:

  Instead of croaking, warn() instead, with the ability to
  warnings_off(). The attached patch to the latest CPAN
  MARC::Field implements this, changing the following croaks
  to $self->_warn:

    Field.pm: croak( "Fields below 010 do not have indicators" )
    Field.pm: croak( "Fields below 010 do not have subfields" )
    Field.pm: croak( "data() is only for tags less than 010" )

  The example recipe will also need to be revised to handle
  undef'd values - the relevant print statement is below.
  Taking care to check for undef's is extra code, but more
  in line with careful Perl programming than MARC rules.

    print
      $field->tag(), " ",
      defined $field->indicator(1) ? $field->indicator(1) : "",
      defined $field->indicator(2) ? $field->indicator(2) : "",
      $field->as_string, " ",
      "\n";
    }


Other Notes:

  I believe there's an error in the ::Field POD documentation.
  In the indicator and subfield intro's, we're told that MARC::
  Field::ERROR will be set at various instances. I don't believe
  this is the case - the only time ERROR is set is when the _gripe
  routine is called, and the _gripe routine is .. . never .. called.
  MARC::Record calls its own internal _gripe routine twice:

     return _gripe( $MARC::Field::ERROR );

  but would seem to always return undef, as ERROR is never set.

  The attached patch does not address ANY of the above, as I'm
  not sure if I'm missing something. Someone please confirm -
  I can do the leg work to correct the POD (or, fix the code,
  depending on how you think it should be fixed).

-- 
Morbus Iff ( small pieces of morbus loosely joined )
Technical: http://www.oreillynet.com/pub/au/779
Culture: http://www.disobey.com/ and http://www.gamegrene.com/
icq: 2927491 / aim: akaMorbus / yahoo: morbus_iff / jabber.org: morbus

Attachment: %
Description: application/applefile

Attachment: Field.patch
Description: Binary data

Reply via email to