| Filename | /mnt/catalyst/koha/C4/ClassSortRoutine/Dewey.pm |
| Statements | Executed 26 statements in 1.08ms |
| Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
|---|---|---|---|---|---|
| 1 | 1 | 1 | 546µs | 562µs | C4::ClassSortRoutine::Dewey::BEGIN@20 |
| 1 | 1 | 1 | 34µs | 43µs | C4::ClassSortRoutine::Dewey::get_class_sort_key |
| 1 | 1 | 1 | 8µs | 13µs | C4::ClassSortRoutine::Dewey::BEGIN@21 |
| 1 | 1 | 1 | 6µs | 24µs | C4::ClassSortRoutine::Dewey::BEGIN@23 |
| 5 | 5 | 1 | 6µs | 6µs | C4::ClassSortRoutine::Dewey::CORE:subst (opcode) |
| 2 | 1 | 1 | 2µs | 2µs | C4::ClassSortRoutine::Dewey::CORE:substcont (opcode) |
| 2 | 1 | 1 | 1µs | 1µs | C4::ClassSortRoutine::Dewey::CORE:match (opcode) |
| Line | State ments |
Time on line |
Calls | Time in subs |
Code |
|---|---|---|---|---|---|
| 1 | package C4::ClassSortRoutine::Dewey; | ||||
| 2 | |||||
| 3 | # Copyright (C) 2007 LibLime | ||||
| 4 | # | ||||
| 5 | # This file is part of Koha. | ||||
| 6 | # | ||||
| 7 | # Koha is free software; you can redistribute it and/or modify it under the | ||||
| 8 | # terms of the GNU General Public License as published by the Free Software | ||||
| 9 | # Foundation; either version 2 of the License, or (at your option) any later | ||||
| 10 | # version. | ||||
| 11 | # | ||||
| 12 | # Koha is distributed in the hope that it will be useful, but WITHOUT ANY | ||||
| 13 | # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR | ||||
| 14 | # A PARTICULAR PURPOSE. See the GNU General Public License for more details. | ||||
| 15 | # | ||||
| 16 | # You should have received a copy of the GNU General Public License along | ||||
| 17 | # with Koha; if not, write to the Free Software Foundation, Inc., | ||||
| 18 | # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||||
| 19 | |||||
| 20 | 2 | 28µs | 2 | 578µs | # spent 562µs (546+16) within C4::ClassSortRoutine::Dewey::BEGIN@20 which was called:
# once (546µs+16µs) by C4::ClassSource::BEGIN@25 at line 20 # spent 562µs making 1 call to C4::ClassSortRoutine::Dewey::BEGIN@20
# spent 16µs making 1 call to strict::import |
| 21 | 2 | 29µs | 2 | 18µs | # spent 13µs (8+5) within C4::ClassSortRoutine::Dewey::BEGIN@21 which was called:
# once (8µs+5µs) by C4::ClassSource::BEGIN@25 at line 21 # spent 13µs making 1 call to C4::ClassSortRoutine::Dewey::BEGIN@21
# spent 5µs making 1 call to warnings::import |
| 22 | |||||
| 23 | 2 | 116µs | 2 | 42µs | # spent 24µs (6+18) within C4::ClassSortRoutine::Dewey::BEGIN@23 which was called:
# once (6µs+18µs) by C4::ClassSource::BEGIN@25 at line 23 # spent 24µs making 1 call to C4::ClassSortRoutine::Dewey::BEGIN@23
# spent 18µs making 1 call to vars::import |
| 24 | |||||
| 25 | # set the version for version checking | ||||
| 26 | 1 | 2µs | $VERSION = 3.07.00.049; | ||
| 27 | |||||
| 28 | =head1 NAME | ||||
| 29 | |||||
| 30 | C4::ClassSortRoutine::Dewey - generic call number sorting key routine | ||||
| 31 | |||||
| 32 | =head1 SYNOPSIS | ||||
| 33 | |||||
| 34 | use C4::ClassSortRoutine; | ||||
| 35 | |||||
| 36 | my $cn_sort = GetClassSortKey('Dewey', $cn_class, $cn_item); | ||||
| 37 | |||||
| 38 | =head1 FUNCTIONS | ||||
| 39 | |||||
| 40 | =head2 get_class_sort_key | ||||
| 41 | |||||
| 42 | my $cn_sort = C4::ClassSortRoutine::Dewey::Dewey($cn_class, $cn_item); | ||||
| 43 | |||||
| 44 | Generates sorting key using the following rules: | ||||
| 45 | |||||
| 46 | * Concatenates class and item part. | ||||
| 47 | * Converts to uppercase. | ||||
| 48 | * Removes leading and trailing whitespace and '/' | ||||
| 49 | * Separates alphabetic prefix from the rest of the call number | ||||
| 50 | * Splits into tokens on whitespaces and periods. | ||||
| 51 | * Leaves first digit group as is. | ||||
| 52 | * Converts second digit group to 15-digit long group, padded on right with zeroes. | ||||
| 53 | * Converts each run of whitespace to an underscore. | ||||
| 54 | * Removes any remaining non-alphabetical, non-numeric, non-underscore characters. | ||||
| 55 | |||||
| 56 | =cut | ||||
| 57 | |||||
| 58 | # spent 43µs (34+8) within C4::ClassSortRoutine::Dewey::get_class_sort_key which was called:
# once (34µs+8µs) by C4::ClassSource::BEGIN@25 at line 1 of (eval 43)[C4/ClassSortRoutine.pm:58] | ||||
| 59 | 1 | 700ns | my ($cn_class, $cn_item) = @_; | ||
| 60 | |||||
| 61 | 1 | 200ns | $cn_class = '' unless defined $cn_class; | ||
| 62 | 1 | 0s | $cn_item = '' unless defined $cn_item; | ||
| 63 | 1 | 1µs | my $init = uc "$cn_class $cn_item"; | ||
| 64 | 1 | 8µs | 1 | 2µs | $init =~ s/^\s+//; # spent 2µs making 1 call to C4::ClassSortRoutine::Dewey::CORE:subst |
| 65 | 1 | 3µs | 1 | 1µs | $init =~ s/\s+$//; # spent 1µs making 1 call to C4::ClassSortRoutine::Dewey::CORE:subst |
| 66 | 1 | 2µs | 1 | 200ns | $init =~ s!/!!g; # spent 200ns making 1 call to C4::ClassSortRoutine::Dewey::CORE:subst |
| 67 | 1 | 690µs | 4 | 777µs | $init =~ s/^([\p{IsAlpha}]+)/$1 /; # spent 774µs making 1 call to utf8::SWASHNEW
# spent 2µs making 1 call to C4::ClassSortRoutine::Dewey::CORE:subst
# spent 2µs making 2 calls to C4::ClassSortRoutine::Dewey::CORE:substcont, avg 750ns/call |
| 68 | 1 | 3µs | my @tokens = split /\.|\s+/, $init; | ||
| 69 | 1 | 200ns | my $digit_group_count = 0; | ||
| 70 | 1 | 100ns | my $first_digit_group_idx; | ||
| 71 | 1 | 2µs | for (my $i = 0; $i <= $#tokens; $i++) { | ||
| 72 | 2 | 6µs | 2 | 1µs | if ($tokens[$i] =~ /^\d+$/) { # spent 1µs making 2 calls to C4::ClassSortRoutine::Dewey::CORE:match, avg 500ns/call |
| 73 | $digit_group_count++; | ||||
| 74 | if (1 == $digit_group_count) { | ||||
| 75 | $first_digit_group_idx = $i; | ||||
| 76 | } | ||||
| 77 | if (2 == $digit_group_count) { | ||||
| 78 | $tokens[$i] = sprintf("%-15.15s", $tokens[$i]); | ||||
| 79 | $tokens[$i] =~ tr/ /0/; | ||||
| 80 | } | ||||
| 81 | } | ||||
| 82 | } | ||||
| 83 | # Pad the first digit_group if there was only one | ||||
| 84 | 1 | 100ns | if (1 == $digit_group_count) { | ||
| 85 | $tokens[$first_digit_group_idx] .= '_000000000000000' | ||||
| 86 | } | ||||
| 87 | 1 | 900ns | my $key = join("_", @tokens); | ||
| 88 | 1 | 186µs | 2 | 662µs | $key =~ s/[^\p{IsAlnum}_]//g; # spent 661µs making 1 call to utf8::SWASHNEW
# spent 400ns making 1 call to C4::ClassSortRoutine::Dewey::CORE:subst |
| 89 | |||||
| 90 | 1 | 4µs | return $key; | ||
| 91 | |||||
| 92 | } | ||||
| 93 | |||||
| 94 | 1 | 3µs | 1; | ||
| 95 | |||||
| 96 | =head1 AUTHOR | ||||
| 97 | |||||
| 98 | Koha Development Team <http://koha-community.org/> | ||||
| 99 | |||||
| 100 | =cut | ||||
| 101 | |||||
# spent 1µs within C4::ClassSortRoutine::Dewey::CORE:match which was called 2 times, avg 500ns/call:
# 2 times (1µs+0s) by C4::ClassSortRoutine::Dewey::get_class_sort_key at line 72, avg 500ns/call | |||||
# spent 6µs within C4::ClassSortRoutine::Dewey::CORE:subst which was called 5 times, avg 1µs/call:
# once (2µs+0s) by C4::ClassSortRoutine::Dewey::get_class_sort_key at line 67
# once (2µs+0s) by C4::ClassSortRoutine::Dewey::get_class_sort_key at line 64
# once (1µs+0s) by C4::ClassSortRoutine::Dewey::get_class_sort_key at line 65
# once (400ns+0s) by C4::ClassSortRoutine::Dewey::get_class_sort_key at line 88
# once (200ns+0s) by C4::ClassSortRoutine::Dewey::get_class_sort_key at line 66 | |||||
# spent 2µs within C4::ClassSortRoutine::Dewey::CORE:substcont which was called 2 times, avg 750ns/call:
# 2 times (2µs+0s) by C4::ClassSortRoutine::Dewey::get_class_sort_key at line 67, avg 750ns/call |