Skip Menu |

This queue is for tickets about the MARC-Record CPAN distribution.

Report information
The Basics
Id: 61198
Status: resolved
Priority: 0/
Queue: MARC-Record

People
Owner: GMCHARLT [...] cpan.org
Requestors: ccaimbeul [...] gmail.com
Cc:
AdminCc:

Bug Information
Severity: Normal
Broken in: 2.0.2
Fixed in: (no value)



Subject: Field method subfields dies when called on a control field
The subfields method identifies that it is called on a control field but then attempts to return the non-existent subfields array causing it to die. Many users find the resulting behaviour a bit mystifying. Better to bail out after giving the warning giving an empty array to the caller, especially as one of the basic uses might be to call this in a loop of all tags. Attached a suggested patch
Subject: 0001-let-subfields-return-an-empty-array-on-control-field.patch
From 5648567cf4772e63090f2564c88f18aa5850266b Mon Sep 17 00:00:00 2001 From: Colin Campbell <colin.campbell@ptfs-europe.com> Date: Thu, 9 Sep 2010 11:11:38 +0100 Subject: [PATCH] let subfields return an empty array on control fields Content-Type: text/plain; charset="utf-8" Having identified that it has been called on a control field subfields was proceeding to try to return non-existent subfields and dieing. Avoid the die and just warn --- lib/MARC/Field.pm | 6 ++++-- 1 files changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/MARC/Field.pm b/lib/MARC/Field.pm index 2e970ef..6036b20 100644 --- a/lib/MARC/Field.pm +++ b/lib/MARC/Field.pm @@ -268,8 +268,10 @@ For example, this might be the subfields from a 245 field: sub subfields { my $self = shift; - $self->_warn( "Control fields (generally, just tags below 010) do not have subfields" ) - if $self->is_control_field; + if ($self->is_control_field) { + $self->_warn( "Control fields (generally, just tags below 010) do not have subfields" ); + return; + } my @list; my @data = @{$self->{_subfields}}; -- 1.7.2.2
On Thu Sep 09 06:35:43 2010, colinsc wrote: Show quoted text
> The subfields method identifies that it is called on a control field but > then attempts to return the non-existent subfields array causing it to > die. Many users find the resulting behaviour a bit mystifying. Better to > bail out after giving the warning giving an empty array to the caller, > especially as one of the basic uses might be to call this in a loop of > all tags. > > Attached a suggested patch
Thank you. I have pushed this patch, along with a test case.