[system] / trunk / webwork2 / lib / WeBWorK / Utils.pm Repository:
ViewVC logotype

Diff of /trunk/webwork2/lib/WeBWorK/Utils.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 445 Revision 455
2# WeBWorK mod_perl (c) 1995-2002 WeBWorK Team, Univeristy of Rochester 2# WeBWorK mod_perl (c) 1995-2002 WeBWorK Team, Univeristy of Rochester
3# $Id$ 3# $Id$
4################################################################################ 4################################################################################
5 5
6package WeBWorK::Utils; 6package WeBWorK::Utils;
7
8=head1 NAME
9
10WeBWorK::Utils - useful utilities used by other WeBWorK modules.
11
12=cut
7 13
8use strict; 14use strict;
9use warnings; 15use warnings;
10use base qw(Exporter); 16use base qw(Exporter);
11use Date::Format; 17use Date::Format;
20 dbDecode 26 dbDecode
21 dbEncode 27 dbEncode
22 decodeAnswers 28 decodeAnswers
23 encodeAnswers 29 encodeAnswers
24 ref2string 30 ref2string
25 hash2string
26 array2string
27); 31);
28 32
29sub runtime_use($) { 33sub runtime_use($) {
30 return unless @_; 34 return unless @_;
31 eval "package Main; require $_[0]; import $_[0]"; 35 eval "package Main; require $_[0]; import $_[0]";
165 return "ARRAY" if eval { $_ = @$ref; 1 }; 169 return "ARRAY" if eval { $_ = @$ref; 1 };
166 return "SCALAR" if eval { $_ = $$ref; 1 }; 170 return "SCALAR" if eval { $_ = $$ref; 1 };
167 return 0; 171 return 0;
168} 172}
169 173
170# -----
171
172#sub hash2string($;$$) {
173# my $hr = shift;
174# my $table = shift || 0;
175# my $indent = shift || 0;
176# my $result = $table ? '<table border="1">' : "";
177# foreach my $key (keys %$hr) {
178# my $value = $hr->{$key};
179# $result .= $table
180# ? "<tr><td>$key</td>"
181# : "\t"x$indent . "{$key} =";
182# if (ref $value eq 'HASH') {
183# $result .= $table ? "<td>" : "\n";
184# $result .= hash2string($value, $table, $indent+1);
185# $result .= $table ? "</td>" : "";
186# } elsif (ref $value eq 'ARRAY') {
187# $result .= $table ? "<td>" : "\n";
188# $result .= array2string($value, $table, $indent+1);
189# $result .= $table ? "</td>" : "";
190# } elsif (defined $value) {
191# $result .= $table
192# ? "<td>$value</td>"
193# : " $value\n";
194# } else {
195# $result .= $table ? "" : "\n";
196# }
197# $result .= $table ? "</tr>" : "";
198# }
199# $result .= "</table>";
200# return $result;
201#}
202#
203#sub array2string($;$$) {
204# my $ar = shift;
205# my $table = shift || 0;
206# my $indent = shift || 0;
207# my $result = $table ? '<table border="1">' : "";
208# foreach my $index (0 .. @$ar-1) {
209# my $value = $ar->[$index];
210# $result .= $table
211# ? "<tr><td>$index</td>"
212# : "\t"x$indent . "[$index] =";
213# if (ref $value eq 'HASH') {
214# $result .= $table ? "<td>" : "\n";
215# $result .= hash2string($value, $table, $indent+1);
216# $result .= $table ? "</td>" : "";
217# } elsif (ref $value eq 'ARRAY') {
218# $result .= $table ? "<td>" : "\n";
219# $result .= array2string($value, $table, $indent+1);
220# $result .= $table ? "</td>" : "";
221# } elsif (defined $value) {
222# $result .= $table
223# ? "<td>$value</td>"
224# : " $value\n";
225# } else {
226# $result .= $table ? "" : "\n";
227# }
228# $result .= $table ? "</tr>" : "";
229# }
230# $result .= "</table>";
231# return $result;
232#}
233#
234#sub isHashRef($) {
235# my $ref = shift;
236# local $SIG{__DIE__} = 'IGNORE';
237# $_ = eval{ %$ref };
238# return not defined $@;
239#}
240#
241#sub isArrayRef($) {
242# my $ref = shift;
243# local $SIG{__DIE__} = 'IGNORE';
244# $_ = eval{ @$ref };
245# return not defined $@;
246#}
247
2481; 1741;

Legend:
Removed from v.445  
changed lines
  Added in v.455

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9