undo change allowing domain in redirect_to
[catagits/Reaction.git] / lib / Reaction / UI / Controller.pm
index 45a85d8..2d1b843 100644 (file)
@@ -1,6 +1,6 @@
 package Reaction::UI::Controller;
 
-use base qw(Catalyst::Controller Reaction::Object);
+use base qw(Catalyst::Controller); # Reaction::Object);
 
 use Reaction::Class;
 use Scalar::Util 'weaken';
@@ -11,7 +11,8 @@ with 'Catalyst::Component::InstancePerContext';
 
 sub build_per_context_instance {
   my ($self, $c, @args) = @_;
-  my $newself =  $self->new($self->_application, {%$self, context => $c, @args});
+  my $class = ref($self) || $self;
+  my $newself =  $class->new($self->_application, {%$self, context => $c, @args});
   return $newself;
 }
 
@@ -26,9 +27,7 @@ sub push_viewport {
       $vp_attr = $vp_attr->[0];
     }
     if (ref($vp_attr) eq 'HASH') {
-      if (my $conf_class = delete $vp_attr->{class}) {
-        $class = $conf_class;
-      }
+      $class = $vp_attr->{class} if defined $vp_attr->{class};
       %args = %{ $self->merge_config_hashes($vp_attr, {@proto_args}) };
     } else {
       $class = $vp_attr;
@@ -93,7 +92,26 @@ __END__;
 
 =head1 NAME
 
-Reaction::UI::Controller
+Reaction::UI::Controller - Reaction Base Controller Class
+
+=head1 SYNOPSIS
+
+  package MyApp::Controller::Foo;
+  use strict;
+  use warnings;
+  use parent 'Reaction::UI::Controller';
+
+  use aliased 'Reaction::UI::ViewPort';
+
+  sub foo: Chained('/base') Args(0) {
+    my ($self, $ctx) = @_;
+
+    $ctx->push_viewport(ViewPort,
+      layout => 'foo',
+    );
+  }
+
+  1;
 
 =head1 DESCRIPTION
 
@@ -165,6 +183,45 @@ controller.
 $captures and $args default to the current requests $captures and
 $args if not supplied.
 
+=head2 make_context_closure
+
+The purpose of this method is to prevent memory leaks.
+It weakens the context object, often denoted $c, and passes it as the 
+first argument to the sub{} that is passed to the make_context_closure method.
+In other words,
+
+=over 4
+
+make_context_closure returns sub { $sub_you_gave_it->($weak_c, @_)
+
+=back
+
+To further expound up this useful construct consider code written before
+make_context_closure was created:
+
+    on_apply_callback => 
+        sub {
+          $self->after_search( $c, @_ );
+        }
+    ),
+
+This could be rewritten as:
+
+    on_apply_callback => $self->make_context_closure(
+        sub {
+            my $weak_c = shift;
+            $self->after_search( $weak_c, @_ );
+        }
+    ),
+
+Or even more succintly:
+
+    on_apply_callback => $self->make_context_closure(
+        sub {
+            $self->after_search( @_ );
+        }
+    ),
+
 =head1 AUTHORS
 
 See L<Reaction::Class> for authors.