Clean up around method modifier
Tomas Doran [Tue, 9 Dec 2008 23:31:09 +0000 (23:31 +0000)]
Changes
lib/Catalyst/Controller.pm

diff --git a/Changes b/Changes
index 67ea177..440c793 100644 (file)
--- a/Changes
+++ b/Changes
@@ -1,5 +1,7 @@
 # This file documents the revision history for Perl extension Catalyst.
 
+        - Switch an around 'new' in Catalyst::Controller to a BUILDARGS
+          method as it's much neater and more obvious what is going on (t0m)
         - Add a clearer method on request and response _context 
           attributes, and use if from ::Engine rather than deleting
           the key from the instance hash (t0m)
index c5e6249..ec536ae 100644 (file)
@@ -32,9 +32,19 @@ has actions =>
      init_arg => undef,
     );
 
-# isa => 'ClassName|Catalyst' ?
-has _application => (is => 'rw');
-sub _app{ shift->_application(@_) } 
+# Future - isa => 'ClassName|Catalyst' performance?
+#           required => 1 breaks tests..
+has _application => (is => 'ro');
+sub _app { shift->_application(@_) } 
+
+override 'BUILDARGS' => sub {
+    my ($self, $app) = @_;
+    
+    my $args = super();
+    $args->{_application} = $app;
+    return $args;
+};
 
 sub BUILD {
     my ($self, $args) = @_;
@@ -122,15 +132,6 @@ sub _END : Private {
     return !@{ $c->error };
 }
 
-around new => sub {
-    my $orig = shift;
-    my $self = shift;
-    my $app = $_[0];
-    my $new = $self->$orig(@_);
-    $new->_application( $app );
-    return $new;
-};
-
 sub action_for {
     my ( $self, $name ) = @_;
     my $app = ($self->isa('Catalyst') ? $self : $self->_application);