Bug 22723: Correct syntax error on confess call in Koha/MetadataRecord/Authority.pm
[koha.git] / C4 / ClassSplitRoutine / Dewey.pm
blob9a627e46b77bbcf5e1eb6821bcd8ea4cb3ea5026
1 package C4::ClassSplitRoutine::Dewey;
3 # Copyright 2018 Koha Development Team
5 # This file is part of Koha.
7 # Koha is free software; you can redistribute it and/or modify it
8 # under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3 of the License, or
10 # (at your option) any later version.
12 # Koha is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with Koha; if not, see <http://www.gnu.org/licenses>.
20 use Modern::Perl;
22 use C4::Debug;
24 =head1 NAME
26 C4::ClassSplitRoutine::Dewey - Dewey call number split method
28 =head1 SYNOPSIS
30 use C4::ClassSplitRoutine;
32 my $cn_split = C4::ClassSplitRoutine::Dewey::split_callnumber($cn_item);
34 =head1 FUNCTIONS
36 =head2 split_callnumber
38 my $cn_split = C4::ClassSplitRoutine::Dewey::split_callnumber($cn_item);
40 =cut
42 sub split_callnumber {
43 my ($cn_item) = @_;
45 my $possible_decimal =
46 qr/\d{3,}(?:\.\d+)?/; # at least three digits for a DDCN
48 $cn_item =~ s/\///g
49 ; # in theory we should be able to simply remove all segmentation markers and arrive at the correct call number...
50 my (@lines) = $cn_item =~ m/
51 ^([-a-zA-Z]*\s?(?:$possible_decimal)?) # R220.3 CD-ROM 787.87 # will require extra splitting
52 \s+
53 (.+) # H2793Z H32 c.2 EAS # everything else (except bracketing spaces)
54 \s*
55 /x;
56 unless (@lines) {
57 warn sprintf( 'regexp failed to match string: %s', $cn_item );
58 push @lines, $cn_item; # if no match, just push the whole string.
61 if ( $lines[0] =~ /^([-a-zA-Z]+)\s?($possible_decimal)$/ ) {
62 shift @lines; # pull off the mathching first element, like example 1
63 unshift @lines, $1, $2; # replace it with the two pieces
66 push @lines, split /\s+/,
67 pop @lines
68 ; # split the last piece into an arbitrary number of pieces at spaces
69 $debug and print STDERR "split_ddcn array: ", join( " | ", @lines ), "\n";
70 return @lines;
75 =head1 AUTHOR
77 Koha Development Team <http://koha-community.org/>
79 =cut