cleanup of hard to read layout_args code
[catagits/Reaction.git] / lib / Reaction / UI / ViewPort / Role / Actions.pm
index eb8ad76..f2d40fb 100644 (file)
@@ -5,6 +5,12 @@ use Reaction::UI::ViewPort::URI;
 
 use namespace::clean -except => [ qw(meta) ];
 
+has actions => (
+  is => 'ro',
+  isa => 'ArrayRef',
+  lazy_build => 1
+);
+
 has action_order => (
   is => 'ro',
   isa => 'ArrayRef'
@@ -44,27 +50,34 @@ sub _build_computed_action_order {
   return $ordered;
 }
 
-sub actions {
+sub _build_actions {
   my ($self) = @_;
   my (@act, $i);
   my $ctx = $self->ctx;
   my $loc = $self->location;
   my $target = $self->model;
-  my $valid_actions = $self->has_action_filter ?
-      $self->action_filter->($self->computed_action_order, $self->model)
-      : $self->computed_action_order;
 
-  foreach my $proto_name ( @$valid_actions ) {
+  foreach my $proto_name ( @{ $self->computed_action_order } ) {
     my $proto = $self->action_prototypes->{$proto_name};
     my $uri = $proto->{uri} or confess('uri is required in prototype action');
     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);
   }