[Catalyst-commits] r11889 -
Catalyst-Runtime/5.80/branches/basic-app-ctx-separation-cleaned/lib
zby at dev.catalyst.perl.org
zby at dev.catalyst.perl.org
Wed Nov 18 21:16:30 GMT 2009
Author: zby
Date: 2009-11-18 21:16:30 +0000 (Wed, 18 Nov 2009)
New Revision: 11889
Modified:
Catalyst-Runtime/5.80/branches/basic-app-ctx-separation-cleaned/lib/Catalyst.pm
Log:
view and model methods for the application class
Modified: Catalyst-Runtime/5.80/branches/basic-app-ctx-separation-cleaned/lib/Catalyst.pm
===================================================================
--- Catalyst-Runtime/5.80/branches/basic-app-ctx-separation-cleaned/lib/Catalyst.pm 2009-11-18 18:05:01 UTC (rev 11888)
+++ Catalyst-Runtime/5.80/branches/basic-app-ctx-separation-cleaned/lib/Catalyst.pm 2009-11-18 21:16:30 UTC (rev 11889)
@@ -291,6 +291,55 @@
return $c->component( $c->action->class );
}
+sub view {
+ my ( $c, $name, @args ) = @_;
+
+ if( $name ) {
+ my @result = $c->_comp_search_prefixes( $name, qw/View V/ );
+ return map { $c->_filter_component( $_, @args ) } @result if ref $name;
+ return $c->_filter_component( $result[ 0 ], @args );
+ }
+
+ return $c->view( $c->config->{default_view} )
+ if $c->config->{default_view};
+ my( $comp, $rest ) = $c->_comp_search_prefixes( undef, qw/View V/);
+
+ if( $rest ) {
+ $c->log->warn( 'Calling $c->view() will return a random view unless you specify one of:' );
+ $c->log->warn( '* $c->config(default_view => "the name of the default view to use")' );
+ $c->log->warn( '* $c->stash->{current_view} # the name of the view to use for this request' );
+ $c->log->warn( '* $c->stash->{current_view_instance} # the instance of the view to use for this request' );
+ $c->log->warn( 'NB: in version 5.81, the "random" behavior will not work at all.' );
+ }
+
+ return $c->_filter_component( $comp );
+}
+
+sub model {
+ my ( $c, $name, @args ) = @_;
+ if( $name ) {
+ my @result = $c->_comp_search_prefixes( $name, qw/Model M/ );
+ return map { $c->_filter_component( $_, @args ) } @result if ref $name;
+ return $c->_filter_component( $result[ 0 ], @args );
+ }
+
+ return $c->model( $c->config->{default_model} )
+ if $c->config->{default_model};
+
+ my( $comp, $rest ) = $c->_comp_search_prefixes( undef, qw/Model M/);
+
+ if( $rest ) {
+ $c->log->warn( Carp::shortmess('Calling $c->model() will return a random model unless you specify one of:') );
+ $c->log->warn( '* $c->config(default_model => "the name of the default model to use")' );
+ $c->log->warn( '* $c->stash->{current_model} # the name of the model to use for this request' );
+ $c->log->warn( '* $c->stash->{current_model_instance} # the instance of the model to use for this request' );
+ $c->log->warn( 'NB: in version 5.81, the "random" behavior will not work at all.' );
+ }
+
+ return $c->_filter_component( $comp );
+}
+
+
sub _comp_search_prefixes {
my $c = shift;
return map $c->components->{ $_ }, $c->_comp_names_search_prefixes(@_);
More information about the Catalyst-commits
mailing list