diff options
author | matthewt <matthewt@03d0b0b2-0e1a-0410-a411-fdb2f4bd65d7> | 2007-09-12 18:11:34 +0000 |
---|---|---|
committer | matthewt <matthewt@03d0b0b2-0e1a-0410-a411-fdb2f4bd65d7> | 2007-09-12 18:11:34 +0000 |
commit | 7adfd53f17f66ffe93763e944ed1d3fc52a369dc (patch) | |
tree | 19e599e74419b41cbbe651fd226b81e8b73551d3 /lib/Reaction/UI/Controller.pm | |
parent | c728c97cb1061330e63c7cc048e768ef74988fe6 (diff) | |
download | reaction-7adfd53f17f66ffe93763e944ed1d3fc52a369dc.tar.gz reaction-7adfd53f17f66ffe93763e944ed1d3fc52a369dc.zip |
moved shit to trunk
Diffstat (limited to 'lib/Reaction/UI/Controller.pm')
-rw-r--r-- | lib/Reaction/UI/Controller.pm | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/lib/Reaction/UI/Controller.pm b/lib/Reaction/UI/Controller.pm new file mode 100644 index 0000000..e0e1423 --- /dev/null +++ b/lib/Reaction/UI/Controller.pm @@ -0,0 +1,73 @@ +package Reaction::UI::Controller; + +use base qw/Catalyst::Controller::BindLex Reaction::Object/; +use Reaction::Class; + +sub push_viewport { + my $self = shift; + my $focus_stack :Stashed; + 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]; + } + if (ref($vp_attr) eq 'HASH') { + if (my $conf_class = delete $vp_attr->{class}) { + $class = $conf_class; + } + %args = (%$vp_attr, @proto_args); + } else { + $class = $vp_attr; + %args = @proto_args; + } + } else { + %args = @proto_args; + } + + $args{ctx} = $c; + + if (exists $args{next_action} && !ref($args{next_action})) { + $args{next_action} = [ $self, 'redirect_to', $args{next_action} ]; + } + $focus_stack->push_viewport($class, %args); +} + +sub pop_viewport { + my $focus_stack :Stashed; + return $focus_stack->pop_viewport; +} + +sub pop_viewports_to { + my ($self, $vp) = @_; + my $focus_stack :Stashed; + return $focus_stack->pop_viewports_to($vp); +} + +sub redirect_to { + my ($self, $c, $to, $cap, $args, $attrs) = @_; + + #the confess calls could be changed later to $c->log ? + my $action; + if(!ref $to){ + $action = $self->action_for($to); + confess("Failed to locate action ${to} in " . $self->blessed) unless $action; + } + elsif( blessed $to && $to->isa('Catalyst::Action') ){ + $action = $to; + } elsif(ref $action eq 'ARRAY' && @$action == 2){ #is that overkill / too strict? + $action = $c->controller($to->[0])->action_for($to->[1]); + confess("Failed to locate action $to->[1] in $to->[0]" ) unless $action; + } else{ + confess("Failed to locate action from ${to}"); + } + + $cap ||= $c->req->captures; + $args ||= $c->req->args; + $attrs ||= {}; + my $uri = $c->uri_for($action, $cap, @$args, $attrs); + $c->res->redirect($uri); +} + +1; |