[system] / trunk / webwork-modperl / lib / WeBWorK / ContentGenerator.pm Repository:
ViewVC logotype

Diff of /trunk/webwork-modperl/lib/WeBWorK/ContentGenerator.pm

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

Revision 507 Revision 508
97 #open(TEMPLATE, $templateFile) or die "Couldn't open template $templateFile"; 97 #open(TEMPLATE, $templateFile) or die "Couldn't open template $templateFile";
98 #my @template = <TEMPLATE>; 98 #my @template = <TEMPLATE>;
99 #close TEMPLATE; 99 #close TEMPLATE;
100 # 100 #
101 # Let's try something else instead: 101 # Let's try something else instead:
102 102 local $/="\n";
103 my @template = split /\n/, readFile($templateFile); 103 my @template = split /\n/, readFile($templateFile);
104 104
105 foreach my $line (@template) { 105 foreach my $line (@template) {
106 #warn "foo: $line\n"; 106 #warn "foo: $line\n";
107 # This is incremental regex processing. 107 # This is incremental regex processing.
115 if ($self->can($function)) { 115 if ($self->can($function)) {
116 print $self->$function(@_, $args); 116 print $self->$function(@_, $args);
117 } 117 }
118 } 118 }
119 119
120 print substr $line, (defined(pos($line)) ? pos($line) : 0); 120 print substr $line, (defined pos $line) ? pos $line : 0);
121 } 121 }
122} 122}
123 123
124# cook_args(STRING) - parses a string of the form ARG1="FOO" ARG2="BAR". Returns 124# cook_args(STRING) - parses a string of the form ARG1="FOO" ARG2="BAR". Returns
125# a reference to a hash containing the parsed arguments. 125# a reference to a hash containing the parsed arguments.
126# 126#
127sub cook_args($) { 127sub cook_args($) {
128 # There are a bunch of commented-out lines that I am using to remind myself
129 # That I want to write a better regex sometime.
130 my ($raw_args) = @_; 128 my ($raw_args) = @_;
131 my $args = {}; 129 my $args = {};
132 #my $quotable_string = qr/(?:".*?(?<![^\\](?:\\\\)*\\)"|\W*)/;
133 #my $quotable_string = qr/(?:".*?(?<!\\)"|\W*)/;
134 #my $test_string = '"hel \" lo" hello';
135 130
136 #warn $test_string =~ m/($quotable_string)/ ? $1 : "false"; 131 # Boy I love m//g in scalar context! Go read the camel book, heathen.
137 132 # First, get the whole token with the quotes on both ends...
138 while ($raw_args =~ m/\G\s*(\w*)="(.*?)"/g) { 133 while ($raw_args =~ m/\G\s*(\w*)="((?:[^"\\]|\\.)*)"/g) {
139 #while ($raw_args =~ m/\G\s*($quotable_string)=($quotable_string)/g) { 134 my ($key, $value) = ($1, $2);
135 # ... then, rip out all the protecty backspaces
136 $value =~ s/\(.)/$1/g;
140 $args->{$1} = $2; 137 $args->{$key} = $value;
141 } 138 }
142 139
143 return $args; 140 return $args;
144} 141}
145 142
342sub body { 339sub body {
343 return "Generated content"; 340 return "Generated content";
344} 341}
345 342
3461; 3431;
344
345__END__
346
347=head1 AUTHOR
348
349Written by Dennis Lambe Jr., malsyned (at) math.rochester.edu
350and Sam Hathaway, sh002i (at) math.rochester.edu.
351
352=cut

Legend:
Removed from v.507  
changed lines
  Added in v.508

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9