X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FReaction%2FUI%2FViewPort%2FRole%2FActions.pm;h=778115b4f96279b08f754ed0e3832f91e6346f3e;hb=08c27c5b18df934a3f052d50a9e4ab361ddc4f3e;hp=1731a7ef3617076f96b57f5db5f094cc342a293d;hpb=3be50b19f80d78dc4889fa3cc7586febcbcdcb86;p=catagits%2FReaction.git diff --git a/lib/Reaction/UI/ViewPort/Role/Actions.pm b/lib/Reaction/UI/ViewPort/Role/Actions.pm index 1731a7e..778115b 100644 --- a/lib/Reaction/UI/ViewPort/Role/Actions.pm +++ b/lib/Reaction/UI/ViewPort/Role/Actions.pm @@ -16,6 +16,10 @@ has action_order => ( isa => 'ArrayRef' ); +has action_filter => ( + isa => 'CodeRef', is => 'ro', +); + has action_prototypes => ( is => 'ro', isa => 'HashRef', @@ -29,13 +33,21 @@ has computed_action_order => ( lazy_build => 1 ); +sub _filter_action_list { + my $self = shift; + my $actions = [keys %{$self->action_prototypes}]; + return $self->has_action_filter ? + $self->action_filter->($actions, $self->model) + : $actions; +} + sub _build_computed_action_order { my $self = shift; my $ordered = $self->sort_by_spec( ($self->has_action_order ? $self->action_order : []), - [ keys %{ $self->action_prototypes } ] + $self->_filter_action_list ); - return $ordered ; + return $ordered; } sub _build_actions { @@ -49,11 +61,19 @@ sub _build_actions { 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 $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 => $layout, + exists $proto->{layout_args} ? + ( ref($proto->{layout_args}) eq 'CODE' ? + $proto->{layout_args}->($target, $ctx) + : + $proto->{layout_args} ) + : () ); push(@act, $action); } @@ -76,7 +96,7 @@ A role to ease attaching actions to Ls =head2 actions -Automatically built ArrayRef of URI objects pointing to actions +Read-only, lazy-building ArrayRef of URI objects pointing to actions. =head2 action_prototypes @@ -108,8 +128,38 @@ User-provided ArrayRef with how the actions should be ordered eg =head2 computed_action_order -The final computed action order. This may differ from the action_order provided -if you didn't list all of the actions in that. +Read-only lazy-building ARRAY ref. The final computed action order. This may +differ from the C provided if you any actions were not included +in that list. + +=head1 METHODS + +=head2 _build_actions + +Cycle through the C and create a new +L object for each action using the +provided prototypes. + +=head2 _build_computed_action_order + +Compute the final action ordering by using the provided C as a +spec to order all the present actions (the keys of C) + +=head1 ACTION PROTOTYPES + +Action prototypes are simply hashrefs that must contain a C key and may +contain a C