From edb8bddff074769a95744b6a7fa59eff61e0cfc1 Mon Sep 17 00:00:00 2001 From: Galen Charlton Date: Tue, 8 Jan 2013 17:32:47 -0800 Subject: [PATCH] bug 9370: improve splitting of LC call numbers for labels Use the Perl module Library::CallNumber::LC to parse and split LC call numbers when generating spine labels. For example, QH541.15.C6 C25 2012 should be split as follows: QH 541.15 .C6 C25 2012 To test, create an item with call number QH541.15.C6 C25 2012 and classification source LC, then create a spine label for that item using a layout of type 'biblio' that has the split call numbers option enabled. The call number should be split as indicated above. Signed-off-by: Galen Charlton Signed-off-by: Kyle M Hall Signed-off-by: Chris Cormack Signed-off-by: Galen Charlton --- C4/Labels/Label.pm | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/C4/Labels/Label.pm b/C4/Labels/Label.pm index 760bacfed9..f62d50c0c8 100644 --- a/C4/Labels/Label.pm +++ b/C4/Labels/Label.pm @@ -7,6 +7,7 @@ use Text::Wrap; use Algorithm::CheckDigits; use Text::CSV_XS; use Data::Dumper; +use Library::CallNumber::LC; use C4::Context; use C4::Debug; @@ -113,18 +114,10 @@ sub _split_lccn { my ($lccn) = @_; $_ = $lccn; # lccn examples: 'HE8700.7 .P6T44 1983', 'BS2545.E8 H39 1996'; - my (@parts) = m/ - ^([a-zA-Z]+) # HE # BS - (\d+(?:\.\d)*) # 8700.7 # 2545 - \s* - (\.*\D+\d*) # .P6 # .E8 - \s* - (.*) # T44 1983 # H39 1996 # everything else (except any bracketing spaces) - \s* - /x; - unless (scalar @parts) { + my @parts = Library::CallNumber::LC->new($lccn)->components(); + unless (scalar @parts && defined $parts[0]) { warn sprintf('regexp failed to match string: %s', $_); - push @parts, $_; # if no match, just push the whole string. + @parts = $_; # if no match, just use the whole string. } push @parts, split /\s+/, pop @parts; # split the last piece into an arbitrary number of pieces at spaces $debug and warn "split_lccn array: ", join(" | ", @parts), "\n"; -- 2.39.5