Reaction::UI::Controller::Role::Action::Simple - Reaction::UI::Controller::Role::Action::Simple documentation


Reaction documentation Contained in the Reaction distribution.

Index


Code Index:

NAME

Top

Reaction::UI::Controller::Role::Action::Simple

DESCRIPTION

Top

Provides a setup_viewport method, which makes it easier to setup and configure a viewport in controller actions.

SYNOPSYS

Top

    package MyApp::Controller::Foo;

    use base 'Reaction::Controller';
    use Reaction::Class;

    with 'Reaction::UI::Controller::Role::Action::Simple';

    __PACKAGE__->config(
      action_viewport_map => { bar => 'Reaction::UI::Viewport::Object' },
      action_viewport_args => { location => 'custom-location' },
    );

    sub bar :Local {
      my($self, $c) = @_;
      my $obj = $self->get_collection($c)->find( $some_key );
      $self->setup_viewport($c, { model => $obj });
    }

ATTRIBUTES

Top

action_viewport_map

_build_action_viewport_map - Returns empty hashref by default.
has_action_viewport_map - Auto generated predicate
clear_action_viewport_map- Auto generated clearer method

Read-write lazy building hashref. The keys should match action names in the Controller and the value should be the ViewPort class that this action should use.

action_viewport_args

Read-write lazy building hashref. Additional ViewPort arguments for the action named as the key in the controller.

_build_action_viewport_args - Returns empty hashref by default.
has_action_viewport_args - Auto generated predicate
clear_action_viewport_args- Auto generated clearer method

METHODS

Top

setup_viewport $c, \%vp_args

Accepts two arguments, context, and a hashref of viewport arguments. It will automatically determine the action name using the catalyst stack and call push_viewport with the ViewPort class name contained in the action_viewport_map with a set of options determined by merging $vp_args and the arguments contained in action_viewport_args, if any.

SEE ALSO

Top

AUTHORS

Top

See Reaction::Class for authors.

LICENSE

Top

See Reaction::Class for the license.


Reaction documentation Contained in the Reaction distribution.

package Reaction::UI::Controller::Role::Action::Simple;

use Moose::Role -traits => 'MethodAttributes';

requires 'push_viewport';
requires 'merge_config_hashes';

has action_viewport_map => (isa => 'HashRef', is => 'rw', lazy_build => 1);
has action_viewport_args => (isa => 'HashRef', is => 'rw', lazy_build => 1);

sub _build_action_viewport_map { {} }

sub _build_action_viewport_args { {} }

sub setup_viewport {
  my ($self, $c, $vp_args) = @_;
  my $action_name = $c->stack->[-1]->name;
  my $vp = $self->action_viewport_map->{$action_name};
  my $args = $self->merge_config_hashes(
    $vp_args || {},
    $self->action_viewport_args->{$action_name} || {} ,
  );
  return $self->push_viewport($vp, %$args);
}

1;

__END__;