added ActionClass attribute
[catagits/Catalyst-Runtime.git] / lib / Catalyst / Base.pm
index b1990e9..1ddbe8f 100644 (file)
@@ -27,7 +27,7 @@ sub _BEGIN : Private {
     my ( $self, $c ) = @_;
     my $begin = ( $c->get_actions( 'begin', $c->namespace ) )[-1];
     return 1 unless $begin;
-    $begin->execute($c);
+    $begin->dispatch( $c );
     return !@{ $c->error };
 }
 
@@ -35,7 +35,7 @@ sub _AUTO : Private {
     my ( $self, $c ) = @_;
     my @auto = $c->get_actions( 'auto', $c->namespace );
     foreach my $auto (@auto) {
-        $auto->execute($c);
+        $auto->dispatch( $c );
         return 0 unless $c->state;
     }
     return 1;
@@ -47,7 +47,7 @@ sub _ACTION : Private {
         && $c->action->can('execute')
         && $c->req->action )
     {
-        $c->action->execute($c);
+        $c->action->dispatch( $c );
     }
     return !@{ $c->error };
 }
@@ -56,7 +56,7 @@ sub _END : Private {
     my ( $self, $c ) = @_;
     my $end = ( $c->get_actions( 'end', $c->namespace ) )[-1];
     return 1 unless $end;
-    $end->execute($c);
+    $end->dispatch( $c );
     return !@{ $c->error };
 }
 
@@ -151,7 +151,18 @@ sub register_actions {
 
 sub create_action {
     my $self = shift;
-    $self->_action_class->new( { @_ } );
+    my %args = @_;
+
+    my $class = (exists $args{attributes}{ActionClass}
+                    ? $args{attributes}{ActionClass}[0]
+                    : $self->_action_class);
+
+    unless ( $class->can("can") ) {
+      $class->require;
+      die "Couldn't load action class ${class}: $@" if $@;
+    }
+    
+    return $class->new( \%args );
 }
 
 sub _parse_attrs {
@@ -220,6 +231,14 @@ sub _parse_LocalRegex_attr {
 
 sub _parse_LocalRegexp_attr { shift->_parse_LocalRegex_attr(@_); }
 
+sub _parse_ActionClass_attr {
+    my ( $self, $c, $name, $value ) = @_;
+    unless ( $value =~ s/^\+// ) {
+      $value = join('::', $self->_action_class, $value );
+    }
+    return ( 'ActionClass', $value );
+}
+
 =head1 SEE ALSO
 
 L<Catalyst>, L<Catalyst::Controller>.