1 package Reaction::UI::Controller;
5 Catalyst::Component::ACCEPT_CONTEXT
13 my $c = $self->context;
14 my $focus_stack = $c->stash->{focus_stack};
15 my ($class, @proto_args) = @_;
17 if (my $vp_attr = $c->stack->[-1]->attributes->{ViewPort}) {
18 if (ref($vp_attr) eq 'ARRAY') {
19 $vp_attr = $vp_attr->[0];
21 if (ref($vp_attr) eq 'HASH') {
22 if (my $conf_class = delete $vp_attr->{class}) {
25 %args = %{ $self->merge_config_hashes($vp_attr, {@proto_args}) };
36 if (exists $args{next_action} && !ref($args{next_action})) {
37 $args{next_action} = [ $self, 'redirect_to', $args{next_action} ];
39 $focus_stack->push_viewport($class, %args);
43 return shift->context->stash->{focus_stack}->pop_viewport;
46 sub pop_viewports_to {
48 return $self->context->stash->{focus_stack}->pop_viewports_to($vp);
52 my ($self, $c, $to, $cap, $args, $attrs) = @_;
54 #the confess calls could be changed later to $c->log ?
56 my $reftype = ref($to);
58 $action = $self->action_for($to);
59 confess("Failed to locate action ${to} in " . blessed($self)) unless $action;
60 } elsif($reftype eq 'ARRAY' && @$to == 2){ #is that overkill / too strict?
61 $action = $c->controller($to->[0])->action_for($to->[1]);
62 confess("Failed to locate action $to->[1] in $to->[0]" ) unless $action;
63 } elsif( blessed $to && $to->isa('Catalyst::Action') ){
66 confess("Failed to locate action from ${to}");
69 $cap ||= $c->req->captures;
70 $args ||= $c->req->args;
72 my $uri = $c->uri_for($action, $cap, @$args, $attrs);
73 $c->res->redirect($uri);
82 Reaction::UI::Controller
86 Base Reaction Controller class. Inherits from:
90 =item L<Catalyst::Controller>
91 =item L<Catalyst::Component::ACCEPT_CONTEXT>
92 =item L<Reaction::Object>
98 =head2 push_viewport $vp_class, %args
100 Creates a new instance of the L<Reaction::UI::ViewPort> class
101 ($vp_class) using the rest of the arguments given (%args). Defaults of
102 the action can be overridden by using the C<ViewPort> key in the
103 controller configuration. For example to override the default number
104 of items in a CRUD list action:
108 list => { ViewPort => { per_page => 50 } },
112 The ViewPort is added to the L<Reaction::UI::Window>'s FocusStack in
113 the stash, and also returned to the calling code.
119 =item L<Reaction::UI::Controller::Root>
120 =item L<Reaction::UI::Window>
124 TODO: explain how next_action as a scalar gets converted to the redirect arrayref thing
128 =head2 pop_viewport_to $vp
130 Call L<Reaction::UI::FocusStack/pop_viewport> or
131 L<Reaction::UI::FocusStack/pop_viewport_to> on
132 the C<< $c->stash->{focus_stack} >>.
134 =head2 redirect_to $c, $to, $captures, $args, $attrs
136 Construct a URI and redirect to it.
142 =item The name of an action in the current controller.
144 =item A L<Catalyst::Action> instance.
146 =item An arrayref of controller name and the name of an action in that
151 $captures and $args default to the current requests $captures and
152 $args if not supplied.
156 See L<Reaction::Class> for authors.
160 See L<Reaction::Class> for the license.