1 package Reaction::UI::ViewPort::Role::Actions;
4 use Reaction::UI::ViewPort::URI;
6 use namespace::clean -except => [ qw(meta) ];
19 has action_prototypes => (
26 has computed_action_order => (
32 sub _build_computed_action_order {
34 my $ordered = $self->sort_by_spec(
35 ($self->has_action_order ? $self->action_order : []),
36 [ keys %{ $self->action_prototypes } ]
45 my $loc = $self->location;
46 my $target = $self->model;
48 foreach my $proto_name ( @{ $self->computed_action_order } ) {
49 my $proto = $self->action_prototypes->{$proto_name};
50 my $uri = $proto->{uri} or confess('uri is required in prototype action');
51 my $label = exists $proto->{label} ? $proto->{label} : $proto_name;
53 my $action = Reaction::UI::ViewPort::URI->new(
54 location => join ('-', $loc, 'action', $i++),
55 uri => ( ref($uri) eq 'CODE' ? $uri->($target, $ctx) : $uri ),
56 display => ( ref($label) eq 'CODE' ? $label->($target, $ctx) : $label ),
69 Reaction::UI::ViewPort::Role::Actions
73 A role to ease attaching actions to L<Reaction::InterfaceModel::Object>s
79 Automatically built ArrayRef of URI objects pointing to actions
81 =head2 action_prototypes
83 A HashRef of prototypes for building the Action links. The prototypes should be
86 my %action_prototypes = (
87 example_action => { label => 'Example Action', uri => $uri_obj },
90 #or you can get fancy and do something like what is below:
92 my($im, $ctx) = @_; #InterfaceModel::Object/Collection, Catalyst Context
96 my($im, $ctx) = @_; #InterfaceModel::Object/Collection, Catalyst Context
97 return return $ctx->uri_for('some_action');
99 my %action_prototypes = (
100 example_action => { label => \&make_label, uri => \&make_uri },
105 User-provided ArrayRef with how the actions should be ordered eg
107 action_order => [qw/view edit delete/]
109 =head2 computed_action_order
111 The final computed action order. This may differ from the action_order provided
112 if you didn't list all of the actions in that.
116 See L<Reaction::Class> for authors.
120 See L<Reaction::Class> for the license.