Update of /cvsroot/mason/mason/dist/lib/HTML/Mason
In directory usw-pr-cvs1:/tmp/cvs-serv8404
Modified Files:
Request.pm Component.pm
Log Message:
code cleanup
moved filter handling into Request->comp and out of Component->run
this puts all the filter/buffer code funkiness into Request.pm,
primarily in the comp method, though cache_self has its own extra bit
of weirdness
This makes the code a little easier to follow as there's not a special
case for Component->run
need more crazy filter tests
Index: Request.pm
===================================================================
RCS file: /cvsroot/mason/mason/dist/lib/HTML/Mason/Request.pm,v
retrieving revision 1.262
retrieving revision 1.263
diff -u -r1.262 -r1.263
--- Request.pm 16 Oct 2002 22:14:10 -0000 1.262
+++ Request.pm 29 Oct 2002 19:50:54 -0000 1.263
@@ -667,14 +667,14 @@
UNIVERSAL::can($@, 'rethrow') ? $@->rethrow : error $@;
}
+ push @{ $self->{buffer_stack} }, $filter
+ if $filter;
+
#
# Print the component output.
#
$self->print($output);
- push @{ $self->{buffer_stack} }, $filter
- if $filter;
-
#
# Return the component return value in case the caller is interested,
# followed by 1 indicating the cache retrieval success.
@@ -978,6 +978,12 @@
push @{ $self->{buffer_stack} }, $self->{buffer_stack}[-1]->new_child;
}
+ if ( $comp->has_filter )
+ {
+ push @{ $self->{buffer_stack} },
+ $self->{buffer_stack}[-1]->new_child( filter_from => $comp );
+ }
+
my @result;
# The eval block creates a new context so we need to get this
@@ -997,31 +1003,39 @@
}
};
- #
- # If an error occurred, pop stack and pass error down to next level.
- #
- if (my $err = $@) {
- # any unflushed output is at $self->top_buffer->output
- $self->flush_buffer if $self->aborted;
+ my $err = $@;
+
+ # any unflushed output is at $self->top_buffer->output
+ $self->flush_buffer if $self->aborted;
- pop @{ $self->{stack} };
- if ( $mods{store} )
+ if ( $comp->has_filter )
+ {
+ my $buffer = pop @{ $self->{buffer_stack} };
+
+ # we don't want to send output if there was a real error
+ unless ( $err && ! $self->aborted )
{
- pop @{ $self->{buffer_stack} };
- pop @{ $self->{buffer_stack} };
+ # have to catch errors from filter code too
+ $self->print( $buffer->output );
}
-
- UNIVERSAL::can($err, 'rethrow') ? $err->rethrow : error $err;
}
pop @{ $self->{stack} };
+
if ( $mods{store} )
{
$self->flush_buffer;
+
pop @{ $self->{buffer_stack} };
pop @{ $self->{buffer_stack} };
}
+ if ($err)
+ {
+ UNIVERSAL::can($err, 'rethrow') ? $err->rethrow : error $err;
+ }
+
+
return wantarray ? @result : $result[0]; # Will return undef in void context (correct)
}
@@ -1033,13 +1047,6 @@
my $buf;
$self->comp({store=>\$buf},@_);
return $buf;
-}
-
-sub push_filter_buffer
-{
- my $self = shift;
-
- push @{ $self->{buffer_stack} }, $self->top_buffer->new_child(@_);
}
sub content {
Index: Component.pm
===================================================================
RCS file: /cvsroot/mason/mason/dist/lib/HTML/Mason/Component.pm,v
retrieving revision 1.97
retrieving revision 1.98
diff -u -r1.97 -r1.98
--- Component.pm 15 Oct 2002 17:50:37 -0000 1.97
+++ Component.pm 29 Oct 2002 19:50:54 -0000 1.98
@@ -117,33 +117,7 @@
$self->{mfu_count}++;
- return $self->{code}->(@_) unless $self->has_filter;
-
- my $req = HTML::Mason::Request->instance;
-
- $req->push_filter_buffer( filter_from => $self );
-
- my @r;
-
- my $wantarray = wantarray;
- my @result;
- # Note: this must always preserve calling wantarray() context
- eval {
- if ($wantarray) {
- @result = $self->{code}->(@_);
- } elsif (defined $wantarray) {
- $result[0] = $self->{code}->(@_);
- } else {
- $self->{code}->(@_);
- }
- };
-
- my $buffer = $req->pop_buffer_stack;
- $req->print( $buffer->output );
-
- die $@ if $@;
-
- return $wantarray ? @result : defined $wantarray ? $result[0] : undef;
+ return $self->{code}->(@_);
}
sub dynamic_subs_init {
|