From: Matt S Trout Date: Tue, 1 Nov 2005 02:35:03 +0000 (+0000) Subject: - Split _DISPATCH out into _BEGIN, _AUTO, _ACTION and _END X-Git-Tag: 5.7099_04~1071 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Runtime.git;a=commitdiff_plain;h=1143712c6bec3492444f03a91fde0ce081d9540a - Split _DISPATCH out into _BEGIN, _AUTO, _ACTION and _END --- diff --git a/lib/Catalyst/Base.pm b/lib/Catalyst/Base.pm index 6bda121..e2bf41a 100644 --- a/lib/Catalyst/Base.pm +++ b/lib/Catalyst/Base.pm @@ -6,59 +6,50 @@ use base qw/Catalyst::AttrContainer Class::Accessor::Fast/; use Catalyst::Exception; use NEXT; -__PACKAGE__->mk_classdata($_) for qw/_config/; +__PACKAGE__->mk_classdata($_) for qw/_config _dispatch_steps/; + +__PACKAGE__->_dispatch_steps([ qw/_BEGIN _AUTO _ACTION/ ]); sub _DISPATCH :Private { my ( $self, $c ) = @_; - my @containers = $c->dispatcher->get_containers( $c->namespace ); - my %actions; - foreach my $name (qw/begin auto end/) { - - # Go down the container list representing each part of the - # current namespace inheritance tree, grabbing the actions hash - # of the ActionContainer object and looking for actions of the - # appropriate name registered to the namespace - - $actions{$name} = [ - map { $_->{$name} } - grep { exists $_->{$name} } - map { $_->actions } @containers - ]; + + foreach my $disp (@{$self->_dispatch_steps}) { + last unless $c->forward($disp); } - # Errors break the normal flow and the end action is instantly run - my $error = 0; + $c->forward('_END'); +} - # Execute last begin - $c->state(1); - if ( my $begin = @{ $actions{begin} }[-1] ) { - $begin->execute($c); - $error++ if scalar @{ $c->error }; - } +sub _BEGIN :Private { + my ( $self, $c ) = @_; + my $begin = @{ $c->get_action('begin', $c->namespace, 1) }[-1]; + return 1 unless $begin; + $begin->[0]->execute($c); + return !@{$c->error}; +} - # Execute the auto chain - my $autorun = 0; - for my $auto ( @{ $actions{auto} } ) { - last if $error; - $autorun++; - $auto->execute($c); - $error++ if scalar @{ $c->error }; - last unless $c->state; +sub _AUTO :Private { + my ( $self, $c ) = @_; + my @auto = @{ $c->get_action('auto', $c->namespace, 1) }; + foreach my $auto (@auto) { + $auto->[0]->execute($c); + return 0 unless $c->state; } + return 1; +} - # Execute the action or last default - my $mkay = $autorun ? $c->state ? 1 : 0 : 1; - if ($mkay) { - unless ($error) { - $c->action->execute($c); - $error++ if scalar @{ $c->error }; - } - } +sub _ACTION :Private { + my ( $self, $c ) = @_; + $c->action->execute($c); + return !@{$c->error}; +} - # Execute last end - if ( my $end = @{ $actions{end} }[-1] ) { - $end->execute($c); - } +sub _END :Private { + my ( $self, $c ) = @_; + my $end = @{ $c->get_action('end', $c->namespace, 1) }[-1]; + return 1 unless $end; + $end->[0]->execute($c); + return !@{$c->error}; } =head1 NAME