From: Tomas Doran Date: Tue, 9 Dec 2008 23:31:09 +0000 (+0000) Subject: Clean up around method modifier X-Git-Tag: 5.8000_05~99 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Runtime.git;a=commitdiff_plain;h=fd0434d760ec012f2031da332c959463e1466ef2 Clean up around method modifier --- diff --git a/Changes b/Changes index 67ea177..440c793 100644 --- 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) diff --git a/lib/Catalyst/Controller.pm b/lib/Catalyst/Controller.pm index c5e6249..ec536ae 100644 --- a/lib/Catalyst/Controller.pm +++ b/lib/Catalyst/Controller.pm @@ -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);