cleanup of hard to read layout_args code
[catagits/Reaction.git] / lib / Reaction / UI / ViewPort / Role / Actions.pm
index 32c7bbb..f2d40fb 100644 (file)
@@ -63,11 +63,21 @@ sub _build_actions {
     my $label = exists $proto->{label} ? $proto->{label} : $proto_name;
     my $layout = exists $proto->{layout} ? $proto->{layout} : 'uri';
 
+    my $layout_args;
+    if( exists $proto->{layout_args} ){
+      if( ref($proto->{layout_args}) eq 'CODE' ){
+        $layout_args = $proto->{layout_args}->($target, $ctx);
+      } else {
+        $layout_args = $proto->{layout_args};
+      }
+    }
+
     my $action = Reaction::UI::ViewPort::URI->new(
       location => join ('-', $loc, 'action', $i++),
       uri => ( ref($uri) eq 'CODE' ? $uri->($target, $ctx) : $uri ),
       display => ( ref($label) eq 'CODE' ? $label->($target, $ctx) : $label ),
-      layout => ( ref($layout) eq 'CODE' ? $layout->($target, $ctx) : $layout ),
+      layout => $layout,
+      ( ref($layout_args) eq ' HASH' ? layout_args => $layout_args : () ),
     );
     push(@act, $action);
   }