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

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

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

Revision 324 Revision 422
1package WeBWorK::CourseEnvironment; 1package WeBWorK::CourseEnvironment;
2 2
3use strict; 3use strict;
4use warnings; 4use warnings;
5use Safe; 5use Safe;
6use WeBWorK::Utils qw(readFile);
6 7
7# new($invocant, $webworkRoot, $courseName) 8# new($invocant, $webworkRoot, $courseName)
8# $invocant implicitly set by caller 9# $invocant implicitly set by caller
9# $webworkRoot directory that contains the WeBWorK distribution 10# $webworkRoot directory that contains the WeBWorK distribution
10# $courseName name of the course being used 11# $courseName name of the course being used
69 70
70 bless $self, $class; 71 bless $self, $class;
71 return $self; 72 return $self;
72} 73}
73 74
74sub hash2string {
75 my $hr = shift;
76 my $indent = shift || 0;
77 my $result;
78 foreach (keys %$hr) {
79 $result .= "\t"x$indent . "{$_} =";
80 if (ref $hr->{$_} eq 'HASH') {
81 $result .= "\n";
82 $result .= hash2string($hr->{$_}, $indent+1);
83 } elsif (ref $hr->{$_} eq 'ARRAY') {
84 $result .= "\n";
85 $result .= array2string($hr->{$_}, $indent+1);
86 } else {
87 $result .= " " . $hr->{$_} . "\n";
88 }
89 }
90 return $result;
91}
92
93sub array2string {
94 my $ar = shift;
95 my $indent = shift || 0;
96 my $result;
97 foreach (0 .. @$ar-1) {
98 $result .= "\t"x$indent . "[$_] =";
99 if (ref $ar->[$_] eq 'HASH') {
100 $result .= "\n";
101 $result .= hash2string($ar->[$_], $indent+1);
102 } elsif (ref $ar->[$_] eq 'ARRAY') {
103 $result .= "\n";
104 $result .= array2string($ar->[$_], $indent+1);
105 } else {
106 $result .= " " . $ar->[$_] . "\n";
107 }
108 }
109 return $result;
110}
111
112# ----- utils -----
113
114sub readFile {
115 my $fileName = shift;
116 open INPUTFILE, "<", $fileName
117 or die "Couldn't open environment file $fileName: $!";
118 my $result = join "\n", <INPUTFILE>;
119 close INPUTFILE;
120 return $result;
121}
122
1231; 751;

Legend:
Removed from v.324  
changed lines
  Added in v.422

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9