From: Andy Grundman Date: Mon, 26 Feb 2007 18:07:01 +0000 (+0000) Subject: Patch from zamolxes: MyApp->model/view now looks at MyApp->config->{default_view... X-Git-Tag: 5.7099_04~239 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Runtime.git;a=commitdiff_plain;h=72f87c4bec018bc59ef69db7c55b9a8d68bb503d Patch from zamolxes: MyApp->model/view now looks at MyApp->config->{default_view/model} --- diff --git a/Changes b/Changes index 32e9176..12a52d9 100644 --- a/Changes +++ b/Changes @@ -7,6 +7,8 @@ This file documents the revision history for Perl extension Catalyst. - Skip body processing if we don't have a Content-Length header. Results in about a 9% performance increase when handling GET/HEAD requests. - Add a default body to redirect responses. + - MyApp->model/view now looks at MyApp->config->{default_view/model} + (Bogdan Lucaciu) 5.7006 2006-11-03 14.18 - Updated manifest diff --git a/lib/Catalyst.pm b/lib/Catalyst.pm index c4a2089..ab4c3f0 100644 --- a/lib/Catalyst.pm +++ b/lib/Catalyst.pm @@ -511,6 +511,8 @@ Gets a L instance by name. $c->model('Foo')->do_stuff; +Any extra arguments are directly passed to ACCEPT_CONTEXT. + If the name is omitted, it will look for - a model object in $c->stash{current_model_instance}, then - a model name in $c->stash->{current_model}, then @@ -529,10 +531,10 @@ sub model { if $c->stash->{current_model_instance}; return $c->model( $c->stash->{current_model} ) if $c->stash->{current_model}; - return $c->model( $c->config->{default_model} ) - if $c->config->{default_model}; } - return $c->_filter_component( $c->_comp_singular(qw/Model M/), @args ); + return $c->model( $c->config->{default_model} ) + if $c->config->{default_model}; + return $c->_filter_component( $c->_comp_singular(qw/Model M/) ); } @@ -554,6 +556,8 @@ Gets a L instance by name. $c->view('Foo')->do_stuff; +Any extra arguments are directly passed to ACCEPT_CONTEXT. + If the name is omitted, it will look for - a view object in $c->stash{current_view_instance}, then - a view name in $c->stash->{current_view}, then @@ -572,9 +576,9 @@ sub view { if $c->stash->{current_view_instance}; return $c->view( $c->stash->{current_view} ) if $c->stash->{current_view}; - return $c->view( $c->config->{default_view} ) - if $c->config->{default_view}; } + return $c->view( $c->config->{default_view} ) + if $c->config->{default_view}; return $c->_filter_component( $c->_comp_singular(qw/View V/) ); } diff --git a/t/unit_core_mvc.t b/t/unit_core_mvc.t index d5dfb7e..9229ee7 100644 --- a/t/unit_core_mvc.t +++ b/t/unit_core_mvc.t @@ -1,4 +1,4 @@ -use Test::More tests => 23; +use Test::More tests => 27; use strict; use warnings; @@ -73,6 +73,20 @@ is ( bless ({stash=>{current_model_instance=> $model, current_model=>'MyApp::M:: MyApp->config->{default_view} = 'V'; is ( bless ({stash=>{}}, 'MyApp')->view , 'MyApp::View::V', 'default_view ok'); +is ( MyApp->view , 'MyApp::View::V', 'default_view in class method ok'); MyApp->config->{default_model} = 'M'; is ( bless ({stash=>{}}, 'MyApp')->model , 'MyApp::Model::M', 'default_model ok'); +is ( MyApp->model , 'MyApp::Model::M', 'default_model in class method ok'); + +#checking @args passed to ACCEPT_CONTEXT +my $args; +{ + no warnings; + *MyApp::Model::M::ACCEPT_CONTEXT = sub { my ($self, $c, @args) = @_; $args= \@args}; + *MyApp::View::V::ACCEPT_CONTEXT = sub { my ($self, $c, @args) = @_; $args= \@args}; +} +MyApp->model('M', qw/foo bar/); +is_deeply($args, [qw/foo bar/], '$c->model args passed to ACCEPT_CONTEXT ok'); +MyApp->view('V', qw/baz moo/); +is_deeply($args, [qw/baz moo/], '$c->view args passed to ACCEPT_CONTEXT ok');