Alex Robinson
2007-09-23 13:24:11 UTC
Prompted by CJ's mention of stripping out redundant whitespace I
thought I'd revisit the subject.
I note the two tickets on the todo list (405, 459).
I'd like to suggest a potential solution.
If line 1219 of Request.pm (1.37) was changed like so:
-my $stack_buffer = $comp->{has_filter} ? \$filter_buffer : $top_buffer;
+my $stack_buffer =\$filter_buffer;
this would then allow something like this (assuming the existence of
a configuration parameter filter_newlines) to be added after line 1280
else {
if ($self->{interp}->{filter_newlines}) {
$filter_buffer =~ s/^\n+//;
$filter_buffer =~ s/\n+$//;
}
$$top_buffer .= $filter_buffer;
}
<<<
which would soak up all leading and trailing whitespace on components
without explicit filters which would take precedence. So to not
remove the space would simply require adding an empty filter block
Although that would perhaps do, I'd like to suggest that the
configuration parameter shouldn't be a simple on/off toggle, but
allow the following options (with 'none' the default for backwards
compatibility)
filter_newlines => none | one | all
And allow for component flags block to have the same parameter with
the same possible values to allow for overriding on a component by
component basis.
This would allow for something like:
my $filter_newlines = $comp->{flags}->{filter_newlines} ||
$self->{interp}->{filter_newlines};
if ($filter_newlines and $filter_newlines ne 'none') {
my $lines_to_filter = $filter_newlines eq 'all' ? '' : '1';
$filter_buffer =~ s/^\n{1,$lines_to_filter}//;
$filter_buffer =~ s/\n{1,$lines_to_filter}$//;
}
$$top_buffer .= $filter_buffer;
<<<
If done this way, this could be done in addition to any filter the
component actually has. Or again, the filter could be used to
override the auto stripping entirely.
Thoughts?
thought I'd revisit the subject.
I note the two tickets on the todo list (405, 459).
I'd like to suggest a potential solution.
If line 1219 of Request.pm (1.37) was changed like so:
-my $stack_buffer = $comp->{has_filter} ? \$filter_buffer : $top_buffer;
+my $stack_buffer =\$filter_buffer;
this would then allow something like this (assuming the existence of
a configuration parameter filter_newlines) to be added after line 1280
else {
if ($self->{interp}->{filter_newlines}) {
$filter_buffer =~ s/^\n+//;
$filter_buffer =~ s/\n+$//;
}
$$top_buffer .= $filter_buffer;
}
<<<
which would soak up all leading and trailing whitespace on components
without explicit filters which would take precedence. So to not
remove the space would simply require adding an empty filter block
Although that would perhaps do, I'd like to suggest that the
configuration parameter shouldn't be a simple on/off toggle, but
allow the following options (with 'none' the default for backwards
compatibility)
filter_newlines => none | one | all
And allow for component flags block to have the same parameter with
the same possible values to allow for overriding on a component by
component basis.
This would allow for something like:
my $filter_newlines = $comp->{flags}->{filter_newlines} ||
$self->{interp}->{filter_newlines};
if ($filter_newlines and $filter_newlines ne 'none') {
my $lines_to_filter = $filter_newlines eq 'all' ? '' : '1';
$filter_buffer =~ s/^\n{1,$lines_to_filter}//;
$filter_buffer =~ s/\n{1,$lines_to_filter}$//;
}
$$top_buffer .= $filter_buffer;
<<<
If done this way, this could be done in addition to any filter the
component actually has. Or again, the filter could be used to
override the auto stripping entirely.
Thoughts?