Bug 14783: (follow-up) Move pickup library form into modal
[koha.git] / C4 / ClassSplitRoutine / Dewey.pm
1 package C4::ClassSplitRoutine::Dewey;
2
3 # Copyright 2018 Koha Development Team
4 #
5 # This file is part of Koha.
6 #
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.
11 #
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.
16 #
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>.
19
20 use Modern::Perl;
21
22 =head1 NAME
23
24 C4::ClassSplitRoutine::Dewey - Dewey call number split method
25
26 =head1 SYNOPSIS
27
28 use C4::ClassSplitRoutine;
29
30 my $cn_split = C4::ClassSplitRoutine::Dewey::split_callnumber($cn_item);
31
32 =head1 FUNCTIONS
33
34 =head2 split_callnumber
35
36   my $cn_split = C4::ClassSplitRoutine::Dewey::split_callnumber($cn_item);
37
38 =cut
39
40 sub split_callnumber {
41     my ($cn_item) = @_;
42
43     my $possible_decimal =
44       qr/\d{3,}(?:\.\d+)?/;    # at least three digits for a DDCN
45
46     $cn_item =~ s/\///g
47       ; # in theory we should be able to simply remove all segmentation markers and arrive at the correct call number...
48     my (@lines) = $cn_item =~ m/
49         ^([-a-zA-Z]*\s?(?:$possible_decimal)?) # R220.3  CD-ROM 787.87 # will require extra splitting
50         \s+
51         (.+)                               # H2793Z H32 c.2 EAS # everything else (except bracketing spaces)
52         \s*
53         /x;
54     unless (@lines) {
55         warn sprintf( 'regexp failed to match string: %s', $cn_item );
56         push @lines, $cn_item;    # if no match, just push the whole string.
57     }
58
59     if ( $lines[0] =~ /^([-a-zA-Z]+)\s?($possible_decimal)$/ ) {
60         shift @lines;    # pull off the mathching first element, like example 1
61         unshift @lines, $1, $2;    # replace it with the two pieces
62     }
63
64     push @lines, split /\s+/,
65       pop @lines
66       ;    # split the last piece into an arbitrary number of pieces at spaces
67     return @lines;
68 }
69
70 1;
71
72 =head1 AUTHOR
73
74 Koha Development Team <http://koha-community.org/>
75
76 =cut