Grammar tweaklet
[catagits/CatalystX-Routes.git] / lib / CatalystX / Routes / Role / Controller.pm
index 9a2fab2..6918597 100644 (file)
@@ -9,36 +9,53 @@ after register_actions => sub {
     my $self = shift;
     my $c    = shift;
 
-    my $class     = $self->catalyst_component_name;
-    my $namespace = $self->action_namespace($c);
-
     for my $route ( $self->meta()->route_names() ) {
         my ( $attrs, $method ) = @{ $self->meta()->get_route($route) };
 
-        for my $key ( keys %{$attrs} ) {
-            my $parse_meth = "_parse_${key}_attr";
+        $self->_add_cx_routes_action( $c, $route, $attrs, $method->body() );
+    }
+
+    for my $chain_point ( $self->meta()->chain_point_names() ) {
+        my ( $attrs, $code )
+            = @{ $self->meta()->get_chain_point($chain_point) };
+
+        $self->_add_cx_routes_action( $c, $chain_point, $attrs, $code );
+    }
+};
 
-            next unless $self->can($parse_meth);
+sub _add_cx_routes_action {
+    my $self  = shift;
+    my $c     = shift;
+    my $name  = shift;
+    my $attrs = shift;
+    my $code  = shift;
 
-            ( undef, my $value )
-                = $self->$parse_meth( $c, $route, $attrs->{$key} );
+    my $class     = $self->catalyst_component_name;
+    my $namespace = $self->action_namespace($c);
 
-            $attrs->{$key} = [$value];
-        }
+    for my $key ( keys %{$attrs} ) {
+        my $parse_meth = "_parse_${key}_attr";
 
-        my $reverse = $namespace ? "${namespace}/$route" : $route;
+        next unless $self->can($parse_meth);
 
-        my $action = $self->create_action(
-            name       => $route,
-            code       => $method->body(),
-            reverse    => $reverse,
-            namespace  => $namespace,
-            class      => $class,
-            attributes => $attrs,
-        );
+        ( undef, my $value )
+            = $self->$parse_meth( $c, $name, $attrs->{$key} );
 
-        $c->dispatcher->register( $c, $action );
+        $attrs->{$key} = [$value];
     }
-};
+
+    my $reverse = $namespace ? "${namespace}/$name" : $name;
+
+    my $action = $self->create_action(
+        name       => $name,
+        code       => $code,
+        reverse    => $reverse,
+        namespace  => $namespace,
+        class      => $class,
+        attributes => $attrs,
+    );
+
+    $c->dispatcher->register( $c, $action );
+}
 
 1;