Bug 17600: Standardize our EXPORT_OK
[srvgit] / C4 / ClassSortRoutine / Dewey.pm
index b4ba921..eedf4ed 100644 (file)
@@ -4,26 +4,23 @@ package C4::ClassSortRoutine::Dewey;
 # 
 # This file is part of Koha.
 #
-# Koha is free software; you can redistribute it and/or modify it under the
-# terms of the GNU General Public License as published by the Free Software
-# Foundation; either version 2 of the License, or (at your option) any later
-# version.
+# Koha is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
 #
-# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
-# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
-# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
+# Koha is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
 #
-# You should have received a copy of the GNU General Public License along
-# with Koha; if not, write to the Free Software Foundation, Inc.,
-# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+# You should have received a copy of the GNU General Public License
+# along with Koha; if not, see <http://www.gnu.org/licenses>.
 
 use strict;
 use warnings;
 
-use vars qw($VERSION);
 
-# set the version for version checking
-$VERSION = 3.00;
 
 =head1 NAME 
 
@@ -31,7 +28,7 @@ C4::ClassSortRoutine::Dewey - generic call number sorting key routine
 
 =head1 SYNOPSIS
 
-use C4::ClassSortRoutine;
+use C4::ClassSortRoutine qw( GetClassSortKey );
 
 my $cn_sort = GetClassSortKey('Dewey', $cn_class, $cn_item);
 
@@ -63,19 +60,32 @@ sub get_class_sort_key {
     my $init = uc "$cn_class $cn_item";
     $init =~ s/^\s+//;
     $init =~ s/\s+$//;
+    $init =~ s/\// /g;
     $init =~ s!/!!g;
     $init =~ s/^([\p{IsAlpha}]+)/$1 /;
     my @tokens = split /\.|\s+/, $init;
     my $digit_group_count = 0;
+    my $first_digit_group_idx;
     for (my $i = 0; $i <= $#tokens; $i++) {
         if ($tokens[$i] =~ /^\d+$/) {
             $digit_group_count++;
+            if (1 == $digit_group_count) {
+                $first_digit_group_idx = $i;
+            }
             if (2 == $digit_group_count) {
-                $tokens[$i] = sprintf("%-15.15s", $tokens[$i]);
-                $tokens[$i] =~ tr/ /0/;
+               if ($i - $first_digit_group_idx == 1) {
+                    $tokens[$i] = sprintf("%-15.15s", $tokens[$i]);
+                    $tokens[$i] =~ tr/ /0/;
+                } else {
+                    $tokens[$first_digit_group_idx] .= '_000000000000000'
+                }
             }
         }
     }
+    # Pad the first digit_group if there was only one
+    if (1 == $digit_group_count) {
+        $tokens[$first_digit_group_idx] .= '_000000000000000'
+    }
     my $key = join("_", @tokens);
     $key =~ s/[^\p{IsAlnum}_]//g;