| Filename | /usr/share/koha/lib/C4/ClassSortRoutine.pm |
| Statements | Executed 36 statements in 814µs |
| Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
|---|---|---|---|---|---|
| 1 | 1 | 1 | 20µs | 23µs | C4::ClassSortRoutine::BEGIN@20 |
| 1 | 1 | 1 | 17µs | 27µs | C4::ClassSortRoutine::BEGIN@24 |
| 1 | 1 | 1 | 14µs | 36µs | C4::ClassSortRoutine::BEGIN@21 |
| 1 | 1 | 1 | 12µs | 88µs | C4::ClassSortRoutine::BEGIN@27 |
| 1 | 1 | 1 | 10µs | 12µs | C4::ClassSortRoutine::BEGIN@25 |
| 1 | 1 | 1 | 7µs | 232µs | C4::ClassSortRoutine::GetSortRoutineNames |
| 0 | 0 | 0 | 0s | 0s | C4::ClassSortRoutine::GetClassSortKey |
| 0 | 0 | 0 | 0s | 0s | C4::ClassSortRoutine::_get_class_sort_key |
| Line | State ments |
Time on line |
Calls | Time in subs |
Code |
|---|---|---|---|---|---|
| 1 | package C4::ClassSortRoutine; | ||||
| 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 | 3 | 35µs | 2 | 27µs | # spent 23µs (20+4) within C4::ClassSortRoutine::BEGIN@20 which was called:
# once (20µs+4µs) by C4::ClassSource::BEGIN@25 at line 20 # spent 23µs making 1 call to C4::ClassSortRoutine::BEGIN@20
# spent 4µs making 1 call to strict::import |
| 21 | 3 | 49µs | 2 | 58µs | # spent 36µs (14+22) within C4::ClassSortRoutine::BEGIN@21 which was called:
# once (14µs+22µs) by C4::ClassSource::BEGIN@25 at line 21 # spent 36µs making 1 call to C4::ClassSortRoutine::BEGIN@21
# spent 22µs making 1 call to warnings::import |
| 22 | |||||
| 23 | 1 | 1µs | require Exporter; | ||
| 24 | 3 | 39µs | 2 | 37µs | # spent 27µs (17+10) within C4::ClassSortRoutine::BEGIN@24 which was called:
# once (17µs+10µs) by C4::ClassSource::BEGIN@25 at line 24 # spent 27µs making 1 call to C4::ClassSortRoutine::BEGIN@24
# spent 10µs making 1 call to Class::Factory::Util::import |
| 25 | 3 | 36µs | 2 | 14µs | # spent 12µs (10+2) within C4::ClassSortRoutine::BEGIN@25 which was called:
# once (10µs+2µs) by C4::ClassSource::BEGIN@25 at line 25 # spent 12µs making 1 call to C4::ClassSortRoutine::BEGIN@25
# spent 2µs making 1 call to C4::Context::import |
| 26 | |||||
| 27 | 3 | 342µs | 2 | 165µs | # spent 88µs (12+77) within C4::ClassSortRoutine::BEGIN@27 which was called:
# once (12µs+77µs) by C4::ClassSource::BEGIN@25 at line 27 # spent 88µs making 1 call to C4::ClassSortRoutine::BEGIN@27
# spent 77µs making 1 call to vars::import |
| 28 | |||||
| 29 | # set the version for version checking | ||||
| 30 | 1 | 2µs | $VERSION = 3.07.00.049; | ||
| 31 | |||||
| 32 | =head1 NAME | ||||
| 33 | |||||
| - - | |||||
| 45 | 1 | 8µs | @ISA = qw(Exporter); | ||
| 46 | 1 | 1µs | @EXPORT = qw( | ||
| 47 | &GetSortRoutineNames | ||||
| 48 | &GetClassSortKey | ||||
| 49 | ); | ||||
| 50 | |||||
| 51 | # intialization code | ||||
| 52 | 1 | 500ns | my %loaded_routines = (); | ||
| 53 | 1 | 4µs | 1 | 232µs | my @sort_routines = GetSortRoutineNames(); # spent 232µs making 1 call to C4::ClassSortRoutine::GetSortRoutineNames |
| 54 | 1 | 1µs | foreach my $sort_routine (@sort_routines) { | ||
| 55 | 3 | 111µs | if (eval "require C4::ClassSortRoutine::$sort_routine") { # spent 97µs executing statements in string eval
# spent 90µs executing statements in string eval
# spent 77µs executing statements in string eval | ||
| 56 | 3 | 1µs | my $ref; | ||
| 57 | 3 | 85µs | eval "\$ref = \\\&C4::ClassSortRoutine::${sort_routine}::get_class_sort_key"; # spent 8µs executing statements in string eval
# spent 4µs executing statements in string eval
# spent 4µs executing statements in string eval | ||
| 58 | 3 | 73µs | if (eval "\$ref->(\"a\", \"b\")") { # spent 23µs executing statements in 3 string evals (merged) | ||
| 59 | $loaded_routines{$sort_routine} = $ref; | ||||
| 60 | } else { | ||||
| 61 | $loaded_routines{$sort_routine} = \&_get_class_sort_key; | ||||
| 62 | } | ||||
| 63 | } else { | ||||
| 64 | $loaded_routines{$sort_routine} = \&_get_class_sort_key; | ||||
| 65 | } | ||||
| 66 | } | ||||
| 67 | |||||
| 68 | =head2 GetSortRoutineNames | ||||
| 69 | |||||
| - - | |||||
| 79 | # spent 232µs (7+225) within C4::ClassSortRoutine::GetSortRoutineNames which was called:
# once (7µs+225µs) by C4::ClassSource::BEGIN@25 at line 53 | ||||
| 80 | 1 | 7µs | 1 | 225µs | return C4::ClassSortRoutine->subclasses(); # spent 225µs making 1 call to Class::Factory::Util::_subclasses |
| 81 | } | ||||
| 82 | |||||
| 83 | =head2 GetClassSortKey | ||||
| 84 | |||||
| - - | |||||
| 93 | sub GetClassSortKey { | ||||
| 94 | my ($sort_routine, $cn_class, $cn_item) = @_; | ||||
| 95 | unless (exists $loaded_routines{$sort_routine}) { | ||||
| 96 | warn "attempting to use non-existent class sorting routine $sort_routine\n"; | ||||
| 97 | $loaded_routines{$sort_routine} = \&_get_class_sort_key; | ||||
| 98 | } | ||||
| 99 | my $key = $loaded_routines{$sort_routine}->($cn_class, $cn_item); | ||||
| 100 | # FIXME -- hardcoded length for cn_sort | ||||
| 101 | # should replace with some way of getting column widths from | ||||
| 102 | # the DB schema -- since doing this should ideally be | ||||
| 103 | # independent of the DBMS, deferring for the moment. | ||||
| 104 | return substr($key, 0, 30); | ||||
| 105 | } | ||||
| 106 | |||||
| 107 | =head2 _get_class_sort_key | ||||
| 108 | |||||
| - - | |||||
| 116 | sub _get_class_sort_key { | ||||
| 117 | my ($cn_class, $cn_item) = @_; | ||||
| 118 | my $key = uc "$cn_class $cn_item"; | ||||
| 119 | $key =~ s/\s+/_/; | ||||
| 120 | $key =~ s/[^A-Z_0-9]//g; | ||||
| 121 | return $key; | ||||
| 122 | } | ||||
| 123 | |||||
| 124 | 1 | 18µs | 1; | ||
| 125 | |||||
| 126 | =head1 AUTHOR | ||||
| 127 | |||||
| - - |