View | Details | Raw Unified | Return to bug 10927
Collapse All | Expand All

(-)a/C4/Auth_with_cas.pm (-1 lines)
Lines 22-28 use warnings; Link Here
22
22
23
use C4::Debug;
23
use C4::Debug;
24
use C4::Context;
24
use C4::Context;
25
use C4::Utils qw( :all );
26
use Authen::CAS::Client;
25
use Authen::CAS::Client;
27
use CGI;
26
use CGI;
28
use FindBin;
27
use FindBin;
(-)a/C4/Utils.pm (-66 lines)
Lines 1-66 Link Here
1
package C4::Utils;
2
3
# Copyright 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
21
# Useful code I didn't feel like duplicating all over the place.
22
#
23
24
use strict;
25
use warnings;
26
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS $debug);
27
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)], );
35
}
36
37
38
sub maxwidth {
39
	(@_) or return 0;
40
	return (sort {$a <=> $b} map {length} @_)[-1];
41
}
42
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->{$_});
51
		}
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', $_) . '}', $_);
58
		}
59
		print "\n";
60
	} else {
61
		print "$pre = $val\n";
62
	}
63
}
64
65
1;
66
__END__
(-)a/t/Utils.t (-14 lines)
Lines 1-14 Link Here
1
#!/usr/bin/perl
2
#
3
# This Koha test module is a stub!  
4
# Add more tests here!!!
5
6
use strict;
7
use warnings;
8
9
use Test::More tests => 1;
10
11
BEGIN {
12
        use_ok('C4::Utils');
13
}
14
(-)a/t/db_dependent/Context.t (-10 / +3 lines)
Lines 16-22 BEGIN { Link Here
16
			ok($ret = $ENV{$_}, "ENV{$_} = $ret");
16
			ok($ret = $ENV{$_}, "ENV{$_} = $ret");
17
		}
17
		}
18
		use_ok('C4::Context');
18
		use_ok('C4::Context');
19
		use_ok('C4::Utils', qw/ :all /);
20
}
19
}
21
20
22
ok($koha = C4::Context->new,  'C4::Context->new');
21
ok($koha = C4::Context->new,  'C4::Context->new');
Lines 30-39 ok( Link Here
30
);
29
);
31
my @keys = keys %$koha;
30
my @keys = keys %$koha;
32
diag("Number of keys in \%\$koha: " . scalar @keys); 
31
diag("Number of keys in \%\$koha: " . scalar @keys); 
33
our $width = 0;
32
my $width = 0;
34
if (ok(@keys)) { 
33
if (ok(@keys)) { 
35
	$width = maxwidth(@keys);
34
    $width = (sort {$a <=> $b} map {length} @keys)[-1];
36
	$debug and diag "widest key is $width";
35
    $debug and diag "widest key is $width";
37
}
36
}
38
foreach (sort @keys) {
37
foreach (sort @keys) {
39
	ok(exists $koha->{$_}, 
38
	ok(exists $koha->{$_}, 
Lines 41-51 foreach (sort @keys) { Link Here
41
		. ((defined $koha->{$_}) ? "and is defined." : "but is not defined.")
40
		. ((defined $koha->{$_}) ? "and is defined." : "but is not defined.")
42
	);
41
	);
43
}
42
}
44
diag "Examining defined key values.";
45
foreach (grep {defined $koha->{$_}} sort @keys) {
46
	print "\n";
47
	hashdump('$koha->{' . sprintf('%' . $width . 's', $_)  . '}', $koha->{$_});
48
}
49
ok($config = $koha->{config}, 'Getting $koha->{config} ');
43
ok($config = $koha->{config}, 'Getting $koha->{config} ');
50
44
51
diag "Testing syspref caching.";
45
diag "Testing syspref caching.";
52
- 

Return to bug 10927