Bug 9552 - BIB1 Relation "Greater Than" Attribute Not Mapped Properly in CCL.Properties
[koha.git] / C4 / Utils.pm
blobdac942307378c7b50163ba48a43597efec04ebfc
1 package C4::Utils;
3 # Copyright 2007 Liblime
5 # This file is part of Koha.
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.
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.
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.
21 # Useful code I didn't feel like duplicating all over the place.
24 use strict;
25 use warnings;
26 use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS $debug);
28 BEGIN {
29 require Exporter;
30 $VERSION = 3.07.00.049; # set the version for version checking
31 $debug = $ENV{DEBUG} || 0;
32 @ISA = qw(Exporter);
33 @EXPORT_OK = qw(&maxwidth &hashdump);
34 %EXPORT_TAGS = ( all => [qw(&maxwidth &hashdump)], );
38 sub maxwidth {
39 (@_) or return 0;
40 return (sort {$a <=> $b} map {length} @_)[-1];
43 sub hashdump {
44 my $pre = shift;
45 my $val = shift;
46 if (ref($val) =~ /HASH/) {
47 print "$pre = HASH w/ " . scalar(keys %$val) . " keys.\n";
48 my $w2 = maxwidth(keys %$val);
49 foreach (sort keys %$val) {
50 &hashdump($pre . '->{' . sprintf('%' . $w2 .'s', $_) . '}', $val->{$_});
52 print "\n";
53 } elsif (ref($val) =~ /ARRAY/) {
54 print "$pre = ARRAY w/ " . scalar(@$val) . " members.\n";
55 my $w2 = maxwidth(@$val);
56 foreach (@$val) {
57 &hashdump($pre . '->{' . sprintf('%' . $w2 .'s', $_) . '}', $_);
59 print "\n";
60 } else {
61 print "$pre = $val\n";
66 __END__