X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FReaction%2FUI%2FController.pm;h=361a5c24486abcaa0bc6f84a28698bb0bd8932f2;hb=bd1aa0c203d4e2c70aeb2ced17ad023d2a27dd8f;hp=e0e142397d876bc085e61e684634bfd6511e8cb0;hpb=7adfd53f17f66ffe93763e944ed1d3fc52a369dc;p=catagits%2FReaction.git diff --git a/lib/Reaction/UI/Controller.pm b/lib/Reaction/UI/Controller.pm index e0e1423..361a5c2 100644 --- a/lib/Reaction/UI/Controller.pm +++ b/lib/Reaction/UI/Controller.pm @@ -1,14 +1,19 @@ package Reaction::UI::Controller; -use base qw/Catalyst::Controller::BindLex Reaction::Object/; +use base qw( + Catalyst::Controller + Catalyst::Component::ACCEPT_CONTEXT + Reaction::Object +); + use Reaction::Class; sub push_viewport { my $self = shift; - my $focus_stack :Stashed; + my $c = $self->context; + my $focus_stack = $c->stash->{focus_stack}; my ($class, @proto_args) = @_; my %args; - my $c = Catalyst::Controller::BindLex::_get_c_obj(4); if (my $vp_attr = $c->stack->[-1]->attributes->{ViewPort}) { if (ref($vp_attr) eq 'ARRAY') { $vp_attr = $vp_attr->[0]; @@ -17,7 +22,7 @@ sub push_viewport { if (my $conf_class = delete $vp_attr->{class}) { $class = $conf_class; } - %args = (%$vp_attr, @proto_args); + %args = %{ $self->merge_config_hashes($vp_attr, {@proto_args}) }; } else { $class = $vp_attr; %args = @proto_args; @@ -35,14 +40,12 @@ sub push_viewport { } sub pop_viewport { - my $focus_stack :Stashed; - return $focus_stack->pop_viewport; + return shift->context->stash->{focus_stack}->pop_viewport; } sub pop_viewports_to { my ($self, $vp) = @_; - my $focus_stack :Stashed; - return $focus_stack->pop_viewports_to($vp); + return $self->context->stash->{focus_stack}->pop_viewports_to($vp); } sub redirect_to { @@ -52,7 +55,7 @@ sub redirect_to { my $action; if(!ref $to){ $action = $self->action_for($to); - confess("Failed to locate action ${to} in " . $self->blessed) unless $action; + confess("Failed to locate action ${to} in " . blessed($self)) unless $action; } elsif( blessed $to && $to->isa('Catalyst::Action') ){ $action = $to; @@ -71,3 +74,64 @@ sub redirect_to { } 1; + +__END__; + +=head1 NAME + +Reaction::UI::Controller + +=head1 DESCRIPTION + +Base Reaction Controller class. Inherits from: + +=over 4 + +=item L +=item L +=item L + +=back + +=head1 METHODS + +=head2 push_viewport $vp_class, %args + +Will create a new instance of $vp_class with the arguments of %args +merged in with any arguments in the ViewPort attribute of the current +Catalyst action (also accessible through the controller config), add +it to the main FocusStack (C<$c-Estash-E{focus_stack}>) and +return the instantiated viewport. + +TODO: explain how next_action as a scalar gets converted to the redirect arrayref thing + +=head2 pop_viewport + +=head2 pop_viewport_to $vp + +Shortcut to subs of the same name in the main FocusStack (C<$c-Estash-E{focus_stack}>) + +=head2 redirect_to $c, $to, $captures, $args, $attrs + +If C<$to> is a string then redirects to the action of the same name in the current + controller (C<$c-Econtroller> not C<$self>). + +If C<$to> isa L +it will pass the argument directly to C<$c-Euri_for>. + +If C<$to> is an ArrayRef with two items it will treat the first as a Controller name +and the second as the action name whithin that controller. + +C<$captures>, C<$args>, and C<$attrs> are equivalent to the same arguments in +C. If left blank the current request captures and args will be used +and C<$attrs> will be passed as an empty HashRef. + +=head1 AUTHORS + +See L for authors. + +=head1 LICENSE + +See L for the license. + +=cut