[Catalyst-commits] r11976 - in Catalyst-Runtime/5.80/branches/basic-app-ctx-separation-cleaned/lib: . Catalyst

zby at dev.catalyst.perl.org zby at dev.catalyst.perl.org
Mon Nov 23 12:11:12 GMT 2009


Author: zby
Date: 2009-11-23 12:11:11 +0000 (Mon, 23 Nov 2009)
New Revision: 11976

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/Context.pm
Log:
using methods from Catalyst in Catalyst::Context instead of copy and paste

Modified: Catalyst-Runtime/5.80/branches/basic-app-ctx-separation-cleaned/lib/Catalyst/Context.pm
===================================================================
--- Catalyst-Runtime/5.80/branches/basic-app-ctx-separation-cleaned/lib/Catalyst/Context.pm	2009-11-22 20:13:06 UTC (rev 11975)
+++ Catalyst-Runtime/5.80/branches/basic-app-ctx-separation-cleaned/lib/Catalyst/Context.pm	2009-11-23 12:11:11 UTC (rev 11976)
@@ -367,12 +367,7 @@
 
 sub model {
     my ( $c, $name, @args ) = @_;
-    my $appclass = ref($c) || $c;
-    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->application->_comp_by_name( 'Model', $name, @args ) if $name;
 
     if (ref $c) {
         return $c->stash->{current_model_instance}
@@ -380,20 +375,7 @@
         return $c->model( $c->stash->{current_model} )
           if $c->stash->{current_model};
     }
-    return $c->model( $appclass->config->{default_model} )
-      if $appclass->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 );
+    return $c->application->_no_name_comp( 'Model' );
 }
 
 
@@ -421,11 +403,7 @@
 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->application->_comp_by_name( 'View', $name, @args ) if $name;
 
     if (ref $c) {
         return $c->stash->{current_view_instance}
@@ -433,19 +411,7 @@
         return $c->view( $c->stash->{current_view} )
           if $c->stash->{current_view};
     }
-    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 );
+    return $c->application->_no_name_comp( 'View' );
 }
 
 =head2 UTILITY METHODS

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-22 20:13:06 UTC (rev 11975)
+++ Catalyst-Runtime/5.80/branches/basic-app-ctx-separation-cleaned/lib/Catalyst.pm	2009-11-23 12:11:11 UTC (rev 11976)
@@ -306,26 +306,9 @@
 
 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 );
+    
+    return $c->_comp_by_name( 'View', $name, @args ) if $name;
+    return $c->_no_name_comp( 'View' );
 }
 
 =head2 $c->model($name)
@@ -334,24 +317,37 @@
 
 =cut
 
+sub _comp_by_name {
+    my ( $c, $type, $name, @args ) = @_;
+    my $short_type = substr( $type, 0, 1 );
+    my @result = $c->_comp_search_prefixes( $name, $type, $short_type);
+    return map { $c->_filter_component( $_, @args ) } @result if ref $name;
+    return $c->_filter_component( $result[ 0 ], @args );
+}
+
+
 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->_comp_by_name( 'Model', $name, @args ) if $name;
+    return $c->_no_name_comp( 'Model' );
+}
 
-    return $c->model( $c->config->{default_model} )
-      if $c->config->{default_model};
+sub _no_name_comp{
+    my ( $c, $type ) = @_;
 
-    my( $comp, $rest ) = $c->_comp_search_prefixes( undef, qw/Model M/);
+    my $lc_type = lc $type;
+    return $c->$lc_type( $c->config->{'default_' . $lc_type} )
+      if $c->config->{'default_' . $lc_type};
 
+    my $short_type = substr( $type, 0, 1 );
+    my( $comp, $rest ) = $c->_comp_search_prefixes( undef, $type, $short_type );
+
     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( Carp::shortmess('Calling $c->' . $lc_type . '() will return a random ' . $lc_type . ' unless you specify one of:') );
+        $c->log->warn( '* $c->config(default_' . $lc_type . '}=> "the name of the default ' . $lc_type . ' to use")' );
+        $c->log->warn( '* $c->stash->{current' . $lc_type . '} # the name of the ' . $lc_type . ' to use for this request' );
+        $c->log->warn( '* $c->stash->{current_' . $lc_type . '_instance} # the instance of the ' . $lc_type . ' to use for this request' );
         $c->log->warn( 'NB: in version 5.81, the "random" behavior will not work at all.' );
     }
 




More information about the Catalyst-commits mailing list