aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorgroditi <groditi@03d0b0b2-0e1a-0410-a411-fdb2f4bd65d7>2009-10-02 21:01:17 +0000
committergroditi <groditi@03d0b0b2-0e1a-0410-a411-fdb2f4bd65d7>2009-10-02 21:01:17 +0000
commit66057c3c1af63001383cd73e83c5a8adc94cef97 (patch)
treed1f27f10c72a72aabeed67dbb4b1a36fdf97cdab
parent565b2142439ace178d400e4acf64c3a21b83ce1f (diff)
downloadreaction-66057c3c1af63001383cd73e83c5a8adc94cef97.tar.gz
reaction-66057c3c1af63001383cd73e83c5a8adc94cef97.zip
move redirect_to to a role and deprecate it
-rw-r--r--Changes1
-rw-r--r--lib/Reaction/UI/Controller.pm42
-rw-r--r--lib/Reaction/UI/Controller/Role/RedirectTo.pm78
3 files changed, 91 insertions, 30 deletions
diff --git a/Changes b/Changes
index bd40cd9..5003d80 100644
--- a/Changes
+++ b/Changes
@@ -13,6 +13,7 @@ Revision history for Reaction
- Wire layout_args, which was forgotten + example of how to use it
- CRUD functionality is now implemented as roles, so it can be used
without needing to use Controller::Collection::CRUD
+ - Deprecate redirect_to and move it to an external role
0.002000 - 29 Apr 2008
- Update CheckUniques role to use around instead of overrides
- Stop using ACCEPT_CONTEXT, use InstancePerContext instead
diff --git a/lib/Reaction/UI/Controller.pm b/lib/Reaction/UI/Controller.pm
index 2d1b843..4777ccd 100644
--- a/lib/Reaction/UI/Controller.pm
+++ b/lib/Reaction/UI/Controller.pm
@@ -7,7 +7,10 @@ use Scalar::Util 'weaken';
use namespace::clean -except => [ qw(meta) ];
has context => (is => 'ro', isa => 'Object', weak_ref => 1);
-with 'Catalyst::Component::InstancePerContext';
+with(
+ 'Catalyst::Component::InstancePerContext',
+ 'Reaction::UI::Controller::Role::RedirectTo'
+);
sub build_per_context_instance {
my ($self, $c, @args) = @_;
@@ -54,31 +57,6 @@ sub pop_viewports_to {
return $self->context->stash->{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;
- my $reftype = ref($to);
- if( $reftype eq '' ){
- $action = $self->action_for($to);
- confess("Failed to locate action ${to} in " . blessed($self)) unless $action;
- } elsif($reftype eq 'ARRAY' && @$to == 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;
- } elsif( blessed $to && $to->isa('Catalyst::Action') ){
- $action = $to;
- } 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);
-}
-
sub make_context_closure {
my($self, $closure) = @_;
my $ctx = $self->context;
@@ -115,13 +93,17 @@ Reaction::UI::Controller - Reaction Base Controller Class
=head1 DESCRIPTION
-Base Reaction Controller class. Inherits from:
+Base Reaction Controller class, subclass of L<Catalyst::Controller>.
+
+=head1 ROLES CONSUMED
=over 4
-=item L<Catalyst::Controller>
-=item L<Catalyst::Component::ACCEPT_CONTEXT>
-=item L<Reaction::Object>
+=item L<Catalyst::Component::InstancePerContext>
+
+=item L<Reaction::UI::Controller::Role::RedirectTo>
+
+Please not that this functionality is now deprecated.
=back
diff --git a/lib/Reaction/UI/Controller/Role/RedirectTo.pm b/lib/Reaction/UI/Controller/Role/RedirectTo.pm
new file mode 100644
index 0000000..7d35b10
--- /dev/null
+++ b/lib/Reaction/UI/Controller/Role/RedirectTo.pm
@@ -0,0 +1,78 @@
+package Reaction::UI::Controller::Role::RedirectTo;
+
+use Moose::Role;
+
+sub redirect_to {
+ my ($self, $c, $to, $cap, $args, $attrs) = @_;
+
+ $c->log->debug(
+ "Using redirect_to is now deprecated and may be removed in the future."
+ );
+
+ #the confess calls could be changed later to $c->log ?
+ my $action;
+ my $reftype = ref($to);
+ if( $reftype eq '' ){
+ $action = $self->action_for($to);
+ confess("Failed to locate action ${to} in " . blessed($self)) unless $action;
+ } elsif($reftype eq 'ARRAY' && @$to == 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;
+ } elsif( blessed $to && $to->isa('Catalyst::Action') ){
+ $action = $to;
+ } 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;
+
+__END__;
+
+
+=head1 NAME
+
+Reaction::UI::Controller::Role::RedirectTo
+
+=head1 DESCRIPTION
+
+Provides a C<redirect_to> method, which aims to be a more convenient way to
+create internal redirects vs C<Catalyst::uri_for> and C<Catalyst::Response::redirect>
+
+=head1 DEPRECATION NOTICE
+
+This method was separated out of L<Catalyst::Controller> to facilitate deprecation.
+The behavior of this method is, by design, flawed and you should aim to replace
+any instances of it in your codebase;
+
+=head1 METHODS
+
+=head2 redirect_to $c, 'action_name', \@captures, \@args, \%query_parms
+
+=head2 redirect_to $c, $action_object, \@captures, \@args, \%query_parms
+
+=head2 redirect_to $c, [ Controller_name => 'action_name' ], \@captures, \@args, \%query_parms
+
+Will create a uri from the arguments given and redirect to it without detaching.
+If captures and arguments are not explicitly given, the ones from the current
+request will be used. If query-parameters are not given, none will be used.
+
+The first argument after C<$c> cab be one of three, the name of an action present
+in the controller returned by C<$c-E<gt>controller>, an action object, or an
+array reference contraining 2 items, a controller name and an action name.
+
+=head1 AUTHORS
+
+See L<Reaction::Class> for authors.
+
+=head1 LICENSE
+
+See L<Reaction::Class> for the license.
+
+=cut