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